Stochastic Bull Bear

barbaros

Administrator
Staff member
Platform
  1. Thinkorswim
jPALiVP.png


Code:
# Stochastic Bull/Bear Indicator
#
# Free for use. Header credits must be included when any form of the code included in this package is used.
# User assumes all risk. Author not responsible for errors or use of tool.
# Copyright (c) 2021 B4 Signals
#
# Get support at: https://b4signals.com
# Join us at: https://discord.gg/kD3pKE2CQd
#
# v1.0 - barbros / chuck - official release

declare lower;

input PaintBars = no;
input KPeriod = 14;
input DPeriod = 13;
input priceH = high;
input priceL = low;
input priceC = close;
input slowing_period = 1;
input averageType = AverageType.SIMPLE;

def lowest_k = Lowest(priceL, KPeriod);
def c1 = priceC - lowest_k;
def c2 = Highest(priceH, KPeriod) - lowest_k;
def FastK = if c2 != 0 then c1 / c2 * 100 else 0;

plot FullK = MovingAverage(averageType, FastK, slowing_period);
FullK.SetDefaultColor(Color.MAGENTA);
FullK.HideTitle();

plot FullD = MovingAverage(averageType, FullK, DPeriod);
FullD.SetDefaultColor(Color.CYAN);
FullD.HideTitle();

plot Signal = if isNaN(close) then Double.NaN else 50;
Signal.SetPaintingStrategy(PaintingStrategy.POINTS);
Signal.SetLineWeight(5);
Signal.HideTitle();
Signal.HideBubble();
Signal.AssignValueColor(if FullK > FullD then Color.GREEN
              else if FullK < FullD then Color.RED
              else Color.DARK_GRAY);

AssignPriceColor(if PaintBars then
                     if FullK > FullD then Color.GREEN
                     else if FullK < FullD then Color.RED
                     else Color.DARK_GRAY
                else Color.CURRENT);
 
Top