SuperTrend RSI Strategy Help

May I please seek some support in fixing the code below. Am not sure if there is already a thread / idea for the below combination

What I am looking to achieve

1. Signal up arrow when both Supertrends (AltMult 2, Length 10) and ((AltMult 4, Length 10) are green and RSI (Length 14, OB 60 and OS 40) > 60;
2. Signal down arrow when both Supertrends (AltMult 2, Length 10) and ((AltMult 4, Length 10) are red and RSI (Length 14, OB 60 and OS 40) < 40;
3) If either of the above conditions are true, then plot SL/Target

This is working fine with the below code but I don't want the signal to reappear if the previous bar already has a signal and want to target/sl bars to continue till either the SL or target is met (if target is met then color should be green and SL is hit then color should be red - Please ignore if this is too much code)

https://tos.mx/acoKDRa
Ruby:
# ST 1
input ST_AltMult = 2;
input ST_Length = 10;
input Show_ST1_indicator = Yes;
def ATR1 = ATR(ST_Length, AverageType.HULL);
def UP_Band_Basic = HL2 + (ST_AltMult * ATR1);
def LW_Band_Basic = HL2 + (-ST_AltMult * ATR1);
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;

def Long_ST = if close > ST then ST else Double.NaN;
def Short_ST = if close < ST then ST else Double.NaN;

def LTrigger_ST = IsNaN(Long_ST[1]) and !IsNaN(Long_ST);
def STrigger_ST = IsNaN(Short_ST[1]) and !IsNaN(Short_ST);

plot Long =
if show_ST1_indicator then
(if close > ST then ST else Double.NaN) else double.nan;
Long.SetDefaultColor(Color.GREEN);
Long.SetLineWeight(1);

plot Short =
if show_ST1_indicator then
(if close < ST then ST else Double.NaN) else double.nan;
Short.SetDefaultColor(Color.RED);
Short.SetLineWeight(1);

def LongTrigger = IsNaN(Long[1]) and !IsNaN(Long);
def ShortTrigger = IsNaN(Short[1]) and !IsNaN(Short);

plot LongDot =
if show_ST1_indicator then
(if LongTrigger then ST else Double.NaN) else double.nan;
LongDot.SetPaintingStrategy(PaintingStrategy.POINTS);
LongDot.SetDefaultColor(Color.GREEN);
LongDot.SetLineWeight(1);

plot ShortDot =
if show_ST1_indicator then
(if ShortTrigger then ST else Double.NaN) else double.nan;
ShortDot.SetPaintingStrategy(PaintingStrategy.POINTS);
ShortDot.SetDefaultColor(Color.RED);
ShortDot.SetLineWeight(1);


# ST2
input ST1_AltMult = 4;
input ST1_Length = 10;
input Show_ST2_indicator = Yes;
def ATR2 = ATR(ST1_Length, AverageType.HULL);
def UP_Band_Basic1 = HL2 + (ST1_AltMult * ATR2);
def LW_Band_Basic1 = HL2 + (-ST1_AltMult * ATR2);
def UP_Band1 = if ((UP_Band_Basic1 < UP_Band1[1]) or (close[1] > UP_Band1[1])) then UP_Band_Basic1 else UP_Band1[1];
def LW_Band1 = if ((LW_Band_Basic1 > LW_Band1[1]) or (close[1] < LW_Band1[1])) then LW_Band_Basic1 else LW_Band1[1];

def ST1 = if ((ST1[1] == UP_Band1[1]) and (close < UP_Band1)) then UP_Band1
else if ((ST1[1] == UP_Band1[1]) and (close > UP_Band1)) then LW_Band1
else if ((ST1[1] == LW_Band1[1]) and (close > LW_Band1)) then LW_Band1
else if ((ST1[1] == LW_Band1) and (close < LW_Band1)) then UP_Band1
else LW_Band1;

def Long_ST1 = if close > ST1 then ST1 else Double.NaN;
def Short_ST1 = if close < ST1 then ST1 else Double.NaN;

def LTrigger_ST1 = IsNaN(Long_ST1[1]) and !IsNaN(Long_ST1);
def STrigger_ST1 = IsNaN(Short_ST1[1]) and !IsNaN(Short_ST1);

plot Long1 = if show_ST1_indicator then
(if close > ST1 then ST1 else Double.NaN)else Double.NaN;
Long1.SetDefaultColor(Color.GREEN);
Long1.SetLineWeight(1);

plot Short1 = if show_ST1_indicator then
(if close < ST1 then ST1 else Double.NaN)else Double.NaN;
Short1.SetDefaultColor(Color.RED);
Short1.SetLineWeight(1);

def LongTrigger1 = IsNaN(Long1[1]) and !IsNaN(Long1);
def ShortTrigger1 = IsNaN(Short1[1]) and !IsNaN(Short1);

plot LongDot1 = if show_ST1_indicator then
(if LongTrigger1 then ST1 else Double.NaN)else Double.NaN;
LongDot1.SetPaintingStrategy(PaintingStrategy.POINTS);
LongDot1.SetDefaultColor(Color.GREEN);
LongDot1.SetLineWeight(1);

plot ShortDot1 = if show_ST1_indicator then
(if ShortTrigger1 then ST1 else Double.NaN)else Double.NaN;
ShortDot1.SetPaintingStrategy(PaintingStrategy.POINTS);
ShortDot1.SetDefaultColor(Color.RED);
ShortDot1.SetLineWeight(1);

#RSI
input RSIOverbought = 60;
input RSIOversold = 40;
input RSILength = 14;
def NetChange = MovingAverage(AverageType.WILDERS, close - close[1], RSILength);
def TotChange = MovingAverage(AverageType.WILDERS, AbsValue(close - close[1]), RSILength);
def ChgRatio = if TotChange != 0 then NetChange / TotChange else 0;
def RSI_IND = 50 * (ChgRatio + 1);
def longRSI = RSI_IND > RSIOverbought;
def shortRSI = RSI_IND < RSIOversold;

def avoidzone1 = Long_st && Short_st1 ;
def avoidzone2 =  Long_st1 && Short_st;
AssignPriceColor(if avoidzone1
                then Color.GRAY
                else Color.CURRENT);
AssignPriceColor(if avoidzone2
                then Color.GRAY
                else Color.CURRENT);

def bullish =
Long_ST
&& Long_ST1
&& lONGRSI
;

def bearish =
Short_ST
&& Short_ST1
&& SHORTRSI
;



plot bullsignal =
bullish ;
bullsignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
bullsignal.SetDefaultColor(Color.MAGENTA);
bullsignal.SetLineWeight(5);

plot bearsignal =
bearish
;
bearsignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
bearsignal.SetDefaultColor(Color.MAGENTA);
bearsignal.SetLineWeight(5);



#SLF


input slf_length = 14;#(title="slf_length", defval=14, minval=1)
input slf_smoothing = {default RMA, SMA, EMA, WMA};#"slf_smoothing",
input slf_ATRFactor = 0.5;       # Multiplier
input slf_target = 1;
input slf_wicks = yes;
input slf_addSrpead = yes;
def slf_c = close;
def slf_h = high;
def slf_l = low;


def slf_ask  = Average(close(priceType = PriceType.ASK), 3);
def slf_bid  = Average(close(priceType = PriceType.BID), 3);
def slf_diff = AbsValue(slf_ask - slf_bid);

def slf_spread = if IsNaN(slf_diff) then 0 else slf_diff;

script ma_function {
    input slf_smoothing = "RMA";
    input source = close;
    input slf_length = 14;
    def maType;
    if slf_smoothing == "RMA" {
        maType = WildersSmoothing(source, slf_length);
    } else {
        if slf_smoothing == "SMA" {
            maType = SimpleMovingAvg(source, slf_length);
        } else {
            if slf_smoothing == "EMA" {
                maType =  ExpAverage(source, slf_length);
            } else {
                maType = WMA(source, slf_length);
            }
        }
    }
    plot return = maType;
}
def slf_tr = TrueRange(slf_h, slf_c, slf_l);
def slf_ATR = ma_function(slf_smoothing, slf_tr, slf_length) + If(slf_addSrpead, slf_spread, 0);
def slf_ATR1 = slf_ATR * slf_ATRFactor;
def ATRUp = slf_ATR1 + If(slf_wicks , slf_h , slf_c);
def ATRDn = If(slf_wicks , slf_l , slf_c) - slf_ATR1;



#TARGET AND SL
input SL_Type = {default "Candle_Cl",  "ATR", "ST" };
input Target_Mult = 1.5;
input SL_Lookback = 1;

def SL_Long;
def SL_Short;
def target_Long;
def target_Short;

switch (SL_Type) {
case "Candle_Cl":
    SL_Long = Lowest(low, SL_Lookback);;
    SL_Short = Highest(high, SL_Lookback);;
    target_Long = close + ((close - SL_Long) * Target_Mult);
    target_Short = close - ((SL_Short - close) * Target_Mult);
case  "ST":
    SL_Long = long;
    SL_Short = short;
    target_Long = close + ((close - SL_Long) * Target_Mult);
    target_Short = close - ((SL_Short - close) * Target_Mult);
case "ATR":
    SL_Long = atrDn;
    SL_Short = atrUp;
    target_Long = close + ((close - SL_Long) * Target_Mult);
    target_Short = close - ((SL_Short - close) * Target_Mult);
}

plot slbar_Long = if bullsignal then SL_Long else Double.NaN;
slbar_Long.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
slbar_Long.SetDefaultColor(Color.WHITE);
#AddChartBubble (slbar_Long, SL_Long, ROUND(CLOSE - SL_Long,0) , color.white, No);


plot slbar_Short = if bearsignal then SL_Short else Double.NaN;
slbar_Short.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
slbar_Short.SetDefaultColor(Color.WHITE);
#AddChartBubble (slbar_Short, SL_Short, ROUND(SL_Short-CLOSE ,0) , color.white, No);

plot Limitbar_Long = if bullsignal then target_Long else Double.NaN;
Limitbar_Long.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Limitbar_Long.SetDefaultColor(Color.WHITE);

plot Limitbar_Short = if bearsignal then target_Short else Double.NaN;
Limitbar_Short.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Limitbar_Short.SetDefaultColor(Color.WHITE);

wdwBg0J.png
 
Last edited by a moderator:
Solution
May I please seek some support in fixing the code below. Am not sure if there is already a thread / idea for the below combination

What I am looking to achieve

1. Signal up arrow when both Supertrends (AltMult 2, Length 10) and ((AltMult 4, Length 10) are green and RSI (Length 14, OB 60 and OS 40) > 60;
2. Signal down arrow when both Supertrends (AltMult 2, Length 10) and ((AltMult 4, Length 10) are red and RSI (Length 14, OB 60 and OS 40) < 40;
3) If either of the above conditions are true, then plot SL/Target

This is working fine with the below code but I don't want the signal to reappear if the previous bar already has a signal and want to target/sl bars to continue till either the SL or target is met (if target is met then...
May I please seek some support in fixing the code below. Am not sure if there is already a thread / idea for the below combination

What I am looking to achieve

1. Signal up arrow when both Supertrends (AltMult 2, Length 10) and ((AltMult 4, Length 10) are green and RSI (Length 14, OB 60 and OS 40) > 60;
2. Signal down arrow when both Supertrends (AltMult 2, Length 10) and ((AltMult 4, Length 10) are red and RSI (Length 14, OB 60 and OS 40) < 40;
3) If either of the above conditions are true, then plot SL/Target

This is working fine with the below code but I don't want the signal to reappear if the previous bar already has a signal and want to target/sl bars to continue till either the SL or target is met (if target is met then color should be green and SL is hit then color should be red - Please ignore if this is too much code)

https://tos.mx/acoKDRa
Ruby:
# ST 1
input ST_AltMult = 2;
input ST_Length = 10;
input Show_ST1_indicator = Yes;
def ATR1 = ATR(ST_Length, AverageType.HULL);
def UP_Band_Basic = HL2 + (ST_AltMult * ATR1);
def LW_Band_Basic = HL2 + (-ST_AltMult * ATR1);
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;

def Long_ST = if close > ST then ST else Double.NaN;
def Short_ST = if close < ST then ST else Double.NaN;

def LTrigger_ST = IsNaN(Long_ST[1]) and !IsNaN(Long_ST);
def STrigger_ST = IsNaN(Short_ST[1]) and !IsNaN(Short_ST);

plot Long =
if show_ST1_indicator then
(if close > ST then ST else Double.NaN) else double.nan;
Long.SetDefaultColor(Color.GREEN);
Long.SetLineWeight(1);

plot Short =
if show_ST1_indicator then
(if close < ST then ST else Double.NaN) else double.nan;
Short.SetDefaultColor(Color.RED);
Short.SetLineWeight(1);

def LongTrigger = IsNaN(Long[1]) and !IsNaN(Long);
def ShortTrigger = IsNaN(Short[1]) and !IsNaN(Short);

plot LongDot =
if show_ST1_indicator then
(if LongTrigger then ST else Double.NaN) else double.nan;
LongDot.SetPaintingStrategy(PaintingStrategy.POINTS);
LongDot.SetDefaultColor(Color.GREEN);
LongDot.SetLineWeight(1);

plot ShortDot =
if show_ST1_indicator then
(if ShortTrigger then ST else Double.NaN) else double.nan;
ShortDot.SetPaintingStrategy(PaintingStrategy.POINTS);
ShortDot.SetDefaultColor(Color.RED);
ShortDot.SetLineWeight(1);


# ST2
input ST1_AltMult = 4;
input ST1_Length = 10;
input Show_ST2_indicator = Yes;
def ATR2 = ATR(ST1_Length, AverageType.HULL);
def UP_Band_Basic1 = HL2 + (ST1_AltMult * ATR2);
def LW_Band_Basic1 = HL2 + (-ST1_AltMult * ATR2);
def UP_Band1 = if ((UP_Band_Basic1 < UP_Band1[1]) or (close[1] > UP_Band1[1])) then UP_Band_Basic1 else UP_Band1[1];
def LW_Band1 = if ((LW_Band_Basic1 > LW_Band1[1]) or (close[1] < LW_Band1[1])) then LW_Band_Basic1 else LW_Band1[1];

def ST1 = if ((ST1[1] == UP_Band1[1]) and (close < UP_Band1)) then UP_Band1
else if ((ST1[1] == UP_Band1[1]) and (close > UP_Band1)) then LW_Band1
else if ((ST1[1] == LW_Band1[1]) and (close > LW_Band1)) then LW_Band1
else if ((ST1[1] == LW_Band1) and (close < LW_Band1)) then UP_Band1
else LW_Band1;

def Long_ST1 = if close > ST1 then ST1 else Double.NaN;
def Short_ST1 = if close < ST1 then ST1 else Double.NaN;

def LTrigger_ST1 = IsNaN(Long_ST1[1]) and !IsNaN(Long_ST1);
def STrigger_ST1 = IsNaN(Short_ST1[1]) and !IsNaN(Short_ST1);

plot Long1 = if show_ST1_indicator then
(if close > ST1 then ST1 else Double.NaN)else Double.NaN;
Long1.SetDefaultColor(Color.GREEN);
Long1.SetLineWeight(1);

plot Short1 = if show_ST1_indicator then
(if close < ST1 then ST1 else Double.NaN)else Double.NaN;
Short1.SetDefaultColor(Color.RED);
Short1.SetLineWeight(1);

def LongTrigger1 = IsNaN(Long1[1]) and !IsNaN(Long1);
def ShortTrigger1 = IsNaN(Short1[1]) and !IsNaN(Short1);

plot LongDot1 = if show_ST1_indicator then
(if LongTrigger1 then ST1 else Double.NaN)else Double.NaN;
LongDot1.SetPaintingStrategy(PaintingStrategy.POINTS);
LongDot1.SetDefaultColor(Color.GREEN);
LongDot1.SetLineWeight(1);

plot ShortDot1 = if show_ST1_indicator then
(if ShortTrigger1 then ST1 else Double.NaN)else Double.NaN;
ShortDot1.SetPaintingStrategy(PaintingStrategy.POINTS);
ShortDot1.SetDefaultColor(Color.RED);
ShortDot1.SetLineWeight(1);

#RSI
input RSIOverbought = 60;
input RSIOversold = 40;
input RSILength = 14;
def NetChange = MovingAverage(AverageType.WILDERS, close - close[1], RSILength);
def TotChange = MovingAverage(AverageType.WILDERS, AbsValue(close - close[1]), RSILength);
def ChgRatio = if TotChange != 0 then NetChange / TotChange else 0;
def RSI_IND = 50 * (ChgRatio + 1);
def longRSI = RSI_IND > RSIOverbought;
def shortRSI = RSI_IND < RSIOversold;

def avoidzone1 = Long_st && Short_st1 ;
def avoidzone2 =  Long_st1 && Short_st;
AssignPriceColor(if avoidzone1
                then Color.GRAY
                else Color.CURRENT);
AssignPriceColor(if avoidzone2
                then Color.GRAY
                else Color.CURRENT);

def bullish =
Long_ST
&& Long_ST1
&& lONGRSI
;

def bearish =
Short_ST
&& Short_ST1
&& SHORTRSI
;



plot bullsignal =
bullish ;
bullsignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
bullsignal.SetDefaultColor(Color.MAGENTA);
bullsignal.SetLineWeight(5);

plot bearsignal =
bearish
;
bearsignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
bearsignal.SetDefaultColor(Color.MAGENTA);
bearsignal.SetLineWeight(5);



#SLF


input slf_length = 14;#(title="slf_length", defval=14, minval=1)
input slf_smoothing = {default RMA, SMA, EMA, WMA};#"slf_smoothing",
input slf_ATRFactor = 0.5;       # Multiplier
input slf_target = 1;
input slf_wicks = yes;
input slf_addSrpead = yes;
def slf_c = close;
def slf_h = high;
def slf_l = low;


def slf_ask  = Average(close(priceType = PriceType.ASK), 3);
def slf_bid  = Average(close(priceType = PriceType.BID), 3);
def slf_diff = AbsValue(slf_ask - slf_bid);

def slf_spread = if IsNaN(slf_diff) then 0 else slf_diff;

script ma_function {
    input slf_smoothing = "RMA";
    input source = close;
    input slf_length = 14;
    def maType;
    if slf_smoothing == "RMA" {
        maType = WildersSmoothing(source, slf_length);
    } else {
        if slf_smoothing == "SMA" {
            maType = SimpleMovingAvg(source, slf_length);
        } else {
            if slf_smoothing == "EMA" {
                maType =  ExpAverage(source, slf_length);
            } else {
                maType = WMA(source, slf_length);
            }
        }
    }
    plot return = maType;
}
def slf_tr = TrueRange(slf_h, slf_c, slf_l);
def slf_ATR = ma_function(slf_smoothing, slf_tr, slf_length) + If(slf_addSrpead, slf_spread, 0);
def slf_ATR1 = slf_ATR * slf_ATRFactor;
def ATRUp = slf_ATR1 + If(slf_wicks , slf_h , slf_c);
def ATRDn = If(slf_wicks , slf_l , slf_c) - slf_ATR1;



#TARGET AND SL
input SL_Type = {default "Candle_Cl",  "ATR", "ST" };
input Target_Mult = 1.5;
input SL_Lookback = 1;

def SL_Long;
def SL_Short;
def target_Long;
def target_Short;

switch (SL_Type) {
case "Candle_Cl":
    SL_Long = Lowest(low, SL_Lookback);;
    SL_Short = Highest(high, SL_Lookback);;
    target_Long = close + ((close - SL_Long) * Target_Mult);
    target_Short = close - ((SL_Short - close) * Target_Mult);
case  "ST":
    SL_Long = long;
    SL_Short = short;
    target_Long = close + ((close - SL_Long) * Target_Mult);
    target_Short = close - ((SL_Short - close) * Target_Mult);
case "ATR":
    SL_Long = atrDn;
    SL_Short = atrUp;
    target_Long = close + ((close - SL_Long) * Target_Mult);
    target_Short = close - ((SL_Short - close) * Target_Mult);
}

plot slbar_Long = if bullsignal then SL_Long else Double.NaN;
slbar_Long.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
slbar_Long.SetDefaultColor(Color.WHITE);
#AddChartBubble (slbar_Long, SL_Long, ROUND(CLOSE - SL_Long,0) , color.white, No);


plot slbar_Short = if bearsignal then SL_Short else Double.NaN;
slbar_Short.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
slbar_Short.SetDefaultColor(Color.WHITE);
#AddChartBubble (slbar_Short, SL_Short, ROUND(SL_Short-CLOSE ,0) , color.white, No);

plot Limitbar_Long = if bullsignal then target_Long else Double.NaN;
Limitbar_Long.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Limitbar_Long.SetDefaultColor(Color.WHITE);

plot Limitbar_Short = if bearsignal then target_Short else Double.NaN;
Limitbar_Short.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Limitbar_Short.SetDefaultColor(Color.WHITE);

this has an option to display only 1 arrow
input show_only_first_arrow = yes;

i wasn't sure about your comments in last sentence about SL line so i didn't do anything for that.

Code:
#supertrend_rsi_strat_0

#https://usethinkscript.com/threads/supertrend-rsi-strategy-help.16062/
#Forums Indicator Forums Questions UnAnswered Graveyard 
#SuperTrend RSI Strategy Help
#Futures_Beginner  Jul 12, 2023  #1
#May I please seek some support in fixing the code below. Am not sure if there is already a thread / idea for the below combination

#What I am looking to achieve

#1. Signal up arrow when both Supertrends (AltMult 2, Length 10) and ((AltMult 4, Length 10) are green and RSI (Length 14, OB 60 and OS 40) > 60;

#2. Signal down arrow when both Supertrends (AltMult 2, Length 10) and ((AltMult 4, Length 10) are red and RSI (Length 14, OB 60 and OS 40) < 40;

#3) If either of the above conditions are true, then plot SL/Target

#This is working fine with the below code but I don't want the signal to reappear if the previous bar already has a signal and want to target/sl bars to continue till either the SL or target is met (if target is met then color should be green and SL is hit then color should be red - Please ignore if this is too much code)

#https://tos.mx/acoKDRa

def na = double.nan;

# ST 1
input ST_AltMult = 2;
input ST_Length = 10;
input Show_ST1_indicator = Yes;
def ATR1 = ATR(ST_Length, AverageType.HULL);
def UP_Band_Basic = HL2 + (ST_AltMult * ATR1);
def LW_Band_Basic = HL2 + (-ST_AltMult * ATR1);
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;

def Long_ST = if close > ST then ST else Double.NaN;
def Short_ST = if close < ST then ST else Double.NaN;

def LTrigger_ST = IsNaN(Long_ST[1]) and !IsNaN(Long_ST);
def STrigger_ST = IsNaN(Short_ST[1]) and !IsNaN(Short_ST);

plot Long = if show_ST1_indicator then
   (if close > ST then ST
    else Double.NaN)
 else double.nan;
Long.SetDefaultColor(Color.GREEN);
Long.SetLineWeight(1);

plot Short = if show_ST1_indicator then
   (if close < ST then ST
    else Double.NaN)
  else double.nan;
Short.SetDefaultColor(Color.RED);
Short.SetLineWeight(1);

def LongTrigger = IsNaN(Long[1]) and !IsNaN(Long);
def ShortTrigger = IsNaN(Short[1]) and !IsNaN(Short);

plot LongDot = if show_ST1_indicator then
   (if LongTrigger then ST
    else Double.NaN)
  else double.nan;
LongDot.SetPaintingStrategy(PaintingStrategy.POINTS);
LongDot.SetDefaultColor(Color.GREEN);
LongDot.SetLineWeight(1);

plot ShortDot = if show_ST1_indicator then
   (if ShortTrigger then ST
    else Double.NaN)
  else double.nan;
ShortDot.SetPaintingStrategy(PaintingStrategy.POINTS);
ShortDot.SetDefaultColor(Color.RED);
ShortDot.SetLineWeight(1);


# ST2
input ST1_AltMult = 4;
input ST1_Length = 10;
input Show_ST2_indicator = Yes;
def ATR2 = ATR(ST1_Length, AverageType.HULL);
def UP_Band_Basic1 = HL2 + (ST1_AltMult * ATR2);
def LW_Band_Basic1 = HL2 + (-ST1_AltMult * ATR2);
def UP_Band1 = if ((UP_Band_Basic1 < UP_Band1[1]) or (close[1] > UP_Band1[1])) then UP_Band_Basic1 else UP_Band1[1];
def LW_Band1 = if ((LW_Band_Basic1 > LW_Band1[1]) or (close[1] < LW_Band1[1])) then LW_Band_Basic1 else LW_Band1[1];

def ST1 = if ((ST1[1] == UP_Band1[1]) and (close < UP_Band1)) then UP_Band1
else if ((ST1[1] == UP_Band1[1]) and (close > UP_Band1)) then LW_Band1
else if ((ST1[1] == LW_Band1[1]) and (close > LW_Band1)) then LW_Band1
else if ((ST1[1] == LW_Band1) and (close < LW_Band1)) then UP_Band1
else LW_Band1;

def Long_ST1 = if close > ST1 then ST1 else Double.NaN;
def Short_ST1 = if close < ST1 then ST1 else Double.NaN;

def LTrigger_ST1 = IsNaN(Long_ST1[1]) and !IsNaN(Long_ST1);
def STrigger_ST1 = IsNaN(Short_ST1[1]) and !IsNaN(Short_ST1);

plot Long1 = if show_ST1_indicator then 
   (if close > ST1 then ST1
    else Double.NaN)
  else Double.NaN;
Long1.SetDefaultColor(Color.GREEN);
Long1.SetLineWeight(1);

plot Short1 = if show_ST1_indicator then
(if close < ST1 then ST1 else Double.NaN)else Double.NaN;
Short1.SetDefaultColor(Color.RED);
Short1.SetLineWeight(1);

def LongTrigger1 = IsNaN(Long1[1]) and !IsNaN(Long1);
def ShortTrigger1 = IsNaN(Short1[1]) and !IsNaN(Short1);

plot LongDot1 = if show_ST1_indicator then
(if LongTrigger1 then ST1 else Double.NaN)else Double.NaN;
LongDot1.SetPaintingStrategy(PaintingStrategy.POINTS);
LongDot1.SetDefaultColor(Color.GREEN);
LongDot1.SetLineWeight(1);

plot ShortDot1 = if show_ST1_indicator then
(if ShortTrigger1 then ST1 else Double.NaN)else Double.NaN;
ShortDot1.SetPaintingStrategy(PaintingStrategy.POINTS);
ShortDot1.SetDefaultColor(Color.RED);
ShortDot1.SetLineWeight(1);

#RSI
input RSIOverbought = 60;
input RSIOversold = 40;
input RSILength = 14;
def NetChange = MovingAverage(AverageType.WILDERS, close - close[1], RSILength);
def TotChange = MovingAverage(AverageType.WILDERS, AbsValue(close - close[1]), RSILength);
def ChgRatio = if TotChange != 0 then NetChange / TotChange else 0;
def RSI_IND = 50 * (ChgRatio + 1);
def longRSI = RSI_IND > RSIOverbought;
def shortRSI = RSI_IND < RSIOversold;

def avoidzone1 = Long_st && Short_st1 ;
def avoidzone2 =  Long_st1 && Short_st;
AssignPriceColor(if avoidzone1
                then Color.GRAY
                else Color.CURRENT);
AssignPriceColor(if avoidzone2
                then Color.GRAY
                else Color.CURRENT);

def bullish = Long_ST and Long_ST1 and lONGRSI;
def bearish = Short_ST and Short_ST1 and SHORTRSI;


input show_only_first_arrow = yes;

#plot bullsignal = bullish;
plot bullsignal = if !show_only_first_arrow then bullish
 else if bullish[1] then na
 else bullish;

#plot bullsignal = if bullish[1] then na else bullish;
bullsignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
bullsignal.SetDefaultColor(Color.MAGENTA);
bullsignal.SetLineWeight(5);

#plot bearsignal = bearish;
plot bearsignal = if !show_only_first_arrow then bearish
 else if bearish[1] then na
 else bearish;

#plot bearsignal = if bearish[1] then na else bearish;
bearsignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
bearsignal.SetDefaultColor(Color.MAGENTA);
bearsignal.SetLineWeight(5);




#SLF

input slf_length = 14;#(title="slf_length", defval=14, minval=1)
input slf_smoothing = {default RMA, SMA, EMA, WMA};#"slf_smoothing",
input slf_ATRFactor = 0.5;       # Multiplier
input slf_target = 1;
input slf_wicks = yes;
input slf_addSrpead = yes;
def slf_c = close;
def slf_h = high;
def slf_l = low;


def slf_ask  = Average(close(priceType = PriceType.ASK), 3);
def slf_bid  = Average(close(priceType = PriceType.BID), 3);
def slf_diff = AbsValue(slf_ask - slf_bid);

def slf_spread = if IsNaN(slf_diff) then 0 else slf_diff;

script ma_function {
    input slf_smoothing = "RMA";
    input source = close;
    input slf_length = 14;
    def maType;
    if slf_smoothing == "RMA" {
        maType = WildersSmoothing(source, slf_length);
    } else {
        if slf_smoothing == "SMA" {
            maType = SimpleMovingAvg(source, slf_length);
        } else {
            if slf_smoothing == "EMA" {
                maType =  ExpAverage(source, slf_length);
            } else {
                maType = WMA(source, slf_length);
            }
        }
    }
    plot return = maType;
}
def slf_tr = TrueRange(slf_h, slf_c, slf_l);
def slf_ATR = ma_function(slf_smoothing, slf_tr, slf_length) + If(slf_addSrpead, slf_spread, 0);
def slf_ATR1 = slf_ATR * slf_ATRFactor;
def ATRUp = slf_ATR1 + If(slf_wicks , slf_h , slf_c);
def ATRDn = If(slf_wicks , slf_l , slf_c) - slf_ATR1;



#TARGET AND SL
input SL_Type = {default "Candle_Cl",  "ATR", "ST" };
input Target_Mult = 1.5;
input SL_Lookback = 1;

def SL_Long;
def SL_Short;
def target_Long;
def target_Short;

switch (SL_Type) {
case "Candle_Cl":
    SL_Long = Lowest(low, SL_Lookback);;
    SL_Short = Highest(high, SL_Lookback);;
    target_Long = close + ((close - SL_Long) * Target_Mult);
    target_Short = close - ((SL_Short - close) * Target_Mult);
case  "ST":
    SL_Long = long;
    SL_Short = short;
    target_Long = close + ((close - SL_Long) * Target_Mult);
    target_Short = close - ((SL_Short - close) * Target_Mult);
case "ATR":
    SL_Long = atrDn;
    SL_Short = atrUp;
    target_Long = close + ((close - SL_Long) * Target_Mult);
    target_Short = close - ((SL_Short - close) * Target_Mult);
}

plot slbar_Long = if bullsignal then SL_Long else Double.NaN;
slbar_Long.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
slbar_Long.SetDefaultColor(Color.WHITE);
#AddChartBubble (slbar_Long, SL_Long, ROUND(CLOSE - SL_Long,0) , color.white, No);


plot slbar_Short = if bearsignal then SL_Short else Double.NaN;
slbar_Short.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
slbar_Short.SetDefaultColor(Color.WHITE);
#AddChartBubble (slbar_Short, SL_Short, ROUND(SL_Short-CLOSE ,0) , color.white, No);

plot Limitbar_Long = if bullsignal then target_Long else Double.NaN;
Limitbar_Long.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Limitbar_Long.SetDefaultColor(Color.WHITE);

plot Limitbar_Short = if bearsignal then target_Short else Double.NaN;
Limitbar_Short.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Limitbar_Short.SetDefaultColor(Color.WHITE);
#
 
Solution

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Thread starter Similar threads Forum Replies Date
M SuperTrend + RSI Trigger Questions 3
N Looking For SuperTrend Questions 1
rvaidyamath TTM with SuperTrend Questions 0
PAYtience Supertrend with 2 timeframes Questions 0
M Supertrend indicator Questions 3

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
428 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top