This has been a useful thread for me. I borrowed @chewie76 supertrend indicator. I'm having difficulty setting up a scan that informs me that a trend has gone in the opposite direction. In other words, a long trend would begin when the price breaks above the short trend. How can I scan for that event? Tried using LongDot and ShortDot but it didn't work properly. This is the code:
#Hull_SuperTrend_Trading_System
# assembled by Chewie 4/10/2022
input Target_Bubbles = no;
input Entry_SL_Bubbles = no;
input Targetlines = yes;
input Labels = yes;
input alertON = yes;
input Bands = yes;
input AvgType = AverageType.HULL;
input STAtrMult = 2.75;
input nATR = 12;
#======== Calculate the Supertrend =====================================================
def ATR = ATR("length" = nATR, "average type" = AvgType);
def UP_Band_Basic = HL2 + (STAtrMult * ATR);
def LW_Band_Basic = HL2 + (-STAtrMult * 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 Long = if close > ST then ST else Double.NaN;
Long.AssignValueColor(Color.cyan);
Long.SetLineWeight(3);
plot Short = if close < ST then ST else Double.NaN;
Short.AssignValueColor(Color.magenta);
Short.SetLineWeight(3);
def LongTrigger = isNaN(Long[1]) and !isNaN(Long);
def ShortTrigger = isNaN(Short[1]) and !isNaN(Short);
plot LongDot = if LongTrigger then ST else Double.NaN;
LongDot.SetPaintingStrategy(PaintingStrategy.POINTS);
LongDot.AssignValueColor(Color.cyan);
LongDot.SetLineWeight(4);
plot ShortDot = if ShortTrigger then ST else Double.NaN;
ShortDot.SetPaintingStrategy(PaintingStrategy.POINTS);
ShortDot.AssignValueColor(Color.magenta);
ShortDot.SetLineWeight(4);
AddChartBubble(Entry_SL_Bubbles and LongTrigger, ST, "BUY", Color.GREEN, no);
AddChartBubble(Entry_SL_Bubbles and ShortTrigger, ST, "SELL", Color.RED, yes);
#Super Trend Labels
AddLabel(yes and labels and Long, "ST:LONG", color.CYAN);
AddLabel(yes and labels and Short, "ST:SHORT", color.magenta);
#======== End of Supertrend calcs
#Hull_SuperTrend_Trading_System
# assembled by Chewie 4/10/2022
input Target_Bubbles = no;
input Entry_SL_Bubbles = no;
input Targetlines = yes;
input Labels = yes;
input alertON = yes;
input Bands = yes;
input AvgType = AverageType.HULL;
input STAtrMult = 2.75;
input nATR = 12;
#======== Calculate the Supertrend =====================================================
def ATR = ATR("length" = nATR, "average type" = AvgType);
def UP_Band_Basic = HL2 + (STAtrMult * ATR);
def LW_Band_Basic = HL2 + (-STAtrMult * 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 Long = if close > ST then ST else Double.NaN;
Long.AssignValueColor(Color.cyan);
Long.SetLineWeight(3);
plot Short = if close < ST then ST else Double.NaN;
Short.AssignValueColor(Color.magenta);
Short.SetLineWeight(3);
def LongTrigger = isNaN(Long[1]) and !isNaN(Long);
def ShortTrigger = isNaN(Short[1]) and !isNaN(Short);
plot LongDot = if LongTrigger then ST else Double.NaN;
LongDot.SetPaintingStrategy(PaintingStrategy.POINTS);
LongDot.AssignValueColor(Color.cyan);
LongDot.SetLineWeight(4);
plot ShortDot = if ShortTrigger then ST else Double.NaN;
ShortDot.SetPaintingStrategy(PaintingStrategy.POINTS);
ShortDot.AssignValueColor(Color.magenta);
ShortDot.SetLineWeight(4);
AddChartBubble(Entry_SL_Bubbles and LongTrigger, ST, "BUY", Color.GREEN, no);
AddChartBubble(Entry_SL_Bubbles and ShortTrigger, ST, "SELL", Color.RED, yes);
#Super Trend Labels
AddLabel(yes and labels and Long, "ST:LONG", color.CYAN);
AddLabel(yes and labels and Short, "ST:SHORT", color.magenta);
#======== End of Supertrend calcs