3x SuperTrend

barbaros

Administrator
Staff member
This strategy combines 3 SuperTrend indicators with stochastic RSI and 200 EMA for some great results.

gz9XFLY.png


Indicators and settings:
  • SuperTrend can be found here.
    • UseEmaCross: No
    • Show Bubbles: No
    • Paint Bars: No
    • SuperTrend #1
      • atr mult: 3
      • nAtr: 12
    • SuperTrend #2
      • atr mult: 2
      • nAtr: 11
    • SuperTrend #3
      • atr mult: 1
      • nAtr: 10
  • StochasticRSI is built into Thinkorswim with name "StochRSI".
    • RSI length: 14
    • K period: 14
    • D period: 3
    • Slowing period: 3
  • EMA is built into Thinkorswim with name "MovAvgExponential"
    • Period: 200
Long position rules:
  • Price is above EMA
  • Stochastic is in the oversold territory and crosses above
  • At least 2 SuperTrend is in long direction
Short position rules:
  • Price is below EMA
  • Stochastic is in the overbought territory and crosses below
  • At least 2 SuperTrend is in short direction
 

klo12

New member
Is it possible to create a backtester in TOS to know the win rate of any given stock using this strategy.
 

Fluideng

New member
I've unified the Indicator. Need help with the order entries and exits to make it a Strategy. This strategy looks good on a lower time frame, 3 and 5 minute.


Code:
# SuperTrend Yahoo Finance Replica - Modified from Modius SuperTrend
# Modified Modius ver. by RConner7
# Modified by Barbaros to replicate look from TradingView version
# Modified by Barbaros to add EMA cross for bubbles and alerts
# Modified by Barbaros to update bar color painting
# v3.3
# Modified by Fluideng to make the triple SuplerTrend into one indicator. Also removed EMA2 and Bar color.

### SuperTrend #1
input AtrMult = 3.00;
input nATR = 12;
input AvgType = AverageType.HULL;

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 Long = if close > ST then ST else Double.NaN;
Long.AssignValueColor(Color.GREEN);
Long.SetLineWeight(2);

plot Short = if close < ST then ST else Double.NaN;
Short.AssignValueColor(Color.RED);
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.GREEN);
LongDot.SetLineWeight(4);

plot ShortDot = if ShortTrigger then ST else Double.NaN;
ShortDot.SetPaintingStrategy(PaintingStrategy.POINTS);
ShortDot.AssignValueColor(Color.RED);
ShortDot.SetLineWeight(4);

### SuperTrend #2
input AtrMult2 = 2.00;
input nATR2 = 11;

def ATR2 = ATR("length" = nATR2, "average type" = AvgType);
def UP_Band_Basic2 = HL2 + (AtrMult2 * ATR);
def LW_Band_Basic2 = HL2 + (-AtrMult2 * ATR);
def UP_Band2 = if ((UP_Band_Basic2 < UP_Band2[1]) or (close[1] > UP_Band2[1])) then UP_Band_Basic2 else UP_Band2[1];
def LW_Band2 = if ((LW_Band_Basic2 > LW_Band2[1]) or (close[1] < LW_Band2[1])) then LW_Band_Basic2 else LW_Band2[1];

def ST2 = if ((ST2[1] == UP_Band2[1]) and (close < UP_Band2)) then UP_Band2
else if ((ST2[1] == UP_Band2[1]) and (close > Up_Band2)) then LW_Band2
else if ((ST2[1] == LW_Band2[1]) and (close > LW_Band2)) then LW_Band2
else if ((ST2[1] == LW_Band2) and (close < LW_Band2)) then UP_Band2
else LW_Band2;

plot Long2 = if close > ST2 then ST2 else Double.NaN;
Long2.AssignValueColor(Color.GREEN);
Long2.SetLineWeight(2);

plot Short2 = if close < ST2 then ST2 else Double.NaN;
Short2.AssignValueColor(Color.RED);
Short2.SetLineWeight(3);

def LongTrigger2 = isNaN(Long2[1]) and !isNaN(Long2);
def ShortTrigger2 = isNaN(Short2[1]) and !isNaN(Short2);

plot LongDot2 = if LongTrigger2 then ST2 else Double.NaN;
LongDot2.SetPaintingStrategy(PaintingStrategy.POINTS);
LongDot2.AssignValueColor(Color.GREEN);
LongDot2.SetLineWeight(4);

plot ShortDot2 = if ShortTrigger2 then ST2 else Double.NaN;
ShortDot2.SetPaintingStrategy(PaintingStrategy.POINTS);
ShortDot2.AssignValueColor(Color.RED);
ShortDot2.SetLineWeight(4);

### SuperTrend #3
input AtrMult3 = 1.00;
input nATR3 = 10;

def ATR3 = ATR("length" = nATR3, "average type" = AvgType);
def UP_Band_Basic3 = HL2 + (AtrMult3 * ATR);
def LW_Band_Basic3 = HL2 + (-AtrMult3 * ATR);
def UP_Band3 = if ((UP_Band_Basic3 < UP_Band3[1]) or (close[1] > UP_Band3[1])) then UP_Band_Basic3 else UP_Band3[1];
def LW_Band3 = if ((LW_Band_Basic3 > LW_Band3[1]) or (close[1] < LW_Band3[1])) then LW_Band_Basic3 else LW_Band3[1];

def ST3 = if ((ST3[1] == UP_Band3[1]) and (close < UP_Band3)) then UP_Band3
else if ((ST3[1] == UP_Band3[1]) and (close > Up_Band3)) then LW_Band3
else if ((ST3[1] == LW_Band3[1]) and (close > LW_Band3)) then LW_Band3
else if ((ST3[1] == LW_Band3) and (close < LW_Band3)) then UP_Band3
else LW_Band3;

plot Long3 = if close > ST3 then ST3 else Double.NaN;
Long3.AssignValueColor(Color.GREEN);
Long3.SetLineWeight(2);

plot Short3 = if close < ST3 then ST3 else Double.NaN;
Short3.AssignValueColor(Color.RED);
Short3.SetLineWeight(3);

def LongTrigger3 = isNaN(Long3[1]) and !isNaN(Long3);
def ShortTrigger3 = isNaN(Short3[1]) and !isNaN(Short3);

plot LongDot3 = if LongTrigger3 then ST3 else Double.NaN;
LongDot3.SetPaintingStrategy(PaintingStrategy.POINTS);
LongDot3.AssignValueColor(Color.GREEN);
LongDot3.SetLineWeight(4);

plot ShortDot3 = if ShortTrigger3 then ST3 else Double.NaN;
ShortDot3.SetPaintingStrategy(PaintingStrategy.POINTS);
ShortDot3.AssignValueColor(Color.RED);
ShortDot3.SetLineWeight(4);

# End Code SuperTrend Yahoo Finance Replica

###### 200 EMA  ######
input price = close;
input EMA_length = 200;
input displace = 0;

plot AvgExp = ExpAverage(price[-displace], EMA_length);
AvgExp.SetDefaultColor(GetColor(1));

#######   StochRSI   ##########

input RSI_length = 14;
input over_bought = 80;
input over_sold = 20;
input RSI_average_type = AverageType.WILDERS;
input RSI_price = close;
input KPeriod = 14;
input DPeriod = 3;
input slowing_period = 3;
input averageType = AverageType.SIMPLE;
input showBreakoutSignals = {default "No", "On FullK", "On FullD", "On FullK & FullD"};

def RSI = RSI(price = RSI_price, length = RSI_length, averageType = RSI_average_type);
def FullK = StochasticFull(over_bought, over_sold, KPeriod, DPeriod, RSI, RSI, RSI, slowing_period, averageType).FullK;
def FullD = StochasticFull(over_bought, over_sold, KPeriod, DPeriod, RSI, RSI, RSI, slowing_period, averageType).FullD;
def OverBought = over_bought;
def OverSold = over_sold;

def upK = FullK crosses above OverSold;
def upD = FullD crosses above OverSold;
def downK = FullK crosses below OverBought;
def downD = FullD crosses below OverBought;

#plot UpSignal;
#plot DownSignal;
switch (showBreakoutSignals) {
case "No":
#    UpSignal = Double.NaN;
#    DownSignal = Double.NaN;
case "On FullK":
#    UpSignal = if upK then OverSold else Double.NaN;
#   DownSignal = if downK then OverBought else Double.NaN;
case "On FullD":
#    UpSignal = if upD then OverSold else Double.NaN;
#   DownSignal = if downD then OverBought else Double.NaN;
case "On FullK & FullD":
#    UpSignal = if upK or upD then OverSold else Double.NaN;
#    DownSignal = if downK or downD then OverBought else Double.NaN;
}

#UpSignal.setHiding(showBreakoutSignals == showBreakoutSignals."No");
#DownSignal.setHiding(showBreakoutSignals == showBreakoutSignals."No");

#FullK.SetDefaultColor(GetColor(5));
#FullD.SetDefaultColor(GetColor(0));
#OverBought.SetDefaultColor(GetColor(1));
#OverSold.SetDefaultColor(GetColor(1));
#UpSignal.SetDefaultColor(Color.UPTICK);
#UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
#DownSignal.SetDefaultColor(Color.DOWNTICK);
#DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
 

barbaros

Administrator
Staff member
I've unified the Indicator. Need help with the order entries and exits to make it a Strategy. This strategy looks good on a lower time frame, 3 and 5 minute.


Code:
# SuperTrend Yahoo Finance Replica - Modified from Modius SuperTrend
# Modified Modius ver. by RConner7
# Modified by Barbaros to replicate look from TradingView version
# Modified by Barbaros to add EMA cross for bubbles and alerts
# Modified by Barbaros to update bar color painting
# v3.3
# Modified by Fluideng to make the triple SuplerTrend into one indicator. Also removed EMA2 and Bar color.

### SuperTrend #1
input AtrMult = 3.00;
input nATR = 12;
input AvgType = AverageType.HULL;

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 Long = if close > ST then ST else Double.NaN;
Long.AssignValueColor(Color.GREEN);
Long.SetLineWeight(2);

plot Short = if close < ST then ST else Double.NaN;
Short.AssignValueColor(Color.RED);
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.GREEN);
LongDot.SetLineWeight(4);

plot ShortDot = if ShortTrigger then ST else Double.NaN;
ShortDot.SetPaintingStrategy(PaintingStrategy.POINTS);
ShortDot.AssignValueColor(Color.RED);
ShortDot.SetLineWeight(4);

### SuperTrend #2
input AtrMult2 = 2.00;
input nATR2 = 11;

def ATR2 = ATR("length" = nATR2, "average type" = AvgType);
def UP_Band_Basic2 = HL2 + (AtrMult2 * ATR);
def LW_Band_Basic2 = HL2 + (-AtrMult2 * ATR);
def UP_Band2 = if ((UP_Band_Basic2 < UP_Band2[1]) or (close[1] > UP_Band2[1])) then UP_Band_Basic2 else UP_Band2[1];
def LW_Band2 = if ((LW_Band_Basic2 > LW_Band2[1]) or (close[1] < LW_Band2[1])) then LW_Band_Basic2 else LW_Band2[1];

def ST2 = if ((ST2[1] == UP_Band2[1]) and (close < UP_Band2)) then UP_Band2
else if ((ST2[1] == UP_Band2[1]) and (close > Up_Band2)) then LW_Band2
else if ((ST2[1] == LW_Band2[1]) and (close > LW_Band2)) then LW_Band2
else if ((ST2[1] == LW_Band2) and (close < LW_Band2)) then UP_Band2
else LW_Band2;

plot Long2 = if close > ST2 then ST2 else Double.NaN;
Long2.AssignValueColor(Color.GREEN);
Long2.SetLineWeight(2);

plot Short2 = if close < ST2 then ST2 else Double.NaN;
Short2.AssignValueColor(Color.RED);
Short2.SetLineWeight(3);

def LongTrigger2 = isNaN(Long2[1]) and !isNaN(Long2);
def ShortTrigger2 = isNaN(Short2[1]) and !isNaN(Short2);

plot LongDot2 = if LongTrigger2 then ST2 else Double.NaN;
LongDot2.SetPaintingStrategy(PaintingStrategy.POINTS);
LongDot2.AssignValueColor(Color.GREEN);
LongDot2.SetLineWeight(4);

plot ShortDot2 = if ShortTrigger2 then ST2 else Double.NaN;
ShortDot2.SetPaintingStrategy(PaintingStrategy.POINTS);
ShortDot2.AssignValueColor(Color.RED);
ShortDot2.SetLineWeight(4);

### SuperTrend #3
input AtrMult3 = 1.00;
input nATR3 = 10;

def ATR3 = ATR("length" = nATR3, "average type" = AvgType);
def UP_Band_Basic3 = HL2 + (AtrMult3 * ATR);
def LW_Band_Basic3 = HL2 + (-AtrMult3 * ATR);
def UP_Band3 = if ((UP_Band_Basic3 < UP_Band3[1]) or (close[1] > UP_Band3[1])) then UP_Band_Basic3 else UP_Band3[1];
def LW_Band3 = if ((LW_Band_Basic3 > LW_Band3[1]) or (close[1] < LW_Band3[1])) then LW_Band_Basic3 else LW_Band3[1];

def ST3 = if ((ST3[1] == UP_Band3[1]) and (close < UP_Band3)) then UP_Band3
else if ((ST3[1] == UP_Band3[1]) and (close > Up_Band3)) then LW_Band3
else if ((ST3[1] == LW_Band3[1]) and (close > LW_Band3)) then LW_Band3
else if ((ST3[1] == LW_Band3) and (close < LW_Band3)) then UP_Band3
else LW_Band3;

plot Long3 = if close > ST3 then ST3 else Double.NaN;
Long3.AssignValueColor(Color.GREEN);
Long3.SetLineWeight(2);

plot Short3 = if close < ST3 then ST3 else Double.NaN;
Short3.AssignValueColor(Color.RED);
Short3.SetLineWeight(3);

def LongTrigger3 = isNaN(Long3[1]) and !isNaN(Long3);
def ShortTrigger3 = isNaN(Short3[1]) and !isNaN(Short3);

plot LongDot3 = if LongTrigger3 then ST3 else Double.NaN;
LongDot3.SetPaintingStrategy(PaintingStrategy.POINTS);
LongDot3.AssignValueColor(Color.GREEN);
LongDot3.SetLineWeight(4);

plot ShortDot3 = if ShortTrigger3 then ST3 else Double.NaN;
ShortDot3.SetPaintingStrategy(PaintingStrategy.POINTS);
ShortDot3.AssignValueColor(Color.RED);
ShortDot3.SetLineWeight(4);

# End Code SuperTrend Yahoo Finance Replica

###### 200 EMA  ######
input price = close;
input EMA_length = 200;
input displace = 0;

plot AvgExp = ExpAverage(price[-displace], EMA_length);
AvgExp.SetDefaultColor(GetColor(1));

#######   StochRSI   ##########

input RSI_length = 14;
input over_bought = 80;
input over_sold = 20;
input RSI_average_type = AverageType.WILDERS;
input RSI_price = close;
input KPeriod = 14;
input DPeriod = 3;
input slowing_period = 3;
input averageType = AverageType.SIMPLE;
input showBreakoutSignals = {default "No", "On FullK", "On FullD", "On FullK & FullD"};

def RSI = RSI(price = RSI_price, length = RSI_length, averageType = RSI_average_type);
def FullK = StochasticFull(over_bought, over_sold, KPeriod, DPeriod, RSI, RSI, RSI, slowing_period, averageType).FullK;
def FullD = StochasticFull(over_bought, over_sold, KPeriod, DPeriod, RSI, RSI, RSI, slowing_period, averageType).FullD;
def OverBought = over_bought;
def OverSold = over_sold;

def upK = FullK crosses above OverSold;
def upD = FullD crosses above OverSold;
def downK = FullK crosses below OverBought;
def downD = FullD crosses below OverBought;

#plot UpSignal;
#plot DownSignal;
switch (showBreakoutSignals) {
case "No":
#    UpSignal = Double.NaN;
#    DownSignal = Double.NaN;
case "On FullK":
#    UpSignal = if upK then OverSold else Double.NaN;
#   DownSignal = if downK then OverBought else Double.NaN;
case "On FullD":
#    UpSignal = if upD then OverSold else Double.NaN;
#   DownSignal = if downD then OverBought else Double.NaN;
case "On FullK & FullD":
#    UpSignal = if upK or upD then OverSold else Double.NaN;
#    DownSignal = if downK or downD then OverBought else Double.NaN;
}

#UpSignal.setHiding(showBreakoutSignals == showBreakoutSignals."No");
#DownSignal.setHiding(showBreakoutSignals == showBreakoutSignals."No");

#FullK.SetDefaultColor(GetColor(5));
#FullD.SetDefaultColor(GetColor(0));
#OverBought.SetDefaultColor(GetColor(1));
#OverSold.SetDefaultColor(GetColor(1));
#UpSignal.SetDefaultColor(Color.UPTICK);
#UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
#DownSignal.SetDefaultColor(Color.DOWNTICK);
#DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
Take a look at https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Others/AddOrder

If you still need help, let us know.
 

barbaros

Administrator
Staff member
I've unified the Indicator. Need help with the order entries and exits to make it a Strategy. This strategy looks good on a lower time frame, 3 and 5 minute.


Code:
# SuperTrend Yahoo Finance Replica - Modified from Modius SuperTrend
# Modified Modius ver. by RConner7
# Modified by Barbaros to replicate look from TradingView version
# Modified by Barbaros to add EMA cross for bubbles and alerts
# Modified by Barbaros to update bar color painting
# v3.3
# Modified by Fluideng to make the triple SuplerTrend into one indicator. Also removed EMA2 and Bar color.

### SuperTrend #1
input AtrMult = 3.00;
input nATR = 12;
input AvgType = AverageType.HULL;

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 Long = if close > ST then ST else Double.NaN;
Long.AssignValueColor(Color.GREEN);
Long.SetLineWeight(2);

plot Short = if close < ST then ST else Double.NaN;
Short.AssignValueColor(Color.RED);
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.GREEN);
LongDot.SetLineWeight(4);

plot ShortDot = if ShortTrigger then ST else Double.NaN;
ShortDot.SetPaintingStrategy(PaintingStrategy.POINTS);
ShortDot.AssignValueColor(Color.RED);
ShortDot.SetLineWeight(4);

### SuperTrend #2
input AtrMult2 = 2.00;
input nATR2 = 11;

def ATR2 = ATR("length" = nATR2, "average type" = AvgType);
def UP_Band_Basic2 = HL2 + (AtrMult2 * ATR);
def LW_Band_Basic2 = HL2 + (-AtrMult2 * ATR);
def UP_Band2 = if ((UP_Band_Basic2 < UP_Band2[1]) or (close[1] > UP_Band2[1])) then UP_Band_Basic2 else UP_Band2[1];
def LW_Band2 = if ((LW_Band_Basic2 > LW_Band2[1]) or (close[1] < LW_Band2[1])) then LW_Band_Basic2 else LW_Band2[1];

def ST2 = if ((ST2[1] == UP_Band2[1]) and (close < UP_Band2)) then UP_Band2
else if ((ST2[1] == UP_Band2[1]) and (close > Up_Band2)) then LW_Band2
else if ((ST2[1] == LW_Band2[1]) and (close > LW_Band2)) then LW_Band2
else if ((ST2[1] == LW_Band2) and (close < LW_Band2)) then UP_Band2
else LW_Band2;

plot Long2 = if close > ST2 then ST2 else Double.NaN;
Long2.AssignValueColor(Color.GREEN);
Long2.SetLineWeight(2);

plot Short2 = if close < ST2 then ST2 else Double.NaN;
Short2.AssignValueColor(Color.RED);
Short2.SetLineWeight(3);

def LongTrigger2 = isNaN(Long2[1]) and !isNaN(Long2);
def ShortTrigger2 = isNaN(Short2[1]) and !isNaN(Short2);

plot LongDot2 = if LongTrigger2 then ST2 else Double.NaN;
LongDot2.SetPaintingStrategy(PaintingStrategy.POINTS);
LongDot2.AssignValueColor(Color.GREEN);
LongDot2.SetLineWeight(4);

plot ShortDot2 = if ShortTrigger2 then ST2 else Double.NaN;
ShortDot2.SetPaintingStrategy(PaintingStrategy.POINTS);
ShortDot2.AssignValueColor(Color.RED);
ShortDot2.SetLineWeight(4);

### SuperTrend #3
input AtrMult3 = 1.00;
input nATR3 = 10;

def ATR3 = ATR("length" = nATR3, "average type" = AvgType);
def UP_Band_Basic3 = HL2 + (AtrMult3 * ATR);
def LW_Band_Basic3 = HL2 + (-AtrMult3 * ATR);
def UP_Band3 = if ((UP_Band_Basic3 < UP_Band3[1]) or (close[1] > UP_Band3[1])) then UP_Band_Basic3 else UP_Band3[1];
def LW_Band3 = if ((LW_Band_Basic3 > LW_Band3[1]) or (close[1] < LW_Band3[1])) then LW_Band_Basic3 else LW_Band3[1];

def ST3 = if ((ST3[1] == UP_Band3[1]) and (close < UP_Band3)) then UP_Band3
else if ((ST3[1] == UP_Band3[1]) and (close > Up_Band3)) then LW_Band3
else if ((ST3[1] == LW_Band3[1]) and (close > LW_Band3)) then LW_Band3
else if ((ST3[1] == LW_Band3) and (close < LW_Band3)) then UP_Band3
else LW_Band3;

plot Long3 = if close > ST3 then ST3 else Double.NaN;
Long3.AssignValueColor(Color.GREEN);
Long3.SetLineWeight(2);

plot Short3 = if close < ST3 then ST3 else Double.NaN;
Short3.AssignValueColor(Color.RED);
Short3.SetLineWeight(3);

def LongTrigger3 = isNaN(Long3[1]) and !isNaN(Long3);
def ShortTrigger3 = isNaN(Short3[1]) and !isNaN(Short3);

plot LongDot3 = if LongTrigger3 then ST3 else Double.NaN;
LongDot3.SetPaintingStrategy(PaintingStrategy.POINTS);
LongDot3.AssignValueColor(Color.GREEN);
LongDot3.SetLineWeight(4);

plot ShortDot3 = if ShortTrigger3 then ST3 else Double.NaN;
ShortDot3.SetPaintingStrategy(PaintingStrategy.POINTS);
ShortDot3.AssignValueColor(Color.RED);
ShortDot3.SetLineWeight(4);

# End Code SuperTrend Yahoo Finance Replica

###### 200 EMA  ######
input price = close;
input EMA_length = 200;
input displace = 0;

plot AvgExp = ExpAverage(price[-displace], EMA_length);
AvgExp.SetDefaultColor(GetColor(1));

#######   StochRSI   ##########

input RSI_length = 14;
input over_bought = 80;
input over_sold = 20;
input RSI_average_type = AverageType.WILDERS;
input RSI_price = close;
input KPeriod = 14;
input DPeriod = 3;
input slowing_period = 3;
input averageType = AverageType.SIMPLE;
input showBreakoutSignals = {default "No", "On FullK", "On FullD", "On FullK & FullD"};

def RSI = RSI(price = RSI_price, length = RSI_length, averageType = RSI_average_type);
def FullK = StochasticFull(over_bought, over_sold, KPeriod, DPeriod, RSI, RSI, RSI, slowing_period, averageType).FullK;
def FullD = StochasticFull(over_bought, over_sold, KPeriod, DPeriod, RSI, RSI, RSI, slowing_period, averageType).FullD;
def OverBought = over_bought;
def OverSold = over_sold;

def upK = FullK crosses above OverSold;
def upD = FullD crosses above OverSold;
def downK = FullK crosses below OverBought;
def downD = FullD crosses below OverBought;

#plot UpSignal;
#plot DownSignal;
switch (showBreakoutSignals) {
case "No":
#    UpSignal = Double.NaN;
#    DownSignal = Double.NaN;
case "On FullK":
#    UpSignal = if upK then OverSold else Double.NaN;
#   DownSignal = if downK then OverBought else Double.NaN;
case "On FullD":
#    UpSignal = if upD then OverSold else Double.NaN;
#   DownSignal = if downD then OverBought else Double.NaN;
case "On FullK & FullD":
#    UpSignal = if upK or upD then OverSold else Double.NaN;
#    DownSignal = if downK or downD then OverBought else Double.NaN;
}

#UpSignal.setHiding(showBreakoutSignals == showBreakoutSignals."No");
#DownSignal.setHiding(showBreakoutSignals == showBreakoutSignals."No");

#FullK.SetDefaultColor(GetColor(5));
#FullD.SetDefaultColor(GetColor(0));
#OverBought.SetDefaultColor(GetColor(1));
#OverSold.SetDefaultColor(GetColor(1));
#UpSignal.SetDefaultColor(Color.UPTICK);
#UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
#DownSignal.SetDefaultColor(Color.DOWNTICK);
#DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
Double check my logic there...

Python:
# SuperTrend Yahoo Finance Replica - Modified from Modius SuperTrend
# Modified Modius ver. by RConner7
# Modified by Barbaros to replicate look from TradingView version
# Modified by Barbaros to add EMA cross for bubbles and alerts
# Modified by Barbaros to update bar color painting
# v3.3
# Modified by Fluideng to make the triple SuplerTrend into one indicator. Also removed EMA2 and Bar color.
# Madified by Barbaros to show strategy signals

### SuperTrend #1
input AtrMult = 3.00;
input nATR = 12;
input AvgType = AverageType.HULL;

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 Long = if close > ST then ST else Double.NaN;
Long.AssignValueColor(Color.GREEN);
Long.SetLineWeight(2);

plot Short = if close < ST then ST else Double.NaN;
Short.AssignValueColor(Color.RED);
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.GREEN);
LongDot.SetLineWeight(4);

plot ShortDot = if ShortTrigger then ST else Double.NaN;
ShortDot.SetPaintingStrategy(PaintingStrategy.POINTS);
ShortDot.AssignValueColor(Color.RED);
ShortDot.SetLineWeight(4);

### SuperTrend #2
input AtrMult2 = 2.00;
input nATR2 = 11;

def ATR2 = ATR("length" = nATR2, "average type" = AvgType);
def UP_Band_Basic2 = HL2 + (AtrMult2 * ATR);
def LW_Band_Basic2 = HL2 + (-AtrMult2 * ATR);
def UP_Band2 = if ((UP_Band_Basic2 < UP_Band2[1]) or (close[1] > UP_Band2[1])) then UP_Band_Basic2 else UP_Band2[1];
def LW_Band2 = if ((LW_Band_Basic2 > LW_Band2[1]) or (close[1] < LW_Band2[1])) then LW_Band_Basic2 else LW_Band2[1];

def ST2 = if ((ST2[1] == UP_Band2[1]) and (close < UP_Band2)) then UP_Band2
else if ((ST2[1] == UP_Band2[1]) and (close > Up_Band2)) then LW_Band2
else if ((ST2[1] == LW_Band2[1]) and (close > LW_Band2)) then LW_Band2
else if ((ST2[1] == LW_Band2) and (close < LW_Band2)) then UP_Band2
else LW_Band2;

plot Long2 = if close > ST2 then ST2 else Double.NaN;
Long2.AssignValueColor(Color.GREEN);
Long2.SetLineWeight(2);

plot Short2 = if close < ST2 then ST2 else Double.NaN;
Short2.AssignValueColor(Color.RED);
Short2.SetLineWeight(3);

def LongTrigger2 = isNaN(Long2[1]) and !isNaN(Long2);
def ShortTrigger2 = isNaN(Short2[1]) and !isNaN(Short2);

plot LongDot2 = if LongTrigger2 then ST2 else Double.NaN;
LongDot2.SetPaintingStrategy(PaintingStrategy.POINTS);
LongDot2.AssignValueColor(Color.GREEN);
LongDot2.SetLineWeight(4);

plot ShortDot2 = if ShortTrigger2 then ST2 else Double.NaN;
ShortDot2.SetPaintingStrategy(PaintingStrategy.POINTS);
ShortDot2.AssignValueColor(Color.RED);
ShortDot2.SetLineWeight(4);

### SuperTrend #3
input AtrMult3 = 1.00;
input nATR3 = 10;

def ATR3 = ATR("length" = nATR3, "average type" = AvgType);
def UP_Band_Basic3 = HL2 + (AtrMult3 * ATR);
def LW_Band_Basic3 = HL2 + (-AtrMult3 * ATR);
def UP_Band3 = if ((UP_Band_Basic3 < UP_Band3[1]) or (close[1] > UP_Band3[1])) then UP_Band_Basic3 else UP_Band3[1];
def LW_Band3 = if ((LW_Band_Basic3 > LW_Band3[1]) or (close[1] < LW_Band3[1])) then LW_Band_Basic3 else LW_Band3[1];

def ST3 = if ((ST3[1] == UP_Band3[1]) and (close < UP_Band3)) then UP_Band3
else if ((ST3[1] == UP_Band3[1]) and (close > Up_Band3)) then LW_Band3
else if ((ST3[1] == LW_Band3[1]) and (close > LW_Band3)) then LW_Band3
else if ((ST3[1] == LW_Band3) and (close < LW_Band3)) then UP_Band3
else LW_Band3;

plot Long3 = if close > ST3 then ST3 else Double.NaN;
Long3.AssignValueColor(Color.GREEN);
Long3.SetLineWeight(2);

plot Short3 = if close < ST3 then ST3 else Double.NaN;
Short3.AssignValueColor(Color.RED);
Short3.SetLineWeight(3);

def LongTrigger3 = isNaN(Long3[1]) and !isNaN(Long3);
def ShortTrigger3 = isNaN(Short3[1]) and !isNaN(Short3);

plot LongDot3 = if LongTrigger3 then ST3 else Double.NaN;
LongDot3.SetPaintingStrategy(PaintingStrategy.POINTS);
LongDot3.AssignValueColor(Color.GREEN);
LongDot3.SetLineWeight(4);

plot ShortDot3 = if ShortTrigger3 then ST3 else Double.NaN;
ShortDot3.SetPaintingStrategy(PaintingStrategy.POINTS);
ShortDot3.AssignValueColor(Color.RED);
ShortDot3.SetLineWeight(4);

# End Code SuperTrend Yahoo Finance Replica

###### 200 EMA  ######
input price = close;
input EMA_length = 200;
input displace = 0;

plot AvgExp = ExpAverage(price[-displace], EMA_length);
AvgExp.SetDefaultColor(GetColor(1));

#######   StochRSI   ##########

input RSI_length = 14;
input over_bought = 80;
input over_sold = 20;
input RSI_average_type = AverageType.WILDERS;
input RSI_price = close;
input KPeriod = 14;
input DPeriod = 3;
input slowing_period = 3;
input averageType = AverageType.SIMPLE;
input showBreakoutSignals = {"No", "On FullK", "On FullD", default "On FullK & FullD"};

def RSI = RSI(price = RSI_price, length = RSI_length, averageType = RSI_average_type);
def FullK = StochasticFull(over_bought, over_sold, KPeriod, DPeriod, RSI, RSI, RSI, slowing_period, averageType).FullK;
def FullD = StochasticFull(over_bought, over_sold, KPeriod, DPeriod, RSI, RSI, RSI, slowing_period, averageType).FullD;
def OverBought = over_bought;
def OverSold = over_sold;

def upK = FullK crosses above OverSold;
def upD = FullD crosses above OverSold;
def downK = FullK crosses below OverBought;
def downD = FullD crosses below OverBought;

def UpSignal;
def DownSignal;
switch (showBreakoutSignals) {
case "No":
    UpSignal = no;
    DownSignal = no;
case "On FullK":
    UpSignal = upK;
   DownSignal = downK;
case "On FullD":
    UpSignal = upD;
   DownSignal = downD;
case "On FullK & FullD":
    UpSignal = upK or upD;
    DownSignal = downK or downD;
}

# Strategy

input SuperTrendConfirmationLevel = 2;

def ST_Bullish = (if !isNaN(Long) then 1 else 0) + (if !isNaN(Long) then 1 else 0) + (if !isNaN(Long) then 1 else 0);
def ST_Bearish = (if !isNaN(Short) then 1 else 0) + (if !isNaN(Short) then 1 else 0) + (if !isNaN(Short) then 1 else 0);

def SellSignal = close < AvgExp and (ST_Bearish >= SuperTrendConfirmationLevel) and !isNaN(DownSignal);
def BuySignal = close > AvgExp and (ST_Bullish >= SuperTrendConfirmationLevel) and !isNaN(UpSignal);

plot ShortEntry = SellSignal and !SellSignal[1];
ShortEntry.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
ShortEntry.SetDefaultColor(Color.RED);

plot LongEntry = BuySignal and !BuySignal[1];
LongEntry.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
LongEntry.SetDefaultColor(Color.GREEN);

input ShowStrategyBubbles = yes;
AddChartBubble(ShortEntry, high, "Sell", Color.RED);
AddChartBubble(LongEntry, low, "Buy", Color.GREEN, no);
 

5StaRScalper

New member
@barbaros well thats awesome! I dont know much about coding but I can learn pretty quick haha or whatever you need me to do to help. I really dont need it as I have a powerful PC so I can easily just trade off the DOM and Tos chart but..... I wanna get completely away from tos if possible and best case if one platform is lagging badly then the other one may be ok! Thanks for considering it though and if you dont decide to do it.... how much would be a fair price to pay someone to do it? That is if I even can lol..,.,..I know your websites name is in the code...... atleast in the thinkscript version!
 

barbaros

Administrator
Staff member
@barbaros well thats awesome! I dont know much about coding but I can learn pretty quick haha or whatever you need me to do to help. I really dont need it as I have a powerful PC so I can easily just trade off the DOM and Tos chart but..... I wanna get completely away from tos if possible and best case if one platform is lagging badly then the other one may be ok! Thanks for considering it though and if you dont decide to do it.... how much would be a fair price to pay someone to do it? That is if I even can lol..,.,..I know your websites name is in the code...... atleast in the thinkscript version!
Let's discuss to see what we can do for you.
 
Can anyone come up with a scanner for both a long and short version showing when the first bar occurs that all 3 supertrends are the same color and above/ below the 200EMA and put arrows and alerts when all 3 supertrends are green and close is above the 200 EMA and vice versa. I would prefer to leave out the stochastic part of the orginal all in one indicator if possible. Thanks in advance
 
Top