Hello everyone, I use a variety of indicators for bullish/bearish signals. I need some help with the script for when a signal is either bullish or bearish, but it is in between the bull/bear signal zones.
For example, the code below uses the stochastic oscillator. The histogram is painted green when it is overbought, red when it is oversold, and yellow when it is in between those levels.
A bull signal is generated when FullD crosses above 60 and I assign 1 point.
A bear signal occurs when FullD crosses below 40 and I assign -1 point.
Once the signal occurs, I want to have the point value remain at either +1 or -1 until a new signal reverses the existing one. Zero points is not wanted.
I'm assuming that I need to use the Case or Switch statements, but I've never written that script.
#Declarations
declare lower;
#Inputs
input over_bought = 60;
input over_sold = 40;
input KPeriod = 126;
input DPeriod = 5;
input priceH = close;
input priceL = close;
input priceC = close;
input slowing_period = 1;
input averageType = AverageType.SIMPLE;
input showBreakoutSignals = {default "No", "On FullK", "On FullD", "On FullK & FullD"};
#Definitions
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;
def FullK = MovingAverage(averageType, FastK, slowing_period);
def FullD = MovingAverage(averageType, FullK, DPeriod);
def AboveOB = FullD > over_bought;
def BetweenOBOS = FullD <= over_bought and FullD >= over_sold;
def StochClose = StochasticFull(UTLevel, DTLevel, StochLength, StochSMA, Price, Price, Price, SlowP)."FullD";
def SCSignal = if StochClose > UTLevel then 1 else if SCSignal[1] == 1 and StochClose >= DTLevel then 1 else if StochClose < DTLevel then -1 else if SCSignal[1] ==-1 and StochClose <= UTLevel then -1 else 0;
#Plots
plot StochClose = FullD;
plot OverBought = over_bought;
plot OverSold = over_sold;
#Painting Strategies
StochClose.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
StochClose.AssignValueColor(If BetweenOBOS then Color.YELLOW else if AboveOB then Color.GREEN else Color.RED);
Any assistance would be appreciated.
For example, the code below uses the stochastic oscillator. The histogram is painted green when it is overbought, red when it is oversold, and yellow when it is in between those levels.
A bull signal is generated when FullD crosses above 60 and I assign 1 point.
A bear signal occurs when FullD crosses below 40 and I assign -1 point.
Once the signal occurs, I want to have the point value remain at either +1 or -1 until a new signal reverses the existing one. Zero points is not wanted.
I'm assuming that I need to use the Case or Switch statements, but I've never written that script.
#Declarations
declare lower;
#Inputs
input over_bought = 60;
input over_sold = 40;
input KPeriod = 126;
input DPeriod = 5;
input priceH = close;
input priceL = close;
input priceC = close;
input slowing_period = 1;
input averageType = AverageType.SIMPLE;
input showBreakoutSignals = {default "No", "On FullK", "On FullD", "On FullK & FullD"};
#Definitions
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;
def FullK = MovingAverage(averageType, FastK, slowing_period);
def FullD = MovingAverage(averageType, FullK, DPeriod);
def AboveOB = FullD > over_bought;
def BetweenOBOS = FullD <= over_bought and FullD >= over_sold;
def StochClose = StochasticFull(UTLevel, DTLevel, StochLength, StochSMA, Price, Price, Price, SlowP)."FullD";
def SCSignal = if StochClose > UTLevel then 1 else if SCSignal[1] == 1 and StochClose >= DTLevel then 1 else if StochClose < DTLevel then -1 else if SCSignal[1] ==-1 and StochClose <= UTLevel then -1 else 0;
#Plots
plot StochClose = FullD;
plot OverBought = over_bought;
plot OverSold = over_sold;
#Painting Strategies
StochClose.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
StochClose.AssignValueColor(If BetweenOBOS then Color.YELLOW else if AboveOB then Color.GREEN else Color.RED);
Any assistance would be appreciated.