• LIMITED TIME OFFER: use coupon code PRIMEDAY (case sensitive) at checkout to save $50 off VIP membership (down to $149 / year). Valid through Tuesday 6/22. Biggest discount this year!

stochasticMACD going past the last candle bar

kryptoniken

New member
VIP
Could someone please help me to get rid of the tail of the below indicator below, it doesn't stop at the last candle bar?

Code:
declare lower;

input stochLength = 45;
input fastLength = 12;
input slowLength = 26;
input signalLength = 9;
input over_bought = 10;
input over_sold = -10;
input averageType = AverageType.EXPONENTIAL;

def hh = Highest(high, stochLength);
def ll = Lowest(low, stochLength);

def fastMA = MovingAverage(averageType, close, fastLength);
def slowMA = MovingAverage(averageType, close, slowLength);

def stochFastMA;
def stochSlowMA;
if (hh - ll) != 0 {
    stochFastMA = (fastMA - ll) / (hh - ll);
    stochSlowMA = (slowMA - ll) / (hh - ll);
} else {
    stochFastMA = 0;
    stochSlowMA = 0;
}

plot StochasticMACD = (stochFastMA - stochSlowMA) * 100;
plot Signal = MovingAverage(averageType, StochasticMACD, signalLength);
plot OverBought = over_bought;
plot ZeroLine = 0;
plot OverSold = over_sold;

StochasticMACD.SetDefaultColor(GetColor(9));
Signal.SetDefaultColor(GetColor(9));
OverBought.SetDefaultColor(GetColor(7));
ZeroLine.SetDefaultColor(GetColor(0));
OverSold.SetDefaultColor(GetColor(7));

AddCloud(StochasticMACD, Signal, Color.WHITE, Color.GRAY);
 

generic

Active member
@kryptoniken Here you go

Code:
declare lower;

input stochLength = 45;
input fastLength = 12;
input slowLength = 26;
input signalLength = 9;
input over_bought = 10;
input over_sold = -10;
input averageType = AverageType.EXPONENTIAL;

def hh = Highest(high, stochLength);
def ll = Lowest(low, stochLength);

def fastMA = MovingAverage(averageType, close, fastLength);
def slowMA = MovingAverage(averageType, close, slowLength);

def stochFastMA = if (hh - ll) != 0 then (fastMA - ll) / (hh - ll)
    else Double.NaN;
def stochSlowMA = if (hh - ll) != 0 then (slowMA - ll) / (hh - ll)
    else Double.NaN;

plot StochasticMACD = (stochFastMA - stochSlowMA) * 100;
plot Signal = MovingAverage(averageType, StochasticMACD, signalLength);
plot OverBought = over_bought;
plot ZeroLine = 0;
plot OverSold = over_sold;

StochasticMACD.SetDefaultColor(GetColor(9));
Signal.SetDefaultColor(GetColor(9));
OverBought.SetDefaultColor(GetColor(7));
ZeroLine.SetDefaultColor(GetColor(0));
OverSold.SetDefaultColor(GetColor(7));

AddCloud(StochasticMACD, Signal, Color.WHITE, Color.GRAY);
 

Similar threads

Top