Hello
I took supertrend from https://usethinkscript.com/threads/supertrend-yahoo-finance-type-for-thinkorswim.1998/ and want to move it to function so that I can invoke it multiple times in the ToS script that I'm writing.
What I noticed is that it works fine as long as there is no other condition with "crosses" function but as soon as I add any other codition, it stops printing label values.
Appreciate if someone can point me to the error and/or provide the fix for this issue so I can combine multiple conditions by keeping supertrend as a separate script function.
Thanks
I took supertrend from https://usethinkscript.com/threads/supertrend-yahoo-finance-type-for-thinkorswim.1998/ and want to move it to function so that I can invoke it multiple times in the ToS script that I'm writing.
What I noticed is that it works fine as long as there is no other condition with "crosses" function but as soon as I add any other codition, it stops printing label values.
Appreciate if someone can point me to the error and/or provide the fix for this issue so I can combine multiple conditions by keeping supertrend as a separate script function.
Code:
script ss {
input AtrMult = 1.00;
input nATR = 6;
input AvgType = AverageType.HULL;
input PaintBars = yes;
def ATR = ATR("length" = nATR, "average type" = AvgType);
def UP_Band_Basic = HL2 + (AtrMult * ATR);
def LW_Band_Basic = HL2 + (-AtrMult * ATR);
def UP_Band = if ((UP_Band_Basic < UP_Band[1]) or (close[1] > UP_Band[1])) then UP_Band_Basic else UP_Band[1];
def LW_Band = if ((LW_Band_Basic > LW_Band[1]) or (close[1] < LW_Band[1])) then LW_Band_Basic else LW_Band[1];
def ST = if ((ST[1] == UP_Band[1]) and (close < UP_Band)) then UP_Band
else if ((ST[1] == UP_Band[1]) and (close > Up_Band)) then LW_Band
else if ((ST[1] == LW_Band[1]) and (close > LW_Band)) then LW_Band
else if ((ST[1] == LW_Band) and (close < LW_Band)) then UP_Band
else LW_Band;
plot SuperTrend = ST;
};
def supertrend = ss(1, 6, AverageType.HULL, yes);;
def smartFilter = MovAvgExponential(close, 200);
def ArrowDown = (Supertrend crosses above close) and close < smartFilter; # This does not print values and results in NaN and needs fix.
# def ArrowDown = (Supertrend crosses above close); # This works fine and below label prints both values
addlabel(yes, "Supertrend =" + supertrend + ", ArrowDown=" + ArrowDown);
Thanks