Repaints Chewie's Super Trend, Hull Average, Donchian Trend Ribbon Trading System for ThinkorSwim

Repaints
@chewie76 @AnimalMother The following step-by-step outlines how to successfully create a scan when TOS says "it's too complex to scan"...
  1. Open the Hull SuperTrend System code in your preferred text editor
  2. Change all "plots" to "def" (except if part of a Script or an Input)
  3. Delete all corresponding plot formatting code
  4. Add desired Scan Query using plot statement
Below is a sample excerpt of the conversion:

#200 DAY MOVING AVERAGE​
def price1 = close;​
def displace = 0;​
input lengthAvgEXP = 200;​
Delete the plot and replace with def
plot def AvgExp = ExpAverage(price1[-displace], lengthAvgExp);​
Delete all plot formatting code
AvgExp.SetDefaultColor(Color.white);
AvgExp.setlineweight(2);
Add desired Scan Query
plot bullscan = close > open and close > AvgExp and AvgExp > AvgExp[1];​
#plot bearscan = close < open and close < AvgExp and AvgExp < AvgExp[1];​


Complete conversion of Chewie's SuperTrend/Hull Average/Donchian Trend Ribbon Trading System:

Rich (BB code):
# filename: Hull_SuperTrend_System_SCAN

#Hull_SuperTrend_Trading_System
# assembled by Chewie 4/10/2022
# many thanks to all the other noted contributors to this system.

# 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

#input Target_Bubbles = yes;
#input Entry_SL_Bubbles = yes;
#input labels = yes;
#input alertON = no;
input Bands = no;
input EMA1 = 10;
input EMA2 = 20;
input AvgType = AverageType.HULL;
input STAtrMult = 2.75;
input nATR = 12;

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;

def EMA1Val = MovAvgExponential(close, EMA1);
def EMA2Val = MovAvgExponential(close, EMA2);
def EMADirection = if EMA1Val > EMA2Val then 1 else if EMA1Val < EMA2Val then -1 else 0;

def Long = if close > ST then ST else Double.NaN;
def Short = if close < ST then ST else Double.NaN;

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

def LongDot = if LongTrigger then ST else Double.NaN;
def ShortDot = if ShortTrigger then ST else Double.NaN;

#
# Hull Moving Average Concavity and Turning Points
#
# Author: Seth Urion (Mahsume)
# Version: 2020-05-01 V4
#
# Now with support for ToS Mobile - disabled
#

declare upper;

input HMA_Length = 60;
input lookback = 3;
input arrows = no;

def price = HL2;
def HMA = HullMovingAvg(price = price, length = HMA_Length);
def delta = HMA[1] - HMA[lookback + 1];
def delta_per_bar = delta / lookback;
def next_bar = HMA[1] + delta_per_bar;
def concavity = if HMA > next_bar then 1 else -1;

def turning_point = if concavity[1] != concavity then HMA else Double.NaN;

def MA_Max = if HMA[-1] < HMA and HMA > HMA[1] then HMA else Double.NaN;
def MA_Min = if HMA[-1] > HMA and HMA < HMA[1] then HMA else Double.NaN;

#def BuySetup = HMA > HMA[1] and HMA[1] < HMA[2];
#def SellSetup =  HMA < HMA[1] and HMA[1] > HMA[2];

#plot sell = if arrows and turning_point and concavity == -1 then high else Double.NaN;
#sell.SetDefaultColor(Color.DARK_ORANGE);
#sell.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
#sell.SetLineWeight(3);
#sell.hide();

#plot buy = if arrows and turning_point and concavity == 1 then low else Double.NaN;
#buy.SetDefaultColor(Color.CYAN);
#buy.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
#buy.SetLineWeight(3);
#buy.hide();

def divergence = HMA - next_bar;


###################
#
# 2020-05-01
#
# MOBILE TOS SUPPORT
#
# Each color of the HMA needs to be a separate plot as ToS Mobile
# lacks the ability to assign colors the way ToS Desktop does.
# I recommend a plain colored HMA behind the line
# Set the line color of the HMA above to gray or some neutral
#
# CCD_D -> ConCave Down and Decreasing
# CCD_I -> ConCave Down and Increasing
# CCU_D -> ConCave Up and Decreasing
# CCU_I -> ConCave Up and Increasing
#
###################
#plot CCD_D = if concavity == -1 and HMA < HMA[1] then HMA else Double.NaN;
#CCD_D.SetDefaultColor(Color.RED);
#CCD_D.SetLineWeight(1);
#CCD_D.hide();

#plot CCD_I = if concavity == -1 and HMA >= HMA[1] then HMA else Double.NaN;
#CCD_I.SetDefaultColor(Color.DARK_ORANGE);
#CCD_I.SetLineWeight(1);
#CCD_I.hide();

#plot CCU_D = if concavity == 1 and HMA <= HMA[1] then HMA else Double.NaN;
#CCU_D.SetDefaultColor(Color.DARK_GREEN);
#CCU_D.SetLineWeight(1);
#CCU_D.hide();

#plot CCU_I = if concavity == 1 and HMA > HMA[1] then HMA else Double.NaN;
#CCU_I.SetDefaultColor(Color.GREEN);
#CCU_I.SetLineWeight(1);
#CCU_I.hide();

#Hull Label

#AddLabel(yes and labels and CCD_D, "HULL:SELL", color.RED);
#AddLabel(yes and labels and CCU_I, "HULL:BUY", color.green);
#AddLabel(yes and labels and CCU_D, "HULL:WEAK SELL", color.dark_green);
#AddLabel(yes and labels and CCD_I, "HULL:WEAK BUY", color.DARK_ORANGE);

#Target lines
# created by chewie

rec line = if IsNaN(MA_Min) then line[1] else MA_Min[0];
def L_stoploss = if IsNaN(MA_Min) then line else Double.NaN;
def LSL = (if IsNaN(L_stoploss[1]) then L_stoploss else Double.NaN);

rec line2 = if IsNaN(MA_Max) then line2[1] else MA_Max[0];
def S_stoploss = if IsNaN(MA_Max) then line2 else Double.NaN;
def SSL = (if IsNaN(S_stoploss[1]) then S_stoploss else Double.NaN);

#Short Entry
rec line3 = if IsNaN(Long) then line3[1] else Long[0];
def S_Entry = if IsNaN(Long) then line3 else Double.NaN;
def SE = (if IsNaN(S_Entry[1]) then S_Entry else Double.NaN);

#Long Entry
rec line4 = if IsNaN(Short) then line4[1] else Short[0];
def L_Entry = if IsNaN(Short) then line4 else Double.NaN;
def LE = (if IsNaN(L_Entry[1]) then L_Entry else Double.NaN);


#HalfX Long
def x1a_Long =  (L_Entry + (L_Entry - L_stoploss) / 2) ;

#OneX Long
def x1_Long = if x1a_Long > line4 then (L_Entry + (L_Entry - L_stoploss)) else Double.NaN;

#TwoX Long
def x2_Long = x1_Long + (L_Entry - L_stoploss) ;
def X2L = (if IsNaN(x2_Long[1]) then x2_Long else Double.NaN);

#ThreeX Long
def x3_Long = x2_Long + (L_Entry - L_stoploss) ;
def X3L = (if IsNaN(x3_Long[1]) then x3_Long else Double.NaN);

#FourX Long
def x4_Long = x3_Long + (L_Entry - L_stoploss) ;
def X4L = (if IsNaN(x4_Long[1]) then x4_Long else Double.NaN);


#HalfX Short
def x1a_Short = (S_Entry - (S_stoploss - S_Entry) / 2);

#OneX Short
def x1_Short = if x1a_Short < line3 then (S_Entry - (S_stoploss - S_Entry)) else Double.NaN;

#TwoX Short
def x2_Short = x1_Short - (S_stoploss - S_Entry);
def X2S = (if IsNaN(x2_Short[1]) then x2_Short else Double.NaN);

#ThreeX Short
def x3_Short = x2_Short - (S_stoploss - S_Entry);
def X3S = (if IsNaN(x3_Short[1]) then x3_Short else Double.NaN);

#FourX Short
def x4_Short = x3_Short - (S_stoploss - S_Entry);
def X4S = (if IsNaN(x4_Short[1]) then x4_Short else Double.NaN);

#LinearRegCh100 RegressionDivergence - Trigger Lines - Trend Cross
# From Lizard Indicators Link: https://www.lizardindicators.com/trigger-lines-cross-vs-thrust/
# Line #1 - Fast = LinReg (80)
# Line #2 - Slow = EXPEMA[LinReg (80)]

input LinRegLength = 80;
input EMAlength = 20;
input ColorOn = yes;

#Definitions
def price1 = close;
def displace = 0;
def LinReg = Inertia(price1[-displace], LinRegLength);
def EMA_LR = ExpAverage(LinReg[-displace], EMAlength);
def Body = (open + close) / 2;

# Defining Long/Short Filters (these instructions determine entries / exits)
# Entry Requirements
def Long_Entry = close > LinReg and close > EMA_LR and Body > LinReg and Body > EMA_LR and close > high[1] and Body > Body[1];
# LinReg > LinReg[1] and
def Long_Stay_In = close > LinReg and close > EMA_LR;
def Long_Exit = (close < LinReg or close < EMA_LR) or Long_Stay_In == 0;
def Long_State = if Long_Entry then 1 else if Long_Exit then 0 else Long_State[1];
def Long1 = Long_State;

# Exit Requirements
def Short_Entry = close < LinReg and close < EMA_LR and Body < LinReg and Body < EMA_LR and close < low[1] and Body < Body[1];
# LinReg < LinReg[1] and
def Short_Stay_In = close < LinReg and close < EMA_LR;
def Short_Exit = (close > LinReg or close > EMA_LR) or Short_Stay_In == 0;
def Short_State = if Short_Entry then 1 else if Short_Exit then 0 else Short_State[1];
def Short1 = Short_State;

#Adding Linear Regression averages
def LR = LinReg;
def EMA_LinReg = EMA_LR;

#Regression Bands

input deviations = 1.618;  #set your deviation units here.
input length = 500; #set your channel lookback period here.

def stdDeviation = StDevAll(price, length);
def HighBand = if Bands then EMA_LinReg + deviations * stdDeviation else Double.NaN;
def LowBand = if Bands then EMA_LinReg - deviations * stdDeviation else Double.NaN;

#200 DAY MOVING AVERAGE

def price1 = close;
def displace = 0;
input lengthAvgEXP = 200;

def AvgExp = ExpAverage(price[-displace], lengthAvgEXP);
AvgExp.SetDefaultColor(Color.white);
AvgExp.setlineweight(2);

plot bullscan = close > open and close > AvgExp and AvgExp > AvgExp[1];
#plot bearscan = close < open and close < AvgExp and AvgExp < AvgExp[1];


Rich (BB code):
# filename: Donchian_Trend_Ribbon_SCAN

# donchian_trend_ribbon_0e

# convert - donchian trend ribbon
# halcyonguy
# 22-04-07

# 00e
# can chg secondary colors ( 1 , -1) to yellow or diff shades

# 00d
# add histogram , sum of color numbers

# https://usethinkscript.com/threads/convert-tradingview-donchian-trend-ribbon.10822/
# Convert Tradingview Donchian Trend Ribbon
# chewie76  4/4
# Can someone convert the Donchian Trend Ribbon into TOS?
# --------------------------------
# https://www.tradingview.com/script/PxLqmP8o-Donchian-Trend-Ribbon/
#I think you all know Donchian Channels . so I am not going to write about it.
#https://www.tradingview.com/scripts/donchianchannels/
#With this indicator I tried to create Donchian Trend Ribbon by using Donchian Channels .

# How it works ?
# - it calculates main trend direction by using the length that is user-defined. so you can change it as you wish
# - then it calculates trend direction for each 9 lower lengths. if you set the length = 20 then the lengths are 19, 18,...11
# - and it checks if the trend directions that came from lower lengths is same or not with main trend direction.
# - it changes the trend color of the ribbon.
# -----------------------------

#declare lower;

input Donchian_Channel_Period = 20;
def dlen = if Donchian_Channel_Period < 10 then 10 else Donchian_Channel_Period;
input show_data_rows = yes;
input show_sum_histo = yes;
def na = double.nan;

input secondary_colors = { default yellow , green_red };
input show_full_height_of_histogram = yes;
def z = if show_full_height_of_histogram and !isnan(close) then 0 else na;

script dchannel {
  input len = 0;
  def hh = highest(high, len);
  def ll = lowest(low, len);
  def trend = if barnumber() == 1 then 0 else if close > hh[1] then 1 else if close < ll[1] then -1 else trend[1];
  plot z = trend;
}

script dchannelalt {
  input len = 0;
  input maintrend = 0;
  def hh = highest(high, len);
  def ll = lowest(low, len);
  def trend = if barnumber() == 1 then 0 else if close > hh[1] then 1 else if close < ll[1] then -1 else trend[1];
 
 def maincolor =
  if maintrend == 1 then if trend == 1 then 2 else 1
  else if maintrend == -1 then if trend == -1 then -2 else -1
  else 0;

  plot color = maincolor;
#  plot tr = trend;
}

def maintrend = dchannel(dlen);

# ---------------------------------

# input secondary_colors = { default yellow , green_red };
def seccolor;
switch (secondary_colors) {
case yellow:
  seccolor = 1;
case green_red:
  seccolor = 2;
}

#   colors
# 2 - up trend - green
# 1 - up trend - dark green
# 0 no trend
# -1 - down trend - dark red
# -2 - down trend - red

DefineGlobalColor("up2", color.green);
DefineGlobalColor("up1", color.dark_green);
DefineGlobalColor("none", color.dark_gray);
DefineGlobalColor("dwn1", color.dark_red);
DefineGlobalColor("dwn2", color.red);
# GlobalColor("up1")
DefineGlobalColor("alt1", color.yellow);
# GlobalColor("alt1")
#----------------------------------------

input bottom_row = 0;
def rowstart = if bottom_row <> 0 then bottom_row
  else if ( show_data_rows and show_sum_histo ) then 25
  else 0;

input rowskip = 5;
input square_size = 4;

#plot( 5, color = dchannelalt(dlen - 0, maintrend), style = plot.style_columns, histbase= 0)
def c01 = dchannelalt(dlen - 0, maintrend);
def row01 = if isnan(close) then double.nan else (rowstart + ( 1 * rowskip));

def c02 = dchannelalt(dlen - 1, maintrend);
def row02 = if isnan(close) then double.nan else (rowstart + ( 2 * rowskip));

def c03 = dchannelalt(dlen - 2, maintrend);
def row03 = if isnan(close) then double.nan else (rowstart + ( 3 * rowskip));

def c04 = dchannelalt(dlen - 3, maintrend);
def row04 = if isnan(close) then double.nan else (rowstart + ( 4 * rowskip));

def c05 = dchannelalt(dlen - 4, maintrend);
def row05 = if isnan(close) then double.nan else (rowstart + ( 5 * rowskip));

def c06 = dchannelalt(dlen - 5, maintrend);
def row06 = if isnan(close) then double.nan else (rowstart + ( 6 * rowskip));

def c07 = dchannelalt(dlen - 6, maintrend);
def row07 = if isnan(close) then double.nan else (rowstart + ( 7 * rowskip));

def c08 = dchannelalt(dlen - 7, maintrend);
def row08 = if isnan(close) then double.nan else (rowstart + ( 8 * rowskip));

def c09 = dchannelalt(dlen - 8, maintrend);
def row09 = if isnan(close) then double.nan else (rowstart + ( 9 * rowskip));

def c10 = dchannelalt(dlen - 9, maintrend);
def row10 = if isnan(close) then double.nan else (rowstart + ( 10 * rowskip));

# -----------------------------

# add up color numbers, to come up with a 'trend' number , 20 to -20
def colorsum = ( c01 + c02 + c03 + c04 + c05 + c06 + c07 + c08 + c09 + c10 );

# plot a histogram of colorsum.
# it uses absvalue( ), so it is positive numbers, 0 to 20
#input vert1 = 0;  + vert1
def zc = if show_sum_histo then (absvalue(colorsum)) else na;

plot bullscan = colorsum >= 19;
#plot bearscan = colorsum <= -19;


Hope this helps...

Good Luck and Good Trading :cool:
still having problems getting this one set up as a scan. tried to copy paste the entire text from about but still receiving a too complex error "com.devexperts.tos.thinkscript.runtime.TooComplexException: The complexity of the expression suggests that it may not be reliable with real-time data."

I had to # out several lines throughout to include the first line "
Rich (BB code):
" just to get it past the first line.  Is the scan available as a shared link or in the Discord?
 

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

@ponos1207 Please follow the Step-by-Step below and use the Sample as a guide if you want to convert the Indicator to a Scanner...

  1. Open the Hull SuperTrend System code in your preferred text editor
  2. Change all "plots" to "def" (except if part of a Script or an Input)
  3. Delete all corresponding plot formatting code
  4. Add desired Scan Query using plot statement
Below is a sample excerpt of the conversion:

#200 DAY MOVING AVERAGE

def price1 = close;
def displace = 0;
input lengthAvgEXP = 200;

Delete the plot and replace with def
plot def AvgExp = ExpAverage(price1[-displace], lengthAvgExp);

Delete all plot formatting code
AvgExp.SetDefaultColor(Color.white);
AvgExp.setlineweight(2);


Add desired Scan Query
plot bullscan = close > open and close > AvgExp and AvgExp > AvgExp[1];
#plot bearscan = close < open and close < AvgExp and AvgExp < AvgExp[1];

Of course you can always just copy the already converted code:

Rich (BB code):
# filename: Hull_SuperTrend_System_SCAN

#Hull_SuperTrend_Trading_System
# assembled by Chewie 4/10/2022
# many thanks to all the other noted contributors to this system.

# 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

#input Target_Bubbles = yes;
#input Entry_SL_Bubbles = yes;
#input labels = yes;
#input alertON = no;
input Bands = no;
input EMA1 = 10;
input EMA2 = 20;
input AvgType = AverageType.HULL;
input STAtrMult = 2.75;
input nATR = 12;

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;

def EMA1Val = MovAvgExponential(close, EMA1);
def EMA2Val = MovAvgExponential(close, EMA2);
def EMADirection = if EMA1Val > EMA2Val then 1 else if EMA1Val < EMA2Val then -1 else 0;

def Long = if close > ST then ST else Double.NaN;
def Short = if close < ST then ST else Double.NaN;

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

def LongDot = if LongTrigger then ST else Double.NaN;
def ShortDot = if ShortTrigger then ST else Double.NaN;

#
# Hull Moving Average Concavity and Turning Points
#
# Author: Seth Urion (Mahsume)
# Version: 2020-05-01 V4
#
# Now with support for ToS Mobile - disabled
#

declare upper;

input HMA_Length = 60;
input lookback = 3;
input arrows = no;

def price = HL2;
def HMA = HullMovingAvg(price = price, length = HMA_Length);
def delta = HMA[1] - HMA[lookback + 1];
def delta_per_bar = delta / lookback;
def next_bar = HMA[1] + delta_per_bar;
def concavity = if HMA > next_bar then 1 else -1;

def turning_point = if concavity[1] != concavity then HMA else Double.NaN;

def MA_Max = if HMA[-1] < HMA and HMA > HMA[1] then HMA else Double.NaN;
def MA_Min = if HMA[-1] > HMA and HMA < HMA[1] then HMA else Double.NaN;

#def BuySetup = HMA > HMA[1] and HMA[1] < HMA[2];
#def SellSetup =  HMA < HMA[1] and HMA[1] > HMA[2];

#plot sell = if arrows and turning_point and concavity == -1 then high else Double.NaN;
#sell.SetDefaultColor(Color.DARK_ORANGE);
#sell.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
#sell.SetLineWeight(3);
#sell.hide();

#plot buy = if arrows and turning_point and concavity == 1 then low else Double.NaN;
#buy.SetDefaultColor(Color.CYAN);
#buy.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
#buy.SetLineWeight(3);
#buy.hide();

def divergence = HMA - next_bar;


###################
#
# 2020-05-01
#
# MOBILE TOS SUPPORT
#
# Each color of the HMA needs to be a separate plot as ToS Mobile
# lacks the ability to assign colors the way ToS Desktop does.
# I recommend a plain colored HMA behind the line
# Set the line color of the HMA above to gray or some neutral
#
# CCD_D -> ConCave Down and Decreasing
# CCD_I -> ConCave Down and Increasing
# CCU_D -> ConCave Up and Decreasing
# CCU_I -> ConCave Up and Increasing
#
###################
#plot CCD_D = if concavity == -1 and HMA < HMA[1] then HMA else Double.NaN;
#CCD_D.SetDefaultColor(Color.RED);
#CCD_D.SetLineWeight(1);
#CCD_D.hide();

#plot CCD_I = if concavity == -1 and HMA >= HMA[1] then HMA else Double.NaN;
#CCD_I.SetDefaultColor(Color.DARK_ORANGE);
#CCD_I.SetLineWeight(1);
#CCD_I.hide();

#plot CCU_D = if concavity == 1 and HMA <= HMA[1] then HMA else Double.NaN;
#CCU_D.SetDefaultColor(Color.DARK_GREEN);
#CCU_D.SetLineWeight(1);
#CCU_D.hide();

#plot CCU_I = if concavity == 1 and HMA > HMA[1] then HMA else Double.NaN;
#CCU_I.SetDefaultColor(Color.GREEN);
#CCU_I.SetLineWeight(1);
#CCU_I.hide();

#Hull Label

#AddLabel(yes and labels and CCD_D, "HULL:SELL", color.RED);
#AddLabel(yes and labels and CCU_I, "HULL:BUY", color.green);
#AddLabel(yes and labels and CCU_D, "HULL:WEAK SELL", color.dark_green);
#AddLabel(yes and labels and CCD_I, "HULL:WEAK BUY", color.DARK_ORANGE);

#Target lines
# created by chewie

rec line = if IsNaN(MA_Min) then line[1] else MA_Min[0];
def L_stoploss = if IsNaN(MA_Min) then line else Double.NaN;
def LSL = (if IsNaN(L_stoploss[1]) then L_stoploss else Double.NaN);

rec line2 = if IsNaN(MA_Max) then line2[1] else MA_Max[0];
def S_stoploss = if IsNaN(MA_Max) then line2 else Double.NaN;
def SSL = (if IsNaN(S_stoploss[1]) then S_stoploss else Double.NaN);

#Short Entry
rec line3 = if IsNaN(Long) then line3[1] else Long[0];
def S_Entry = if IsNaN(Long) then line3 else Double.NaN;
def SE = (if IsNaN(S_Entry[1]) then S_Entry else Double.NaN);

#Long Entry
rec line4 = if IsNaN(Short) then line4[1] else Short[0];
def L_Entry = if IsNaN(Short) then line4 else Double.NaN;
def LE = (if IsNaN(L_Entry[1]) then L_Entry else Double.NaN);


#HalfX Long
def x1a_Long =  (L_Entry + (L_Entry - L_stoploss) / 2) ;

#OneX Long
def x1_Long = if x1a_Long > line4 then (L_Entry + (L_Entry - L_stoploss)) else Double.NaN;

#TwoX Long
def x2_Long = x1_Long + (L_Entry - L_stoploss) ;
def X2L = (if IsNaN(x2_Long[1]) then x2_Long else Double.NaN);

#ThreeX Long
def x3_Long = x2_Long + (L_Entry - L_stoploss) ;
def X3L = (if IsNaN(x3_Long[1]) then x3_Long else Double.NaN);

#FourX Long
def x4_Long = x3_Long + (L_Entry - L_stoploss) ;
def X4L = (if IsNaN(x4_Long[1]) then x4_Long else Double.NaN);


#HalfX Short
def x1a_Short = (S_Entry - (S_stoploss - S_Entry) / 2);

#OneX Short
def x1_Short = if x1a_Short < line3 then (S_Entry - (S_stoploss - S_Entry)) else Double.NaN;

#TwoX Short
def x2_Short = x1_Short - (S_stoploss - S_Entry);
def X2S = (if IsNaN(x2_Short[1]) then x2_Short else Double.NaN);

#ThreeX Short
def x3_Short = x2_Short - (S_stoploss - S_Entry);
def X3S = (if IsNaN(x3_Short[1]) then x3_Short else Double.NaN);

#FourX Short
def x4_Short = x3_Short - (S_stoploss - S_Entry);
def X4S = (if IsNaN(x4_Short[1]) then x4_Short else Double.NaN);

#LinearRegCh100 RegressionDivergence - Trigger Lines - Trend Cross
# From Lizard Indicators Link: https://www.lizardindicators.com/trigger-lines-cross-vs-thrust/
# Line #1 - Fast = LinReg (80)
# Line #2 - Slow = EXPEMA[LinReg (80)]

input LinRegLength = 80;
input EMAlength = 20;
input ColorOn = yes;

#Definitions
def price1 = close;
def displace = 0;
def LinReg = Inertia(price1[-displace], LinRegLength);
def EMA_LR = ExpAverage(LinReg[-displace], EMAlength);
def Body = (open + close) / 2;

# Defining Long/Short Filters (these instructions determine entries / exits)
# Entry Requirements
def Long_Entry = close > LinReg and close > EMA_LR and Body > LinReg and Body > EMA_LR and close > high[1] and Body > Body[1];
# LinReg > LinReg[1] and
def Long_Stay_In = close > LinReg and close > EMA_LR;
def Long_Exit = (close < LinReg or close < EMA_LR) or Long_Stay_In == 0;
def Long_State = if Long_Entry then 1 else if Long_Exit then 0 else Long_State[1];
def Long1 = Long_State;

# Exit Requirements
def Short_Entry = close < LinReg and close < EMA_LR and Body < LinReg and Body < EMA_LR and close < low[1] and Body < Body[1];
# LinReg < LinReg[1] and
def Short_Stay_In = close < LinReg and close < EMA_LR;
def Short_Exit = (close > LinReg or close > EMA_LR) or Short_Stay_In == 0;
def Short_State = if Short_Entry then 1 else if Short_Exit then 0 else Short_State[1];
def Short1 = Short_State;

#Adding Linear Regression averages
def LR = LinReg;
def EMA_LinReg = EMA_LR;

#Regression Bands

input deviations = 1.618;  #set your deviation units here.
input length = 500; #set your channel lookback period here.

def stdDeviation = StDevAll(price, length);
def HighBand = if Bands then EMA_LinReg + deviations * stdDeviation else Double.NaN;
def LowBand = if Bands then EMA_LinReg - deviations * stdDeviation else Double.NaN;

#200 DAY MOVING AVERAGE

def price1 = close;
def displace = 0;
input lengthAvgEXP = 200;

def AvgExp = ExpAverage(price1[-displace], lengthAvgEXP);
AvgExp.SetDefaultColor(Color.white);
AvgExp.setlineweight(2);

plot bullscan = close > open and close > AvgExp and AvgExp > AvgExp[1];
#plot bearscan = close < open and close < AvgExp and AvgExp < AvgExp[1];


Rich (BB code):
# filename: Donchian_Trend_Ribbon_SCAN

# donchian_trend_ribbon_0e

# convert - donchian trend ribbon
# halcyonguy
# 22-04-07

# 00e
# can chg secondary colors ( 1 , -1) to yellow or diff shades

# 00d
# add histogram , sum of color numbers

# https://usethinkscript.com/threads/convert-tradingview-donchian-trend-ribbon.10822/
# Convert Tradingview Donchian Trend Ribbon
# chewie76  4/4
# Can someone convert the Donchian Trend Ribbon into TOS?
# --------------------------------
# https://www.tradingview.com/script/PxLqmP8o-Donchian-Trend-Ribbon/
#I think you all know Donchian Channels . so I am not going to write about it.
#https://www.tradingview.com/scripts/donchianchannels/
#With this indicator I tried to create Donchian Trend Ribbon by using Donchian Channels .

# How it works ?
# - it calculates main trend direction by using the length that is user-defined. so you can change it as you wish
# - then it calculates trend direction for each 9 lower lengths. if you set the length = 20 then the lengths are 19, 18,...11
# - and it checks if the trend directions that came from lower lengths is same or not with main trend direction.
# - it changes the trend color of the ribbon.
# -----------------------------

#declare lower;

input Donchian_Channel_Period = 20;
def dlen = if Donchian_Channel_Period < 10 then 10 else Donchian_Channel_Period;
input show_data_rows = yes;
input show_sum_histo = yes;
def na = double.nan;

input secondary_colors = { default yellow , green_red };
input show_full_height_of_histogram = yes;
def z = if show_full_height_of_histogram and !isnan(close) then 0 else na;

script dchannel {
  input len = 0;
  def hh = highest(high, len);
  def ll = lowest(low, len);
  def trend = if barnumber() == 1 then 0 else if close > hh[1] then 1 else if close < ll[1] then -1 else trend[1];
  plot z = trend;
}

script dchannelalt {
  input len = 0;
  input maintrend = 0;
  def hh = highest(high, len);
  def ll = lowest(low, len);
  def trend = if barnumber() == 1 then 0 else if close > hh[1] then 1 else if close < ll[1] then -1 else trend[1];
 
 def maincolor =
  if maintrend == 1 then if trend == 1 then 2 else 1
  else if maintrend == -1 then if trend == -1 then -2 else -1
  else 0;

  plot color = maincolor;
#  plot tr = trend;
}

def maintrend = dchannel(dlen);

# ---------------------------------

# input secondary_colors = { default yellow , green_red };
def seccolor;
switch (secondary_colors) {
case yellow:
  seccolor = 1;
case green_red:
  seccolor = 2;
}

#   colors
# 2 - up trend - green
# 1 - up trend - dark green
# 0 no trend
# -1 - down trend - dark red
# -2 - down trend - red

DefineGlobalColor("up2", color.green);
DefineGlobalColor("up1", color.dark_green);
DefineGlobalColor("none", color.dark_gray);
DefineGlobalColor("dwn1", color.dark_red);
DefineGlobalColor("dwn2", color.red);
# GlobalColor("up1")
DefineGlobalColor("alt1", color.yellow);
# GlobalColor("alt1")
#----------------------------------------

input bottom_row = 0;
def rowstart = if bottom_row <> 0 then bottom_row
  else if ( show_data_rows and show_sum_histo ) then 25
  else 0;

input rowskip = 5;
input square_size = 4;

#plot( 5, color = dchannelalt(dlen - 0, maintrend), style = plot.style_columns, histbase= 0)
def c01 = dchannelalt(dlen - 0, maintrend);
def row01 = if isnan(close) then double.nan else (rowstart + ( 1 * rowskip));

def c02 = dchannelalt(dlen - 1, maintrend);
def row02 = if isnan(close) then double.nan else (rowstart + ( 2 * rowskip));

def c03 = dchannelalt(dlen - 2, maintrend);
def row03 = if isnan(close) then double.nan else (rowstart + ( 3 * rowskip));

def c04 = dchannelalt(dlen - 3, maintrend);
def row04 = if isnan(close) then double.nan else (rowstart + ( 4 * rowskip));

def c05 = dchannelalt(dlen - 4, maintrend);
def row05 = if isnan(close) then double.nan else (rowstart + ( 5 * rowskip));

def c06 = dchannelalt(dlen - 5, maintrend);
def row06 = if isnan(close) then double.nan else (rowstart + ( 6 * rowskip));

def c07 = dchannelalt(dlen - 6, maintrend);
def row07 = if isnan(close) then double.nan else (rowstart + ( 7 * rowskip));

def c08 = dchannelalt(dlen - 7, maintrend);
def row08 = if isnan(close) then double.nan else (rowstart + ( 8 * rowskip));

def c09 = dchannelalt(dlen - 8, maintrend);
def row09 = if isnan(close) then double.nan else (rowstart + ( 9 * rowskip));

def c10 = dchannelalt(dlen - 9, maintrend);
def row10 = if isnan(close) then double.nan else (rowstart + ( 10 * rowskip));

# -----------------------------

# add up color numbers, to come up with a 'trend' number , 20 to -20
def colorsum = ( c01 + c02 + c03 + c04 + c05 + c06 + c07 + c08 + c09 + c10 );

# plot a histogram of colorsum.
# it uses absvalue( ), so it is positive numbers, 0 to 20
#input vert1 = 0;  + vert1
def zc = if show_sum_histo then (absvalue(colorsum)) else na;

plot bullscan = colorsum >= 19;
#plot bearscan = colorsum <= -19;


Hope this helps...

Good Luck and Good Trading :cool:
 
Last edited:
mod note:
For SCANNING:
Be aware that scripts using future bars have a one bar lag.
Therefore, the signal is not on the current bar. Scan Hacker MUST be set to use "within 2 bars"
 
@ponos1207 Please follow the Step-by-Step below and use the Sample as a guide if you want to convert the Indicator to a Scanner...



Of course you can always just copy the already converted code:

Rich (BB code):
# filename: Hull_SuperTrend_System_SCAN

#Hull_SuperTrend_Trading_System
# assembled by Chewie 4/10/2022
# many thanks to all the other noted contributors to this system.

# 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

#input Target_Bubbles = yes;
#input Entry_SL_Bubbles = yes;
#input labels = yes;
#input alertON = no;
input Bands = no;
input EMA1 = 10;
input EMA2 = 20;
input AvgType = AverageType.HULL;
input STAtrMult = 2.75;
input nATR = 12;

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;

def EMA1Val = MovAvgExponential(close, EMA1);
def EMA2Val = MovAvgExponential(close, EMA2);
def EMADirection = if EMA1Val > EMA2Val then 1 else if EMA1Val < EMA2Val then -1 else 0;

def Long = if close > ST then ST else Double.NaN;
def Short = if close < ST then ST else Double.NaN;

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

def LongDot = if LongTrigger then ST else Double.NaN;
def ShortDot = if ShortTrigger then ST else Double.NaN;

#
# Hull Moving Average Concavity and Turning Points
#
# Author: Seth Urion (Mahsume)
# Version: 2020-05-01 V4
#
# Now with support for ToS Mobile - disabled
#

declare upper;

input HMA_Length = 60;
input lookback = 3;
input arrows = no;

def price = HL2;
def HMA = HullMovingAvg(price = price, length = HMA_Length);
def delta = HMA[1] - HMA[lookback + 1];
def delta_per_bar = delta / lookback;
def next_bar = HMA[1] + delta_per_bar;
def concavity = if HMA > next_bar then 1 else -1;

def turning_point = if concavity[1] != concavity then HMA else Double.NaN;

def MA_Max = if HMA[-1] < HMA and HMA > HMA[1] then HMA else Double.NaN;
def MA_Min = if HMA[-1] > HMA and HMA < HMA[1] then HMA else Double.NaN;

#def BuySetup = HMA > HMA[1] and HMA[1] < HMA[2];
#def SellSetup =  HMA < HMA[1] and HMA[1] > HMA[2];

#plot sell = if arrows and turning_point and concavity == -1 then high else Double.NaN;
#sell.SetDefaultColor(Color.DARK_ORANGE);
#sell.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
#sell.SetLineWeight(3);
#sell.hide();

#plot buy = if arrows and turning_point and concavity == 1 then low else Double.NaN;
#buy.SetDefaultColor(Color.CYAN);
#buy.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
#buy.SetLineWeight(3);
#buy.hide();

def divergence = HMA - next_bar;


###################
#
# 2020-05-01
#
# MOBILE TOS SUPPORT
#
# Each color of the HMA needs to be a separate plot as ToS Mobile
# lacks the ability to assign colors the way ToS Desktop does.
# I recommend a plain colored HMA behind the line
# Set the line color of the HMA above to gray or some neutral
#
# CCD_D -> ConCave Down and Decreasing
# CCD_I -> ConCave Down and Increasing
# CCU_D -> ConCave Up and Decreasing
# CCU_I -> ConCave Up and Increasing
#
###################
#plot CCD_D = if concavity == -1 and HMA < HMA[1] then HMA else Double.NaN;
#CCD_D.SetDefaultColor(Color.RED);
#CCD_D.SetLineWeight(1);
#CCD_D.hide();

#plot CCD_I = if concavity == -1 and HMA >= HMA[1] then HMA else Double.NaN;
#CCD_I.SetDefaultColor(Color.DARK_ORANGE);
#CCD_I.SetLineWeight(1);
#CCD_I.hide();

#plot CCU_D = if concavity == 1 and HMA <= HMA[1] then HMA else Double.NaN;
#CCU_D.SetDefaultColor(Color.DARK_GREEN);
#CCU_D.SetLineWeight(1);
#CCU_D.hide();

#plot CCU_I = if concavity == 1 and HMA > HMA[1] then HMA else Double.NaN;
#CCU_I.SetDefaultColor(Color.GREEN);
#CCU_I.SetLineWeight(1);
#CCU_I.hide();

#Hull Label

#AddLabel(yes and labels and CCD_D, "HULL:SELL", color.RED);
#AddLabel(yes and labels and CCU_I, "HULL:BUY", color.green);
#AddLabel(yes and labels and CCU_D, "HULL:WEAK SELL", color.dark_green);
#AddLabel(yes and labels and CCD_I, "HULL:WEAK BUY", color.DARK_ORANGE);

#Target lines
# created by chewie

rec line = if IsNaN(MA_Min) then line[1] else MA_Min[0];
def L_stoploss = if IsNaN(MA_Min) then line else Double.NaN;
def LSL = (if IsNaN(L_stoploss[1]) then L_stoploss else Double.NaN);

rec line2 = if IsNaN(MA_Max) then line2[1] else MA_Max[0];
def S_stoploss = if IsNaN(MA_Max) then line2 else Double.NaN;
def SSL = (if IsNaN(S_stoploss[1]) then S_stoploss else Double.NaN);

#Short Entry
rec line3 = if IsNaN(Long) then line3[1] else Long[0];
def S_Entry = if IsNaN(Long) then line3 else Double.NaN;
def SE = (if IsNaN(S_Entry[1]) then S_Entry else Double.NaN);

#Long Entry
rec line4 = if IsNaN(Short) then line4[1] else Short[0];
def L_Entry = if IsNaN(Short) then line4 else Double.NaN;
def LE = (if IsNaN(L_Entry[1]) then L_Entry else Double.NaN);


#HalfX Long
def x1a_Long =  (L_Entry + (L_Entry - L_stoploss) / 2) ;

#OneX Long
def x1_Long = if x1a_Long > line4 then (L_Entry + (L_Entry - L_stoploss)) else Double.NaN;

#TwoX Long
def x2_Long = x1_Long + (L_Entry - L_stoploss) ;
def X2L = (if IsNaN(x2_Long[1]) then x2_Long else Double.NaN);

#ThreeX Long
def x3_Long = x2_Long + (L_Entry - L_stoploss) ;
def X3L = (if IsNaN(x3_Long[1]) then x3_Long else Double.NaN);

#FourX Long
def x4_Long = x3_Long + (L_Entry - L_stoploss) ;
def X4L = (if IsNaN(x4_Long[1]) then x4_Long else Double.NaN);


#HalfX Short
def x1a_Short = (S_Entry - (S_stoploss - S_Entry) / 2);

#OneX Short
def x1_Short = if x1a_Short < line3 then (S_Entry - (S_stoploss - S_Entry)) else Double.NaN;

#TwoX Short
def x2_Short = x1_Short - (S_stoploss - S_Entry);
def X2S = (if IsNaN(x2_Short[1]) then x2_Short else Double.NaN);

#ThreeX Short
def x3_Short = x2_Short - (S_stoploss - S_Entry);
def X3S = (if IsNaN(x3_Short[1]) then x3_Short else Double.NaN);

#FourX Short
def x4_Short = x3_Short - (S_stoploss - S_Entry);
def X4S = (if IsNaN(x4_Short[1]) then x4_Short else Double.NaN);

#LinearRegCh100 RegressionDivergence - Trigger Lines - Trend Cross
# From Lizard Indicators Link: https://www.lizardindicators.com/trigger-lines-cross-vs-thrust/
# Line #1 - Fast = LinReg (80)
# Line #2 - Slow = EXPEMA[LinReg (80)]

input LinRegLength = 80;
input EMAlength = 20;
input ColorOn = yes;

#Definitions
def price1 = close;
def displace = 0;
def LinReg = Inertia(price1[-displace], LinRegLength);
def EMA_LR = ExpAverage(LinReg[-displace], EMAlength);
def Body = (open + close) / 2;

# Defining Long/Short Filters (these instructions determine entries / exits)
# Entry Requirements
def Long_Entry = close > LinReg and close > EMA_LR and Body > LinReg and Body > EMA_LR and close > high[1] and Body > Body[1];
# LinReg > LinReg[1] and
def Long_Stay_In = close > LinReg and close > EMA_LR;
def Long_Exit = (close < LinReg or close < EMA_LR) or Long_Stay_In == 0;
def Long_State = if Long_Entry then 1 else if Long_Exit then 0 else Long_State[1];
def Long1 = Long_State;

# Exit Requirements
def Short_Entry = close < LinReg and close < EMA_LR and Body < LinReg and Body < EMA_LR and close < low[1] and Body < Body[1];
# LinReg < LinReg[1] and
def Short_Stay_In = close < LinReg and close < EMA_LR;
def Short_Exit = (close > LinReg or close > EMA_LR) or Short_Stay_In == 0;
def Short_State = if Short_Entry then 1 else if Short_Exit then 0 else Short_State[1];
def Short1 = Short_State;

#Adding Linear Regression averages
def LR = LinReg;
def EMA_LinReg = EMA_LR;

#Regression Bands

input deviations = 1.618;  #set your deviation units here.
input length = 500; #set your channel lookback period here.

def stdDeviation = StDevAll(price, length);
def HighBand = if Bands then EMA_LinReg + deviations * stdDeviation else Double.NaN;
def LowBand = if Bands then EMA_LinReg - deviations * stdDeviation else Double.NaN;

#200 DAY MOVING AVERAGE

def price1 = close;
def displace = 0;
input lengthAvgEXP = 200;

def AvgExp = ExpAverage(price1[-displace], lengthAvgEXP);
AvgExp.SetDefaultColor(Color.white);
AvgExp.setlineweight(2);

plot bullscan = close > open and close > AvgExp and AvgExp > AvgExp[1];
#plot bearscan = close < open and close < AvgExp and AvgExp < AvgExp[1];


Rich (BB code):
# filename: Donchian_Trend_Ribbon_SCAN

# donchian_trend_ribbon_0e

# convert - donchian trend ribbon
# halcyonguy
# 22-04-07

# 00e
# can chg secondary colors ( 1 , -1) to yellow or diff shades

# 00d
# add histogram , sum of color numbers

# https://usethinkscript.com/threads/convert-tradingview-donchian-trend-ribbon.10822/
# Convert Tradingview Donchian Trend Ribbon
# chewie76  4/4
# Can someone convert the Donchian Trend Ribbon into TOS?
# --------------------------------
# https://www.tradingview.com/script/PxLqmP8o-Donchian-Trend-Ribbon/
#I think you all know Donchian Channels . so I am not going to write about it.
#https://www.tradingview.com/scripts/donchianchannels/
#With this indicator I tried to create Donchian Trend Ribbon by using Donchian Channels .

# How it works ?
# - it calculates main trend direction by using the length that is user-defined. so you can change it as you wish
# - then it calculates trend direction for each 9 lower lengths. if you set the length = 20 then the lengths are 19, 18,...11
# - and it checks if the trend directions that came from lower lengths is same or not with main trend direction.
# - it changes the trend color of the ribbon.
# -----------------------------

#declare lower;

input Donchian_Channel_Period = 20;
def dlen = if Donchian_Channel_Period < 10 then 10 else Donchian_Channel_Period;
input show_data_rows = yes;
input show_sum_histo = yes;
def na = double.nan;

input secondary_colors = { default yellow , green_red };
input show_full_height_of_histogram = yes;
def z = if show_full_height_of_histogram and !isnan(close) then 0 else na;

script dchannel {
  input len = 0;
  def hh = highest(high, len);
  def ll = lowest(low, len);
  def trend = if barnumber() == 1 then 0 else if close > hh[1] then 1 else if close < ll[1] then -1 else trend[1];
  plot z = trend;
}

script dchannelalt {
  input len = 0;
  input maintrend = 0;
  def hh = highest(high, len);
  def ll = lowest(low, len);
  def trend = if barnumber() == 1 then 0 else if close > hh[1] then 1 else if close < ll[1] then -1 else trend[1];
 
 def maincolor =
  if maintrend == 1 then if trend == 1 then 2 else 1
  else if maintrend == -1 then if trend == -1 then -2 else -1
  else 0;

  plot color = maincolor;
#  plot tr = trend;
}

def maintrend = dchannel(dlen);

# ---------------------------------

# input secondary_colors = { default yellow , green_red };
def seccolor;
switch (secondary_colors) {
case yellow:
  seccolor = 1;
case green_red:
  seccolor = 2;
}

#   colors
# 2 - up trend - green
# 1 - up trend - dark green
# 0 no trend
# -1 - down trend - dark red
# -2 - down trend - red

DefineGlobalColor("up2", color.green);
DefineGlobalColor("up1", color.dark_green);
DefineGlobalColor("none", color.dark_gray);
DefineGlobalColor("dwn1", color.dark_red);
DefineGlobalColor("dwn2", color.red);
# GlobalColor("up1")
DefineGlobalColor("alt1", color.yellow);
# GlobalColor("alt1")
#----------------------------------------

input bottom_row = 0;
def rowstart = if bottom_row <> 0 then bottom_row
  else if ( show_data_rows and show_sum_histo ) then 25
  else 0;

input rowskip = 5;
input square_size = 4;

#plot( 5, color = dchannelalt(dlen - 0, maintrend), style = plot.style_columns, histbase= 0)
def c01 = dchannelalt(dlen - 0, maintrend);
def row01 = if isnan(close) then double.nan else (rowstart + ( 1 * rowskip));

def c02 = dchannelalt(dlen - 1, maintrend);
def row02 = if isnan(close) then double.nan else (rowstart + ( 2 * rowskip));

def c03 = dchannelalt(dlen - 2, maintrend);
def row03 = if isnan(close) then double.nan else (rowstart + ( 3 * rowskip));

def c04 = dchannelalt(dlen - 3, maintrend);
def row04 = if isnan(close) then double.nan else (rowstart + ( 4 * rowskip));

def c05 = dchannelalt(dlen - 4, maintrend);
def row05 = if isnan(close) then double.nan else (rowstart + ( 5 * rowskip));

def c06 = dchannelalt(dlen - 5, maintrend);
def row06 = if isnan(close) then double.nan else (rowstart + ( 6 * rowskip));

def c07 = dchannelalt(dlen - 6, maintrend);
def row07 = if isnan(close) then double.nan else (rowstart + ( 7 * rowskip));

def c08 = dchannelalt(dlen - 7, maintrend);
def row08 = if isnan(close) then double.nan else (rowstart + ( 8 * rowskip));

def c09 = dchannelalt(dlen - 8, maintrend);
def row09 = if isnan(close) then double.nan else (rowstart + ( 9 * rowskip));

def c10 = dchannelalt(dlen - 9, maintrend);
def row10 = if isnan(close) then double.nan else (rowstart + ( 10 * rowskip));

# -----------------------------

# add up color numbers, to come up with a 'trend' number , 20 to -20
def colorsum = ( c01 + c02 + c03 + c04 + c05 + c06 + c07 + c08 + c09 + c10 );

# plot a histogram of colorsum.
# it uses absvalue( ), so it is positive numbers, 0 to 20
#input vert1 = 0;  + vert1
def zc = if show_sum_histo then (absvalue(colorsum)) else na;

plot bullscan = colorsum >= 19;
#plot bearscan = colorsum <= -19;


Hope this helps...

Good Luck and Good Trading :cool:
I can't get the first scan to work keep getting these errors :

Identifier Already Used: price1 at 246:5
Identifier Already Used: displace at 247:5
Can not call SetDefaultColor on AvgExp at 251:1
Can not call setlineweight on AvgExp at 252:1
Already assigned: price1 at 246:5
Already assigned: displace at 247:5
Identifier Already Used: price1 at 246:5
Identifier Already Used: displace at 247:5
Can not call SetDefaultColor on AvgExp at 251:1
Can not call setlineweight on AvgExp at 252:1
Already assigned: price1 at 246:5
Already assigned: displace at 247:5
 
@fade Try the Scanners below...they should work now...

Rich (BB code):
# filename: Hull_SuperTrend_System_SCAN

#Hull_SuperTrend_Trading_System
# assembled by Chewie 4/10/2022
# many thanks to all the other noted contributors to this system.

# 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

#input Target_Bubbles = yes;
#input Entry_SL_Bubbles = yes;
#input labels = yes;
#input alertON = no;
input Bands = no;
input EMA1 = 10;
input EMA2 = 20;
input AvgType = AverageType.HULL;
input STAtrMult = 2.75;
input nATR = 12;

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;

def EMA1Val = MovAvgExponential(close, EMA1);
def EMA2Val = MovAvgExponential(close, EMA2);
def EMADirection = if EMA1Val > EMA2Val then 1 else if EMA1Val < EMA2Val then -1 else 0;

def Long = if close > ST then ST else Double.NaN;
def Short = if close < ST then ST else Double.NaN;

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

def LongDot = if LongTrigger then ST else Double.NaN;
def ShortDot = if ShortTrigger then ST else Double.NaN;

#
# Hull Moving Average Concavity and Turning Points
#
# Author: Seth Urion (Mahsume)
# Version: 2020-05-01 V4
#
# Now with support for ToS Mobile - disabled
#

declare upper;

input HMA_Length = 60;
input lookback = 3;
input arrows = no;

def price = HL2;
def HMA = HullMovingAvg(price = price, length = HMA_Length);
def delta = HMA[1] - HMA[lookback + 1];
def delta_per_bar = delta / lookback;
def next_bar = HMA[1] + delta_per_bar;
def concavity = if HMA > next_bar then 1 else -1;

def turning_point = if concavity[1] != concavity then HMA else Double.NaN;

def MA_Max = if HMA[-1] < HMA and HMA > HMA[1] then HMA else Double.NaN;
def MA_Min = if HMA[-1] > HMA and HMA < HMA[1] then HMA else Double.NaN;

#def BuySetup = HMA > HMA[1] and HMA[1] < HMA[2];
#def SellSetup =  HMA < HMA[1] and HMA[1] > HMA[2];

#plot sell = if arrows and turning_point and concavity == -1 then high else Double.NaN;
#sell.SetDefaultColor(Color.DARK_ORANGE);
#sell.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
#sell.SetLineWeight(3);
#sell.hide();

#plot buy = if arrows and turning_point and concavity == 1 then low else Double.NaN;
#buy.SetDefaultColor(Color.CYAN);
#buy.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
#buy.SetLineWeight(3);
#buy.hide();

def divergence = HMA - next_bar;


###################
#
# 2020-05-01
#
# MOBILE TOS SUPPORT
#
# Each color of the HMA needs to be a separate plot as ToS Mobile
# lacks the ability to assign colors the way ToS Desktop does.
# I recommend a plain colored HMA behind the line
# Set the line color of the HMA above to gray or some neutral
#
# CCD_D -> ConCave Down and Decreasing
# CCD_I -> ConCave Down and Increasing
# CCU_D -> ConCave Up and Decreasing
# CCU_I -> ConCave Up and Increasing
#
###################
#plot CCD_D = if concavity == -1 and HMA < HMA[1] then HMA else Double.NaN;
#CCD_D.SetDefaultColor(Color.RED);
#CCD_D.SetLineWeight(1);
#CCD_D.hide();

#plot CCD_I = if concavity == -1 and HMA >= HMA[1] then HMA else Double.NaN;
#CCD_I.SetDefaultColor(Color.DARK_ORANGE);
#CCD_I.SetLineWeight(1);
#CCD_I.hide();

#plot CCU_D = if concavity == 1 and HMA <= HMA[1] then HMA else Double.NaN;
#CCU_D.SetDefaultColor(Color.DARK_GREEN);
#CCU_D.SetLineWeight(1);
#CCU_D.hide();

#plot CCU_I = if concavity == 1 and HMA > HMA[1] then HMA else Double.NaN;
#CCU_I.SetDefaultColor(Color.GREEN);
#CCU_I.SetLineWeight(1);
#CCU_I.hide();

#Hull Label

#AddLabel(yes and labels and CCD_D, "HULL:SELL", color.RED);
#AddLabel(yes and labels and CCU_I, "HULL:BUY", color.green);
#AddLabel(yes and labels and CCU_D, "HULL:WEAK SELL", color.dark_green);
#AddLabel(yes and labels and CCD_I, "HULL:WEAK BUY", color.DARK_ORANGE);

#Target lines
# created by chewie

rec line = if IsNaN(MA_Min) then line[1] else MA_Min[0];
def L_stoploss = if IsNaN(MA_Min) then line else Double.NaN;
def LSL = (if IsNaN(L_stoploss[1]) then L_stoploss else Double.NaN);

rec line2 = if IsNaN(MA_Max) then line2[1] else MA_Max[0];
def S_stoploss = if IsNaN(MA_Max) then line2 else Double.NaN;
def SSL = (if IsNaN(S_stoploss[1]) then S_stoploss else Double.NaN);

#Short Entry
rec line3 = if IsNaN(Long) then line3[1] else Long[0];
def S_Entry = if IsNaN(Long) then line3 else Double.NaN;
def SE = (if IsNaN(S_Entry[1]) then S_Entry else Double.NaN);

#Long Entry
rec line4 = if IsNaN(Short) then line4[1] else Short[0];
def L_Entry = if IsNaN(Short) then line4 else Double.NaN;
def LE = (if IsNaN(L_Entry[1]) then L_Entry else Double.NaN);


#HalfX Long
def x1a_Long =  (L_Entry + (L_Entry - L_stoploss) / 2) ;

#OneX Long
def x1_Long = if x1a_Long > line4 then (L_Entry + (L_Entry - L_stoploss)) else Double.NaN;

#TwoX Long
def x2_Long = x1_Long + (L_Entry - L_stoploss) ;
def X2L = (if IsNaN(x2_Long[1]) then x2_Long else Double.NaN);

#ThreeX Long
def x3_Long = x2_Long + (L_Entry - L_stoploss) ;
def X3L = (if IsNaN(x3_Long[1]) then x3_Long else Double.NaN);

#FourX Long
def x4_Long = x3_Long + (L_Entry - L_stoploss) ;
def X4L = (if IsNaN(x4_Long[1]) then x4_Long else Double.NaN);


#HalfX Short
def x1a_Short = (S_Entry - (S_stoploss - S_Entry) / 2);

#OneX Short
def x1_Short = if x1a_Short < line3 then (S_Entry - (S_stoploss - S_Entry)) else Double.NaN;

#TwoX Short
def x2_Short = x1_Short - (S_stoploss - S_Entry);
def X2S = (if IsNaN(x2_Short[1]) then x2_Short else Double.NaN);

#ThreeX Short
def x3_Short = x2_Short - (S_stoploss - S_Entry);
def X3S = (if IsNaN(x3_Short[1]) then x3_Short else Double.NaN);

#FourX Short
def x4_Short = x3_Short - (S_stoploss - S_Entry);
def X4S = (if IsNaN(x4_Short[1]) then x4_Short else Double.NaN);

#LinearRegCh100 RegressionDivergence - Trigger Lines - Trend Cross
# From Lizard Indicators Link: https://www.lizardindicators.com/trigger-lines-cross-vs-thrust/
# Line #1 - Fast = LinReg (80)
# Line #2 - Slow = EXPEMA[LinReg (80)]

input LinRegLength = 80;
input EMAlength = 20;
input ColorOn = yes;

#Definitions
def price1 = close;
def displace = 0;
def LinReg = Inertia(price1[-displace], LinRegLength);
def EMA_LR = ExpAverage(LinReg[-displace], EMAlength);
def Body = (open + close) / 2;

# Defining Long/Short Filters (these instructions determine entries / exits)
# Entry Requirements
def Long_Entry = close > LinReg and close > EMA_LR and Body > LinReg and Body > EMA_LR and close > high[1] and Body > Body[1];
# LinReg > LinReg[1] and
def Long_Stay_In = close > LinReg and close > EMA_LR;
def Long_Exit = (close < LinReg or close < EMA_LR) or Long_Stay_In == 0;
def Long_State = if Long_Entry then 1 else if Long_Exit then 0 else Long_State[1];
def Long1 = Long_State;

# Exit Requirements
def Short_Entry = close < LinReg and close < EMA_LR and Body < LinReg and Body < EMA_LR and close < low[1] and Body < Body[1];
# LinReg < LinReg[1] and
def Short_Stay_In = close < LinReg and close < EMA_LR;
def Short_Exit = (close > LinReg or close > EMA_LR) or Short_Stay_In == 0;
def Short_State = if Short_Entry then 1 else if Short_Exit then 0 else Short_State[1];
def Short1 = Short_State;

#Adding Linear Regression averages
def LR = LinReg;
def EMA_LinReg = EMA_LR;

#Regression Bands

input deviations = 1.618;  #set your deviation units here.
input length = 500; #set your channel lookback period here.

def stdDeviation = StDevAll(price, length);
def HighBand = if Bands then EMA_LinReg + deviations * stdDeviation else Double.NaN;
def LowBand = if Bands then EMA_LinReg - deviations * stdDeviation else Double.NaN;

#200 DAY MOVING AVERAGE

def price2 = close;
def displace2 = 0;
input lengthAvgEXP = 200;

def AvgExp = ExpAverage(price2[-displace2], lengthAvgEXP);

plot bullscan = close > open and close > AvgExp and AvgExp > AvgExp[1];
#plot bearscan = close < open and close < AvgExp and AvgExp < AvgExp[1];



Rich (BB code):
# filename: Donchian_Trend_Ribbon_SCAN

# donchian_trend_ribbon_0e

# convert - donchian trend ribbon
# halcyonguy
# 22-04-07

# 00e
# can chg secondary colors ( 1 , -1) to yellow or diff shades

# 00d
# add histogram , sum of color numbers

# https://usethinkscript.com/threads/convert-tradingview-donchian-trend-ribbon.10822/
# Convert Tradingview Donchian Trend Ribbon
# chewie76  4/4
# Can someone convert the Donchian Trend Ribbon into TOS?
# --------------------------------
# https://www.tradingview.com/script/PxLqmP8o-Donchian-Trend-Ribbon/
#I think you all know Donchian Channels . so I am not going to write about it.
#https://www.tradingview.com/scripts/donchianchannels/
#With this indicator I tried to create Donchian Trend Ribbon by using Donchian Channels .

# How it works ?
# - it calculates main trend direction by using the length that is user-defined. so you can change it as you wish
# - then it calculates trend direction for each 9 lower lengths. if you set the length = 20 then the lengths are 19, 18,...11
# - and it checks if the trend directions that came from lower lengths is same or not with main trend direction.
# - it changes the trend color of the ribbon.
# -----------------------------

#declare lower;

input Donchian_Channel_Period = 20;
def dlen = if Donchian_Channel_Period < 10 then 10 else Donchian_Channel_Period;
input show_data_rows = yes;
input show_sum_histo = yes;
def na = double.nan;

input secondary_colors = { default yellow , green_red };
input show_full_height_of_histogram = yes;
def z = if show_full_height_of_histogram and !isnan(close) then 0 else na;

script dchannel {
  input len = 0;
  def hh = highest(high, len);
  def ll = lowest(low, len);
  def trend = if barnumber() == 1 then 0 else if close > hh[1] then 1 else if close < ll[1] then -1 else trend[1];
  plot z = trend;
}

script dchannelalt {
  input len = 0;
  input maintrend = 0;
  def hh = highest(high, len);
  def ll = lowest(low, len);
  def trend = if barnumber() == 1 then 0 else if close > hh[1] then 1 else if close < ll[1] then -1 else trend[1];
 
 def maincolor =
  if maintrend == 1 then if trend == 1 then 2 else 1
  else if maintrend == -1 then if trend == -1 then -2 else -1
  else 0;

  plot color = maincolor;
#  plot tr = trend;
}

def maintrend = dchannel(dlen);

# ---------------------------------

# input secondary_colors = { default yellow , green_red };
def seccolor;
switch (secondary_colors) {
case yellow:
  seccolor = 1;
case green_red:
  seccolor = 2;
}

#   colors
# 2 - up trend - green
# 1 - up trend - dark green
# 0 no trend
# -1 - down trend - dark red
# -2 - down trend - red

DefineGlobalColor("up2", color.green);
DefineGlobalColor("up1", color.dark_green);
DefineGlobalColor("none", color.dark_gray);
DefineGlobalColor("dwn1", color.dark_red);
DefineGlobalColor("dwn2", color.red);
# GlobalColor("up1")
DefineGlobalColor("alt1", color.yellow);
# GlobalColor("alt1")
#----------------------------------------

input bottom_row = 0;
def rowstart = if bottom_row <> 0 then bottom_row
  else if ( show_data_rows and show_sum_histo ) then 25
  else 0;

input rowskip = 5;
input square_size = 4;

#plot( 5, color = dchannelalt(dlen - 0, maintrend), style = plot.style_columns, histbase= 0)
def c01 = dchannelalt(dlen - 0, maintrend);
def row01 = if isnan(close) then double.nan else (rowstart + ( 1 * rowskip));

def c02 = dchannelalt(dlen - 1, maintrend);
def row02 = if isnan(close) then double.nan else (rowstart + ( 2 * rowskip));

def c03 = dchannelalt(dlen - 2, maintrend);
def row03 = if isnan(close) then double.nan else (rowstart + ( 3 * rowskip));

def c04 = dchannelalt(dlen - 3, maintrend);
def row04 = if isnan(close) then double.nan else (rowstart + ( 4 * rowskip));

def c05 = dchannelalt(dlen - 4, maintrend);
def row05 = if isnan(close) then double.nan else (rowstart + ( 5 * rowskip));

def c06 = dchannelalt(dlen - 5, maintrend);
def row06 = if isnan(close) then double.nan else (rowstart + ( 6 * rowskip));

def c07 = dchannelalt(dlen - 6, maintrend);
def row07 = if isnan(close) then double.nan else (rowstart + ( 7 * rowskip));

def c08 = dchannelalt(dlen - 7, maintrend);
def row08 = if isnan(close) then double.nan else (rowstart + ( 8 * rowskip));

def c09 = dchannelalt(dlen - 8, maintrend);
def row09 = if isnan(close) then double.nan else (rowstart + ( 9 * rowskip));

def c10 = dchannelalt(dlen - 9, maintrend);
def row10 = if isnan(close) then double.nan else (rowstart + ( 10 * rowskip));

# -----------------------------

# add up color numbers, to come up with a 'trend' number , 20 to -20
def colorsum = ( c01 + c02 + c03 + c04 + c05 + c06 + c07 + c08 + c09 + c10 );

# plot a histogram of colorsum.
# it uses absvalue( ), so it is positive numbers, 0 to 20
#input vert1 = 0;  + vert1
def zc = if show_sum_histo then (absvalue(colorsum)) else na;

plot bullscan = colorsum >= 19;
#plot bearscan = colorsum <= -19;


Hope this helps...

Good Luck and Good Trading :cool:
 
I assembled this indicator that includes a few combined indicators based on watching this video.
I changed a few of the settings however. This is a trading system or strategy that includes where to enter a trade, where to place your stop loss, and 5 targets, and when to close your trade. There is a real "strategy" below that can be loaded as well to view actual profit/loss. Many thanks to the other contributors who created these indicators. NOTE: I know some people love a clean chart and will say that this is too messy. I understand that. You can uncheck viewing any of the plots within the indicator, like certain target lines you don't want to see or anything else if you prefer. Ok, let's carry on. Below is first the trading system summary, and a bunch of chart examples.

SUMMARY OF TRADING SYSTEM:

1.The best trades are in the direction of the 200 EMA (white line). Important point that is why it is #1. Always check first where is the white line 200 EMA.

2. SETUP: You must see three things to define an entry position.
1. A top or bottom reversal signal of the Hull Moving Avg plotted with a white square (top) or white triangle (bottom).
2. Lower Donchian Trend Ribbon either green or red in the color of the direction you are entering the trade. (Shout out to @halcyonguy who converted this into TOS. Much appreciated, you are awesome!!!)
3. Break of the Super Trend indicator. (Default setting is 2.75. Feel free to adjust this if you want in the settings)
4. Stop Loss is placed at or just below the reversal Hull Moving Avg square or triangle. (In some instances, the 200 EMA could be your stop loss.)

3. The first thing that you should expect to see when all 3 triggers are set is when price breaks through the Super Trend, there is sometimes resistance at the first magenta dashed line. This is half of the 1st target. That could be your first trade with trade orders set in place prior to seeing the 3 triggers take effect. Sometimes it is safer to watch price break through the Super Trend, retrace back below, and enter at the entry line as it breaks through the second time.

4. Once price hits the dashed magenta line, it typically either continues in a strong move, or it will come back to the entry line or below. A secondary move will typically push past the magenta line to the next 1x yellow dashed target.

5.Once price hits the first 1x target, it will typically either continue to the 2x target, or retrace back to the 1x or Entry line. 2x target is the goal, but sometimes price will blast to 3x or 4x target.

6.There are times when price will extend beyond the 4x target.

7.The Hull reversal point (white square or triangle) will have a line drawn which is the stop loss. This level is sometimes used as support or resistance, so take note of this area and how price reacts to it.

8.Included is a DYNO regression average that will color the candles green when price is above, red when price is below and yellow when price is between the two lines. Regression bands are also displayed and can be turned on/off in the settings. Your trade should correspond to the color of the candles. Long trade = green candles, short trade = red candles.

9.TRADE EXIT: Place your exit order at any of the target levels of your choice. If price goes beyond the first magenta line, consider moving your stop loss to the entry line (break even), or to the magenta line. You could also move your stop loss to either trail with the Super Trend, or with the Hull moving average. Typically breaking the Hull moving average closes the trade.

This indicator includes labels for the Super Trend, Hull avg, and Dyno regression average. These labels can be turned on/off in the settings.
This indicator includes bubbles for target levels and bubbles for trade entry and stop loss. Bubbles are off by default. These bubbles can be turned on/off in the settings.
This indicator includes various alerts for when Super Trend breaks, when the Hull avg creates a reversal buy/sell signal, and when price crosses the regression bands. These alerts can be turned on/off in the settings.

All example charts are on the 4 minute timeframe. I like the 4 min. Different timeframes will obviously give you different results. Let's get to it!


ArvBkeM.png


In the above chart, you have all 3 conditions trigger in the same red candle. 1. Hull reversal point, 2. Red color Donchian Trend Ribbon, 3. Break below of the cyan Super Trend. Take note on how price first hits the magenta dashed line and retraces beyond the Entry Line. It hits the 1X target and continues all the way to 4X target. If you didn't take the 4x target, price breaking the Hull moving average indicates time to close the trade.


M4iTGih.png


In the above chart, there are two trades long and short. Look for all 3 conditions to trigger. 1. Hull reversal point, 2. color Donchian Trend Ribbon, 3. Break of the Super Trend. In the first trade, price goes above the 200 EMA and hits the 2x target. Closing below the Hull average would close the trade. In the second trade, price hits 3x target, and breaking the Hull avg would close the trade.



CRTAVrq.png


In the above chart, there is a slight downward slope of the 200 EMA, the top Hull reversal plots, Donchian Trend Ribbon is red, you are looking to short at the break of the Super Trend. It rapidly goes to the 4x target and breaks the Hull avg closing the trade.



SNPHRco.png


In the above chart, all 3 trade setups take place to enter the trade. Price retraces back to the 200 EMA which is above your stop loss. It then continues higher to 4x target. Either have an exit order at the 4x level, or trail stop loss with Super Trend or the yellow Dyno average.



1DTFxZW.png


In the above chart, all 3 trade setups take place to enter the trade. Price retraces back to the 200 EMA which is above your stop loss. It then continues higher to beyond the 4x target. You must take your profits. Don’t be greedy.



mt1GJYm.png


In the above chart, all 3 trade setups take place to enter the trade. Price is below the 200 EMA and you short. Here is a tricky situation. It barely breaks the Super Trend. It hits your stop loss, but never closes above your stop loss. It then goes to tag the 3x target. Better to be safe and have your stop loss hit, or have a wider stop loss at the 200 EMA.



sv7xIBT.png


In the above chart, all 3 trade setups take place to enter the trade. Price is below the 200 EMA and you think it could tag it. Price stays above the Hull avg and hits both the 4x target and the 200 EMA. Be cautious because typically you want to trade in the direction of the 200, but when price is far from it, there is a chance it will come back to it.



FbqdeO6.png


In the above chart, all 3 trade setups take place to enter the trade. Price previously is rejected at the 200 EMA and it is rejected a second time. You take the short setup. Price stays below the Hull avg and hits the 3x target. If you didn’t get out at the 3x, you would exit the trade at the break of the Hull avg. Nice trade!



cSXCWLO.png


In the above chart, all 3 trade setups take place to enter the trade. Price breaks above the 200 EMA at your entry. 2x target is hit and price breaks the Hull avg. Good time to take profits, or trail your stop at the Super Trend and take profit at the 4x target.



N69m8Tq.png



I created a strategy, however, it does not incorporate the lower Donchian Trend Ribbon. It also exits trades if it hits levels and breaks back, so it’s pretty conservative. On the 4 min chart, ES would have a profit of $33,234 in the last 30 days.


And now for the codes.

SHAREABLE LINKS:

Upper Indicator Code: http://tos.mx/xwmHCKc
Donchian Trend Ribbon Indicator Code: http://tos.mx/MMxMs6u This can also be found at this post. https://usethinkscript.com/threads/donchian-trend-ribbon-for-thinkorswim.10861/#post-95366
Note: the Donchian Trend Ribbon has a lower histogram. When the lower histogram is magenta color, it is sign of major selling. When cyan, it is major buying, when it is dark green or dark red, it is in consolidation.
Strategy Code: NOTE: Strategy does not take into account the Hull Avg or the Donchian Ribbon, only the Super Trend break and the target levels. http://tos.mx/neHVQml

Code:
#Hull_SuperTrend_Trading_System
# assembled by Chewie 4/10/2022
# many thanks to all the other noted contributors to this system.

# 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

input Target_Bubbles = no;
input Entry_SL_Bubbles = no;
input Targetlines = yes;
input Labels = yes;
input alertON = yes;
input Bands = yes;
input EMA1 = 10;
input EMA2 = 20;
input AvgType = AverageType.HULL;
input STAtrMult = 2.75;
input nATR = 12;

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;

def EMA1Val = MovAvgExponential(close, EMA1);
def EMA2Val = MovAvgExponential(close, EMA2);
def EMADirection = if EMA1Val > EMA2Val then 1 else if EMA1Val < EMA2Val then -1 else 0;

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);

#
# Hull Moving Average Concavity and Turning Points
#
# Author: Seth Urion (Mahsume)
# Version: 2020-05-01 V4
#
# Now with support for ToS Mobile
#

declare upper;

input HMA_Length = 60;
input lookback = 3;
input arrows = no;

def price = HL2;
plot HMA = HullMovingAvg(price = price, length = HMA_Length);
def delta = HMA[1] - HMA[lookback + 1];
def delta_per_bar = delta / lookback;
def next_bar = HMA[1] + delta_per_bar;
def concavity = if HMA > next_bar then 1 else -1;

plot turning_point = if concavity[1] != concavity then HMA else double.nan;

HMA.AssignValueColor(color = if concavity[1] == -1 then
    if HMA > HMA[1] then color.dark_orange else color.red else
    if HMA < HMA[1] then color.dark_green else color.green);

HMA.SetLineWeight(3);

turning_point.SetLineWeight(2);
turning_point.SetPaintingStrategy(paintingStrategy = PaintingStrategy.POINTS);
turning_point.SetDefaultColor(color.white);

plot MA_Max = if HMA[-1] < HMA and HMA > HMA[1] then HMA else Double.NaN;
MA_Max.SetDefaultColor(Color.WHITE);
MA_Max.SetPaintingStrategy(PaintingStrategy.SQUARES);
MA_Max.SetLineWeight(5);

plot MA_Min = if HMA[-1] > HMA and HMA < HMA[1] then HMA else Double.Nan;
MA_Min.SetDefaultColor(Color.WHITE);

MA_Min.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
MA_Min.SetLineWeight(5);

def BuySetup = HMA > HMA[1] and HMA[1] < HMA[2];
def SellSetup =  HMA < HMA[1] and HMA[1] > HMA[2];

plot sell = if arrows and turning_point and concavity == -1 then high else double.nan;
sell.SetDefaultColor(Color.DARK_ORANGE);
sell.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
sell.SetLineWeight(3);

plot buy = if arrows and turning_point and concavity == 1 then low else double.nan;
buy.SetDefaultColor(Color.CYAN);
buy.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
buy.SetLineWeight(3);

def divergence = HMA - next_bar;


###################
#
# 2020-05-01
#
# MOBILE TOS SUPPORT
#
# Each color of the HMA needs to be a separate plot as ToS Mobile
# lacks the ability to assign colors the way ToS Desktop does.
# I recommend a plain colored HMA behind the line
# Set the line color of the HMA above to gray or some neutral
#
# CCD_D -> ConCave Down and Decreasing
# CCD_I -> ConCave Down and Increasing
# CCU_D -> ConCave Up and Decreasing
# CCU_I -> ConCave Up and Increasing
#
###################
plot CCD_D = if concavity == -1 and HMA < HMA[1] then HMA else double.nan;
CCD_D.SetDefaultColor(Color.RED);
CCD_D.SetLineWeight(1);

plot CCD_I = if concavity == -1 and HMA >= HMA[1] then HMA else double.nan;
CCD_I.SetDefaultColor(Color.DARK_ORANGE);
CCD_I.SetLineWeight(1);

plot CCU_D = if concavity == 1 and HMA <= HMA[1] then HMA else double.nan;
CCU_D.SetDefaultColor(COLOR.DARK_GREEN);
CCU_D.SetLineWeight(1);

plot CCU_I = if concavity == 1 and HMA > HMA[1] then HMA else double.nan;
CCU_I.SetDefaultColor(COLOR.GREEN);
CCU_I.SetLineWeight(1);

#Hull Label

AddLabel(yes and labels and CCD_D, "HULL:SELL", color.RED);
AddLabel(yes and labels and CCU_I, "HULL:BUY", color.green);
AddLabel(yes and labels and CCU_D, "HULL:WEAK SELL", color.dark_green);
AddLabel(yes and labels and CCD_I, "HULL:WEAK BUY", color.DARK_ORANGE);

#Target lines
# created by chewie

rec line = if IsNaN(MA_Min) then line[1] else MA_Min[0];
plot L_stoploss= if isnan(MA_Min) then line else double.nan;
L_stoploss.setpaintingStrategy(paintingStrategy.LINE);
L_stoploss.setlineWeight(3);
L_stoploss.setdefaultColor(color.dark_green);
L_stoploss.hideBubble();
def LSL =(if isNaN(L_stoploss[1]) then L_stoploss else Double.NaN);
addchartBubble(Entry_SL_Bubbles and L_stoploss, LSL,"L/SL",color.DARK_GREEN);

rec line2 = if IsNaN(MA_Max) then line2[1] else MA_Max[0];
plot S_stoploss = if IsNaN(MA_MAX) then line2 else double.nan;
S_stoploss.setpaintingStrategy(paintingStrategy.LINE);
S_stoploss.setlineWeight(3);
S_stoploss.setdefaultColor(color.dark_red);
S_stoploss.hideBubble();
def SSL =(if isNaN(S_stoploss[1]) then S_stoploss else Double.NaN);
addchartBubble(Entry_SL_Bubbles and S_stoploss, SSL,"S/SL",color.DARK_RED);

#Short Entry
rec line3 = if IsNaN(long) then line3[1] else long[0];
plot S_Entry = if IsNaN(long) then line3 else double.nan;
S_Entry.setpaintingStrategy(paintingStrategy.LINE);
S_Entry.setlineWeight(3);
S_Entry.setdefaultColor(color.red);
S_Entry.hideBubble();
def SE =(if isNaN(S_Entry[1]) then S_Entry else Double.NaN);
addchartBubble(Entry_SL_Bubbles and S_Entry, SE,"S/E",color.RED);

#Long Entry
rec line4 = if IsNaN(short) then line4[1] else short[0];
plot L_Entry = if IsNaN(short) then line4 else double.nan;
L_Entry.setpaintingStrategy(paintingStrategy.LINE);
L_Entry.setlineWeight(3);
L_Entry.setdefaultColor(color.green);
L_Entry.hideBubble();
def LE =(if isNaN(L_Entry[1]) then L_Entry else Double.NaN);
addchartBubble(Entry_SL_Bubbles and L_Entry, LE,"L/E",color.GREEN);

#HalfX Long
plot x1a_Long =  if Targetlines then (L_Entry +(L_Entry - L_Stoploss)/2) else double.nan;
x1a_Long.setpaintingStrategy(paintingStrategy.dashes);
x1a_Long.setlineWeight(1);
x1a_Long.setdefaultColor(color.magenta);
x1a_Long.hideBubble();

#OneX Long
plot x1_Long = if Targetlines and x1a_Long > line4 then (L_Entry +(L_Entry - L_Stoploss)) else double.nan;
x1_Long.setpaintingStrategy(paintingStrategy.dashes);
x1_Long.setlineWeight(1);
x1_Long.setdefaultColor(color.yellow);

#TwoX Long
plot x2_Long = if Targetlines then x1_Long +(L_Entry - L_Stoploss) else double.nan;
x2_Long.setpaintingStrategy(paintingStrategy.line);
x2_Long.setlineWeight(2);
x2_Long.setdefaultColor(color.light_red);
def X2L =(if isNaN(x2_Long[1]) then x2_Long else Double.NaN);
addchartBubble(Target_Bubbles and x2_Long, x2L,"2xL",color.light_red);

#ThreeX Long
plot x3_Long = if Targetlines then x2_Long +(L_Entry - L_Stoploss) else double.nan;
x3_Long.setpaintingStrategy(paintingStrategy.dashes);
x3_Long.setlineWeight(1);
x3_Long.setdefaultColor(color.cyan);
def X3L =(if isNaN(x3_Long[1]) then x3_Long else Double.NaN);
addchartBubble(Target_Bubbles and x3_Long, x3L,"3xL",color.cyan);

#FourX Long
plot x4_Long = if Targetlines then x3_Long +(L_Entry - L_Stoploss) else double.nan;
x4_Long.setpaintingStrategy(paintingStrategy.dashes);
x4_Long.setlineWeight(1);
x4_Long.setdefaultColor(color.white);
def X4L =(if isNaN(x4_Long[1]) then x4_Long else Double.NaN);
addchartBubble(Target_Bubbles and x4_Long, x4L,"4xL",color.white);

#HalfX Short
plot x1a_Short = if Targetlines then (S_Entry -(S_Stoploss - S_Entry)/2) else double.nan;
x1a_Short.setpaintingStrategy(paintingStrategy.dashes);
x1a_Short.setlineWeight(1);
x1a_Short.setdefaultColor(color.magenta);
x1a_Short.hideBubble();

#OneX Short
plot x1_Short = if Targetlines and x1a_short < line3 then (S_Entry -(S_Stoploss - S_Entry)) else double.nan;
x1_Short.setpaintingStrategy(paintingStrategy.dashes);
x1_Short.setlineWeight(1);
x1_Short.setdefaultColor(color.yellow);

#TwoX Short
plot x2_Short = if Targetlines then x1_Short -(S_Stoploss - S_Entry) else double.nan;
x2_Short.setpaintingStrategy(paintingStrategy.line);
x2_Short.setlineWeight(2);
x2_Short.setdefaultColor(color.light_green);
def X2S =(if isNaN(x2_Short[1]) then x2_Short else Double.NaN);
addchartBubble(Target_Bubbles and x2_Short, x2S,"2xS",color.light_green);

#ThreeX Short
plot x3_Short = if Targetlines then x2_Short -(S_Stoploss - S_Entry) else double.nan;
x3_Short.setpaintingStrategy(paintingStrategy.dashes);
x3_Short.setlineWeight(1);
x3_Short.setdefaultColor(color.cyan);
def X3S =(if isNaN(x3_Short[1]) then x3_Short else Double.NaN);
addchartBubble(Target_Bubbles and x3_Short, x3S,"3xS",color.cyan);

#FourX Short
plot x4_Short = if Targetlines then x3_Short -(S_Stoploss - S_Entry) else double.nan;
x4_Short.setpaintingStrategy(paintingStrategy.dashes);
x4_Short.setlineWeight(1);
x4_Short.setdefaultColor(color.white);
def X4S =(if isNaN(x4_Short[1]) then x4_Short else Double.NaN);
addchartBubble(Target_Bubbles and x4_Short, x4S,"4xS",color.white);

#LinearRegCh100 RegressionDivergence - Trigger Lines - Trend Cross
# From Lizard Indicators Link: https://www.lizardindicators.com/trigger-lines-cross-vs-thrust/
# Line #1 - Fast = LinReg (80)
# Line #2 - Slow = EXPEMA[LinReg (80)]

input LinRegLength = 80;
input EMAlength = 20;
input ColorOn = yes;

#Definitions
def price1 = close;
def displace = 0;
def LinReg = Inertia(price1[-displace], LinRegLength);
def EMA_LR = ExpAverage(LinReg[-displace], EMAlength);
def Body = (open + close)/2;

# Defining Long/Short Filters (these instructions determine entries / exits)
# Entry Requirements
def Long_Entry = close > LinReg and close > EMA_LR and body > LinReg and body > EMA_LR and close > high[1] and body > body[1];
# LinReg > LinReg[1] and
def Long_Stay_In = close > LinReg and close > EMA_LR;
def Long_Exit = (close < LinReg or close < EMA_LR) or Long_Stay_In == 0;
def Long_State = If Long_Entry then 1 else if Long_Exit then 0 else Long_State[1];
def Long1 = Long_State;

# Exit Requirements
def Short_Entry = close < LinReg and close < EMA_LR and body < LinReg and body < EMA_LR and close < low[1] and body < body[1];
# LinReg < LinReg[1] and
def Short_Stay_In = close < LinReg and close < EMA_LR;
def Short_Exit = (close > LinReg or close > EMA_LR) or Short_Stay_In == 0;
def Short_State = If Short_Entry then 1 else if Short_Exit then 0 else Short_State[1];
def Short1 = Short_State;

#Adding Linear Regression averages
plot LR = LinReg;
LR.SetDefaultColor(CreateColor(0, 130, 255));
plot EMA_LinReg = EMA_LR;
EMA_LinReg.SetDefaultColor(CreateColor(255, 215,0));
LR.setlineweight(1);
EMA_LinReg.setlineweight(2);

#DYNO Label

AddLabel(yes and labels and Short1, "DYNO:BEARISH", color.RED);
AddLabel(yes and labels and Long1, "DYNO:BULLISH", color.green);
AddLabel(yes and labels and Long1 == Short1, "DYNO:NEUTRAL", color.YELLOW);

#Regression Bands

input deviations = 1.618;  #set your deviation units here.
input length = 500; #set your channel lookback period here.

def stdDeviation = StDevAll(price, length);
plot HighBand = if Bands then EMA_LinReg + deviations * stdDeviation else double.nan;
HighBand.SetDefaultColor(Color.red);
plot LowBand = if Bands then EMA_LinReg - deviations * stdDeviation else double.nan;
LowBand.SetDefaultColor(Color.green);
DefineGlobalColor("Bullish", Color.light_green);
DefineGlobalColor("Bearish", Color.light_RED);


#200 DAY MOVING AVERAGE

input lengthAvgEXP = 200;

plot AvgExp = ExpAverage(price[-displace], lengthAvgExp);

AvgExp.SetDefaultColor(Color.white);
AvgExp.setlineweight(2);

# Coloring Bars
AssignPriceColor(if ColorON and Long_State then Color.GREEN else if ColorON and Short_State then Color.RED else Color.Yellow);
DefineGlobalColor("Bullish", Color.dark_Green);
DefineGlobalColor("Bearish", Color.dark_Red);
AddCloud(EMA_LR, LinReg, GlobalColor("Bearish"), GlobalColor("Bullish"));


###################
#
# ALERTS
#
###################

Alert(alertON and LongTrigger, "Long Entry", Alert.BAR, Sound.Ding);

Alert(alertON and ShortTrigger, "Short Entry", Alert.BAR, Sound.Ding);

Alert(alertON and Buysetup, "HULL Buy", Alert.BAR, Sound.Bell);

Alert(alertON and Sellsetup, "HULL Sell", Alert.BAR, Sound.Bell);

Alert(alertON and high > highband, "Short Band", Alert.BAR, Sound.Ding);

Alert(alertON and low < lowband, "Long Band", Alert.BAR, Sound.Ding);


Thanks, and enjoy!!
Awesome work. Do you have a way to run a scan for the triangle and square?
 
@netarchitech thanks for your work on the scans. I got the first one (Hull Supertrend scan) to work, but not the Donchian Ribbon scan. I tried both the long and short version and daily and 15 min but kept coming back timed out with no results. I think it needs a bit more work. Thanks in advance
 
@chaseimo Try this...

Ruby:
# filename: Hull_SuperTrend_System_SCAN

#Hull_SuperTrend_Trading_System
# assembled by Chewie 4/10/2022
# many thanks to all the other noted contributors to this system.

# 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

#input Target_Bubbles = yes;
#input Entry_SL_Bubbles = yes;
#input labels = yes;
#input alertON = no;
input Bands = no;
input EMA1 = 10;
input EMA2 = 20;
input AvgType = AverageType.HULL;
input STAtrMult = 2.75;
input nATR = 12;

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;

def EMA1Val = MovAvgExponential(close, EMA1);
def EMA2Val = MovAvgExponential(close, EMA2);
def EMADirection = if EMA1Val > EMA2Val then 1 else if EMA1Val < EMA2Val then -1 else 0;

def Long = if close > ST then ST else Double.NaN;
def Short = if close < ST then ST else Double.NaN;

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

def LongDot = if LongTrigger then ST else Double.NaN;
def ShortDot = if ShortTrigger then ST else Double.NaN;

#
# Hull Moving Average Concavity and Turning Points
#
# Author: Seth Urion (Mahsume)
# Version: 2020-05-01 V4
#
# Now with support for ToS Mobile - disabled
#

declare upper;

input HMA_Length = 60;
input lookback = 3;
input arrows = no;

def price = HL2;
def HMA = HullMovingAvg(price = price, length = HMA_Length);
def delta = HMA[1] - HMA[lookback + 1];
def delta_per_bar = delta / lookback;
def next_bar = HMA[1] + delta_per_bar;
def concavity = if HMA > next_bar then 1 else -1;

def turning_point = if concavity[1] != concavity then HMA else Double.NaN;

def MA_Max = if HMA[-1] < HMA and HMA > HMA[1] then HMA else Double.NaN;
def MA_Min = if HMA[-1] > HMA and HMA < HMA[1] then HMA else Double.NaN;

#def BuySetup = HMA > HMA[1] and HMA[1] < HMA[2];
#def SellSetup =  HMA < HMA[1] and HMA[1] > HMA[2];

#plot sell = if arrows and turning_point and concavity == -1 then high else Double.NaN;
#sell.SetDefaultColor(Color.DARK_ORANGE);
#sell.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
#sell.SetLineWeight(3);
#sell.hide();

#plot buy = if arrows and turning_point and concavity == 1 then low else Double.NaN;
#buy.SetDefaultColor(Color.CYAN);
#buy.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
#buy.SetLineWeight(3);
#buy.hide();

def divergence = HMA - next_bar;


###################
#
# 2020-05-01
#
# MOBILE TOS SUPPORT
#
# Each color of the HMA needs to be a separate plot as ToS Mobile
# lacks the ability to assign colors the way ToS Desktop does.
# I recommend a plain colored HMA behind the line
# Set the line color of the HMA above to gray or some neutral
#
# CCD_D -> ConCave Down and Decreasing
# CCD_I -> ConCave Down and Increasing
# CCU_D -> ConCave Up and Decreasing
# CCU_I -> ConCave Up and Increasing
#
###################
#plot CCD_D = if concavity == -1 and HMA < HMA[1] then HMA else Double.NaN;
#CCD_D.SetDefaultColor(Color.RED);
#CCD_D.SetLineWeight(1);
#CCD_D.hide();

#plot CCD_I = if concavity == -1 and HMA >= HMA[1] then HMA else Double.NaN;
#CCD_I.SetDefaultColor(Color.DARK_ORANGE);
#CCD_I.SetLineWeight(1);
#CCD_I.hide();

#plot CCU_D = if concavity == 1 and HMA <= HMA[1] then HMA else Double.NaN;
#CCU_D.SetDefaultColor(Color.DARK_GREEN);
#CCU_D.SetLineWeight(1);
#CCU_D.hide();

#plot CCU_I = if concavity == 1 and HMA > HMA[1] then HMA else Double.NaN;
#CCU_I.SetDefaultColor(Color.GREEN);
#CCU_I.SetLineWeight(1);
#CCU_I.hide();

#Hull Label

#AddLabel(yes and labels and CCD_D, "HULL:SELL", color.RED);
#AddLabel(yes and labels and CCU_I, "HULL:BUY", color.green);
#AddLabel(yes and labels and CCU_D, "HULL:WEAK SELL", color.dark_green);
#AddLabel(yes and labels and CCD_I, "HULL:WEAK BUY", color.DARK_ORANGE);

#Target lines
# created by chewie

rec line = if IsNaN(MA_Min) then line[1] else MA_Min[0];
def L_stoploss = if IsNaN(MA_Min) then line else Double.NaN;
def LSL = (if IsNaN(L_stoploss[1]) then L_stoploss else Double.NaN);

rec line2 = if IsNaN(MA_Max) then line2[1] else MA_Max[0];
def S_stoploss = if IsNaN(MA_Max) then line2 else Double.NaN;
def SSL = (if IsNaN(S_stoploss[1]) then S_stoploss else Double.NaN);

#Short Entry
rec line3 = if IsNaN(Long) then line3[1] else Long[0];
def S_Entry = if IsNaN(Long) then line3 else Double.NaN;
def SE = (if IsNaN(S_Entry[1]) then S_Entry else Double.NaN);

#Long Entry
rec line4 = if IsNaN(Short) then line4[1] else Short[0];
def L_Entry = if IsNaN(Short) then line4 else Double.NaN;
def LE = (if IsNaN(L_Entry[1]) then L_Entry else Double.NaN);


#HalfX Long
def x1a_Long =  (L_Entry + (L_Entry - L_stoploss) / 2) ;

#OneX Long
def x1_Long = if x1a_Long > line4 then (L_Entry + (L_Entry - L_stoploss)) else Double.NaN;

#TwoX Long
def x2_Long = x1_Long + (L_Entry - L_stoploss) ;
def X2L = (if IsNaN(x2_Long[1]) then x2_Long else Double.NaN);

#ThreeX Long
def x3_Long = x2_Long + (L_Entry - L_stoploss) ;
def X3L = (if IsNaN(x3_Long[1]) then x3_Long else Double.NaN);

#FourX Long
def x4_Long = x3_Long + (L_Entry - L_stoploss) ;
def X4L = (if IsNaN(x4_Long[1]) then x4_Long else Double.NaN);


#HalfX Short
def x1a_Short = (S_Entry - (S_stoploss - S_Entry) / 2);

#OneX Short
def x1_Short = if x1a_Short < line3 then (S_Entry - (S_stoploss - S_Entry)) else Double.NaN;

#TwoX Short
def x2_Short = x1_Short - (S_stoploss - S_Entry);
def X2S = (if IsNaN(x2_Short[1]) then x2_Short else Double.NaN);

#ThreeX Short
def x3_Short = x2_Short - (S_stoploss - S_Entry);
def X3S = (if IsNaN(x3_Short[1]) then x3_Short else Double.NaN);

#FourX Short
def x4_Short = x3_Short - (S_stoploss - S_Entry);
def X4S = (if IsNaN(x4_Short[1]) then x4_Short else Double.NaN);

#LinearRegCh100 RegressionDivergence - Trigger Lines - Trend Cross
# From Lizard Indicators Link: https://www.lizardindicators.com/trigger-lines-cross-vs-thrust/
# Line #1 - Fast = LinReg (80)
# Line #2 - Slow = EXPEMA[LinReg (80)]

input LinRegLength = 80;
input EMAlength = 20;
input ColorOn = yes;

#Definitions
def price1 = close;
def displace = 0;
def LinReg = Inertia(price1[-displace], LinRegLength);
def EMA_LR = ExpAverage(LinReg[-displace], EMAlength);
def Body = (open + close) / 2;

# Defining Long/Short Filters (these instructions determine entries / exits)
# Entry Requirements
def Long_Entry = close > LinReg and close > EMA_LR and Body > LinReg and Body > EMA_LR and close > high[1] and Body > Body[1];
# LinReg > LinReg[1] and
def Long_Stay_In = close > LinReg and close > EMA_LR;
def Long_Exit = (close < LinReg or close < EMA_LR) or Long_Stay_In == 0;
def Long_State = if Long_Entry then 1 else if Long_Exit then 0 else Long_State[1];
def Long1 = Long_State;

# Exit Requirements
def Short_Entry = close < LinReg and close < EMA_LR and Body < LinReg and Body < EMA_LR and close < low[1] and Body < Body[1];
# LinReg < LinReg[1] and
def Short_Stay_In = close < LinReg and close < EMA_LR;
def Short_Exit = (close > LinReg or close > EMA_LR) or Short_Stay_In == 0;
def Short_State = if Short_Entry then 1 else if Short_Exit then 0 else Short_State[1];
def Short1 = Short_State;

#Adding Linear Regression averages
def LR = LinReg;
def EMA_LinReg = EMA_LR;

#Regression Bands

input deviations = 1.618;  #set your deviation units here.
input length = 500; #set your channel lookback period here.

def stdDeviation = StDevAll(price, length);
def HighBand = if Bands then EMA_LinReg + deviations * stdDeviation else Double.NaN;
def LowBand = if Bands then EMA_LinReg - deviations * stdDeviation else Double.NaN;

#200 DAY MOVING AVERAGE

def price2 = close;
def displace2 = 0;
input lengthAvgEXP = 200;

def AvgExp = ExpAverage(price2[-displace2], lengthAvgEXP);

plot Triangle  = if HMA[-1] < HMA and HMA > HMA[1] then HMA else Double.NaN;
#plot Square = if HMA[-1] > HMA and HMA < HMA[1] then HMA else Double.NaN;

Hope this helps...

Good Luck and Good Trading :cool:
 
@netarchitech thanks for your work on the scans. I got the first one (Hull Supertrend scan) to work, but not the Donchian Ribbon scan. I tried both the long and short version and daily and 15 min but kept coming back timed out with no results. I think it needs a bit more work. Thanks in advance

@hockeycoachdoug I tested the Hull and Donchian studies applied to same scan and got results. I will try to reproduce the test and post back when I can...

In the meantime, were you testing the studies separately? If so, can you try them combined in a new scan and see if you get results?
 
@chewie76 @AnimalMother The following step-by-step outlines how to successfully create a scan when TOS says "it's too complex to scan"...
  1. Open the Hull SuperTrend System code in your preferred text editor
  2. Change all "plots" to "def" (except if part of a Script or an Input)
  3. Delete all corresponding plot formatting code
  4. Add desired Scan Query using plot statement
Below is a sample excerpt of the conversion:

#200 DAY MOVING AVERAGE​
def price1 = close;​
def displace = 0;​
input lengthAvgEXP = 200;​
Delete the plot and replace with def
plot def AvgExp = ExpAverage(price1[-displace], lengthAvgExp);​
Delete all plot formatting code
AvgExp.SetDefaultColor(Color.white);
AvgExp.setlineweight(2);
Add desired Scan Query
plot bullscan = close > open and close > AvgExp and AvgExp > AvgExp[1];​
#plot bearscan = close < open and close < AvgExp and AvgExp < AvgExp[1];​


Complete conversion of Chewie's SuperTrend/Hull Average/Donchian Trend Ribbon Trading System:

Rich (BB code):
# filename: Hull_SuperTrend_System_SCAN

#Hull_SuperTrend_Trading_System
# assembled by Chewie 4/10/2022
# many thanks to all the other noted contributors to this system.

# 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

#input Target_Bubbles = yes;
#input Entry_SL_Bubbles = yes;
#input labels = yes;
#input alertON = no;
input Bands = no;
input EMA1 = 10;
input EMA2 = 20;
input AvgType = AverageType.HULL;
input STAtrMult = 2.75;
input nATR = 12;

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;

def EMA1Val = MovAvgExponential(close, EMA1);
def EMA2Val = MovAvgExponential(close, EMA2);
def EMADirection = if EMA1Val > EMA2Val then 1 else if EMA1Val < EMA2Val then -1 else 0;

def Long = if close > ST then ST else Double.NaN;
def Short = if close < ST then ST else Double.NaN;

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

def LongDot = if LongTrigger then ST else Double.NaN;
def ShortDot = if ShortTrigger then ST else Double.NaN;

#
# Hull Moving Average Concavity and Turning Points
#
# Author: Seth Urion (Mahsume)
# Version: 2020-05-01 V4
#
# Now with support for ToS Mobile - disabled
#

declare upper;

input HMA_Length = 60;
input lookback = 3;
input arrows = no;

def price = HL2;
def HMA = HullMovingAvg(price = price, length = HMA_Length);
def delta = HMA[1] - HMA[lookback + 1];
def delta_per_bar = delta / lookback;
def next_bar = HMA[1] + delta_per_bar;
def concavity = if HMA > next_bar then 1 else -1;

def turning_point = if concavity[1] != concavity then HMA else Double.NaN;

def MA_Max = if HMA[-1] < HMA and HMA > HMA[1] then HMA else Double.NaN;
def MA_Min = if HMA[-1] > HMA and HMA < HMA[1] then HMA else Double.NaN;

#def BuySetup = HMA > HMA[1] and HMA[1] < HMA[2];
#def SellSetup =  HMA < HMA[1] and HMA[1] > HMA[2];

#plot sell = if arrows and turning_point and concavity == -1 then high else Double.NaN;
#sell.SetDefaultColor(Color.DARK_ORANGE);
#sell.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
#sell.SetLineWeight(3);
#sell.hide();

#plot buy = if arrows and turning_point and concavity == 1 then low else Double.NaN;
#buy.SetDefaultColor(Color.CYAN);
#buy.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
#buy.SetLineWeight(3);
#buy.hide();

def divergence = HMA - next_bar;


###################
#
# 2020-05-01
#
# MOBILE TOS SUPPORT
#
# Each color of the HMA needs to be a separate plot as ToS Mobile
# lacks the ability to assign colors the way ToS Desktop does.
# I recommend a plain colored HMA behind the line
# Set the line color of the HMA above to gray or some neutral
#
# CCD_D -> ConCave Down and Decreasing
# CCD_I -> ConCave Down and Increasing
# CCU_D -> ConCave Up and Decreasing
# CCU_I -> ConCave Up and Increasing
#
###################
#plot CCD_D = if concavity == -1 and HMA < HMA[1] then HMA else Double.NaN;
#CCD_D.SetDefaultColor(Color.RED);
#CCD_D.SetLineWeight(1);
#CCD_D.hide();

#plot CCD_I = if concavity == -1 and HMA >= HMA[1] then HMA else Double.NaN;
#CCD_I.SetDefaultColor(Color.DARK_ORANGE);
#CCD_I.SetLineWeight(1);
#CCD_I.hide();

#plot CCU_D = if concavity == 1 and HMA <= HMA[1] then HMA else Double.NaN;
#CCU_D.SetDefaultColor(Color.DARK_GREEN);
#CCU_D.SetLineWeight(1);
#CCU_D.hide();

#plot CCU_I = if concavity == 1 and HMA > HMA[1] then HMA else Double.NaN;
#CCU_I.SetDefaultColor(Color.GREEN);
#CCU_I.SetLineWeight(1);
#CCU_I.hide();

#Hull Label

#AddLabel(yes and labels and CCD_D, "HULL:SELL", color.RED);
#AddLabel(yes and labels and CCU_I, "HULL:BUY", color.green);
#AddLabel(yes and labels and CCU_D, "HULL:WEAK SELL", color.dark_green);
#AddLabel(yes and labels and CCD_I, "HULL:WEAK BUY", color.DARK_ORANGE);

#Target lines
# created by chewie

rec line = if IsNaN(MA_Min) then line[1] else MA_Min[0];
def L_stoploss = if IsNaN(MA_Min) then line else Double.NaN;
def LSL = (if IsNaN(L_stoploss[1]) then L_stoploss else Double.NaN);

rec line2 = if IsNaN(MA_Max) then line2[1] else MA_Max[0];
def S_stoploss = if IsNaN(MA_Max) then line2 else Double.NaN;
def SSL = (if IsNaN(S_stoploss[1]) then S_stoploss else Double.NaN);

#Short Entry
rec line3 = if IsNaN(Long) then line3[1] else Long[0];
def S_Entry = if IsNaN(Long) then line3 else Double.NaN;
def SE = (if IsNaN(S_Entry[1]) then S_Entry else Double.NaN);

#Long Entry
rec line4 = if IsNaN(Short) then line4[1] else Short[0];
def L_Entry = if IsNaN(Short) then line4 else Double.NaN;
def LE = (if IsNaN(L_Entry[1]) then L_Entry else Double.NaN);


#HalfX Long
def x1a_Long =  (L_Entry + (L_Entry - L_stoploss) / 2) ;

#OneX Long
def x1_Long = if x1a_Long > line4 then (L_Entry + (L_Entry - L_stoploss)) else Double.NaN;

#TwoX Long
def x2_Long = x1_Long + (L_Entry - L_stoploss) ;
def X2L = (if IsNaN(x2_Long[1]) then x2_Long else Double.NaN);

#ThreeX Long
def x3_Long = x2_Long + (L_Entry - L_stoploss) ;
def X3L = (if IsNaN(x3_Long[1]) then x3_Long else Double.NaN);

#FourX Long
def x4_Long = x3_Long + (L_Entry - L_stoploss) ;
def X4L = (if IsNaN(x4_Long[1]) then x4_Long else Double.NaN);


#HalfX Short
def x1a_Short = (S_Entry - (S_stoploss - S_Entry) / 2);

#OneX Short
def x1_Short = if x1a_Short < line3 then (S_Entry - (S_stoploss - S_Entry)) else Double.NaN;

#TwoX Short
def x2_Short = x1_Short - (S_stoploss - S_Entry);
def X2S = (if IsNaN(x2_Short[1]) then x2_Short else Double.NaN);

#ThreeX Short
def x3_Short = x2_Short - (S_stoploss - S_Entry);
def X3S = (if IsNaN(x3_Short[1]) then x3_Short else Double.NaN);

#FourX Short
def x4_Short = x3_Short - (S_stoploss - S_Entry);
def X4S = (if IsNaN(x4_Short[1]) then x4_Short else Double.NaN);

#LinearRegCh100 RegressionDivergence - Trigger Lines - Trend Cross
# From Lizard Indicators Link: https://www.lizardindicators.com/trigger-lines-cross-vs-thrust/
# Line #1 - Fast = LinReg (80)
# Line #2 - Slow = EXPEMA[LinReg (80)]

input LinRegLength = 80;
input EMAlength = 20;
input ColorOn = yes;

#Definitions
def price1 = close;
def displace = 0;
def LinReg = Inertia(price1[-displace], LinRegLength);
def EMA_LR = ExpAverage(LinReg[-displace], EMAlength);
def Body = (open + close) / 2;

# Defining Long/Short Filters (these instructions determine entries / exits)
# Entry Requirements
def Long_Entry = close > LinReg and close > EMA_LR and Body > LinReg and Body > EMA_LR and close > high[1] and Body > Body[1];
# LinReg > LinReg[1] and
def Long_Stay_In = close > LinReg and close > EMA_LR;
def Long_Exit = (close < LinReg or close < EMA_LR) or Long_Stay_In == 0;
def Long_State = if Long_Entry then 1 else if Long_Exit then 0 else Long_State[1];
def Long1 = Long_State;

# Exit Requirements
def Short_Entry = close < LinReg and close < EMA_LR and Body < LinReg and Body < EMA_LR and close < low[1] and Body < Body[1];
# LinReg < LinReg[1] and
def Short_Stay_In = close < LinReg and close < EMA_LR;
def Short_Exit = (close > LinReg or close > EMA_LR) or Short_Stay_In == 0;
def Short_State = if Short_Entry then 1 else if Short_Exit then 0 else Short_State[1];
def Short1 = Short_State;

#Adding Linear Regression averages
def LR = LinReg;
def EMA_LinReg = EMA_LR;

#Regression Bands

input deviations = 1.618;  #set your deviation units here.
input length = 500; #set your channel lookback period here.

def stdDeviation = StDevAll(price, length);
def HighBand = if Bands then EMA_LinReg + deviations * stdDeviation else Double.NaN;
def LowBand = if Bands then EMA_LinReg - deviations * stdDeviation else Double.NaN;

#200 DAY MOVING AVERAGE

def price1 = close;
def displace = 0;
input lengthAvgEXP = 200;

def AvgExp = ExpAverage(price[-displace], lengthAvgEXP);
AvgExp.SetDefaultColor(Color.white);
AvgExp.setlineweight(2);

plot bullscan = close > open and close > AvgExp and AvgExp > AvgExp[1];
#plot bearscan = close < open and close < AvgExp and AvgExp < AvgExp[1];


Rich (BB code):
# filename: Donchian_Trend_Ribbon_SCAN

# donchian_trend_ribbon_0e

# convert - donchian trend ribbon
# halcyonguy
# 22-04-07

# 00e
# can chg secondary colors ( 1 , -1) to yellow or diff shades

# 00d
# add histogram , sum of color numbers

# https://usethinkscript.com/threads/convert-tradingview-donchian-trend-ribbon.10822/
# Convert Tradingview Donchian Trend Ribbon
# chewie76  4/4
# Can someone convert the Donchian Trend Ribbon into TOS?
# --------------------------------
# https://www.tradingview.com/script/PxLqmP8o-Donchian-Trend-Ribbon/
#I think you all know Donchian Channels . so I am not going to write about it.
#https://www.tradingview.com/scripts/donchianchannels/
#With this indicator I tried to create Donchian Trend Ribbon by using Donchian Channels .

# How it works ?
# - it calculates main trend direction by using the length that is user-defined. so you can change it as you wish
# - then it calculates trend direction for each 9 lower lengths. if you set the length = 20 then the lengths are 19, 18,...11
# - and it checks if the trend directions that came from lower lengths is same or not with main trend direction.
# - it changes the trend color of the ribbon.
# -----------------------------

#declare lower;

input Donchian_Channel_Period = 20;
def dlen = if Donchian_Channel_Period < 10 then 10 else Donchian_Channel_Period;
input show_data_rows = yes;
input show_sum_histo = yes;
def na = double.nan;

input secondary_colors = { default yellow , green_red };
input show_full_height_of_histogram = yes;
def z = if show_full_height_of_histogram and !isnan(close) then 0 else na;

script dchannel {
  input len = 0;
  def hh = highest(high, len);
  def ll = lowest(low, len);
  def trend = if barnumber() == 1 then 0 else if close > hh[1] then 1 else if close < ll[1] then -1 else trend[1];
  plot z = trend;
}

script dchannelalt {
  input len = 0;
  input maintrend = 0;
  def hh = highest(high, len);
  def ll = lowest(low, len);
  def trend = if barnumber() == 1 then 0 else if close > hh[1] then 1 else if close < ll[1] then -1 else trend[1];
 
 def maincolor =
  if maintrend == 1 then if trend == 1 then 2 else 1
  else if maintrend == -1 then if trend == -1 then -2 else -1
  else 0;

  plot color = maincolor;
#  plot tr = trend;
}

def maintrend = dchannel(dlen);

# ---------------------------------

# input secondary_colors = { default yellow , green_red };
def seccolor;
switch (secondary_colors) {
case yellow:
  seccolor = 1;
case green_red:
  seccolor = 2;
}

#   colors
# 2 - up trend - green
# 1 - up trend - dark green
# 0 no trend
# -1 - down trend - dark red
# -2 - down trend - red

DefineGlobalColor("up2", color.green);
DefineGlobalColor("up1", color.dark_green);
DefineGlobalColor("none", color.dark_gray);
DefineGlobalColor("dwn1", color.dark_red);
DefineGlobalColor("dwn2", color.red);
# GlobalColor("up1")
DefineGlobalColor("alt1", color.yellow);
# GlobalColor("alt1")
#----------------------------------------

input bottom_row = 0;
def rowstart = if bottom_row <> 0 then bottom_row
  else if ( show_data_rows and show_sum_histo ) then 25
  else 0;

input rowskip = 5;
input square_size = 4;

#plot( 5, color = dchannelalt(dlen - 0, maintrend), style = plot.style_columns, histbase= 0)
def c01 = dchannelalt(dlen - 0, maintrend);
def row01 = if isnan(close) then double.nan else (rowstart + ( 1 * rowskip));

def c02 = dchannelalt(dlen - 1, maintrend);
def row02 = if isnan(close) then double.nan else (rowstart + ( 2 * rowskip));

def c03 = dchannelalt(dlen - 2, maintrend);
def row03 = if isnan(close) then double.nan else (rowstart + ( 3 * rowskip));

def c04 = dchannelalt(dlen - 3, maintrend);
def row04 = if isnan(close) then double.nan else (rowstart + ( 4 * rowskip));

def c05 = dchannelalt(dlen - 4, maintrend);
def row05 = if isnan(close) then double.nan else (rowstart + ( 5 * rowskip));

def c06 = dchannelalt(dlen - 5, maintrend);
def row06 = if isnan(close) then double.nan else (rowstart + ( 6 * rowskip));

def c07 = dchannelalt(dlen - 6, maintrend);
def row07 = if isnan(close) then double.nan else (rowstart + ( 7 * rowskip));

def c08 = dchannelalt(dlen - 7, maintrend);
def row08 = if isnan(close) then double.nan else (rowstart + ( 8 * rowskip));

def c09 = dchannelalt(dlen - 8, maintrend);
def row09 = if isnan(close) then double.nan else (rowstart + ( 9 * rowskip));

def c10 = dchannelalt(dlen - 9, maintrend);
def row10 = if isnan(close) then double.nan else (rowstart + ( 10 * rowskip));

# -----------------------------

# add up color numbers, to come up with a 'trend' number , 20 to -20
def colorsum = ( c01 + c02 + c03 + c04 + c05 + c06 + c07 + c08 + c09 + c10 );

# plot a histogram of colorsum.
# it uses absvalue( ), so it is positive numbers, 0 to 20
#input vert1 = 0;  + vert1
def zc = if show_sum_histo then (absvalue(colorsum)) else na;

plot bullscan = colorsum >= 19;
#plot bearscan = colorsum <= -19;


Hope this helps...

Good Luck and Good Trading :cool:
Your first converted scirpt has error at line 246:
Identifier Already Used: price1 at 246:5
Identifier Already Used: displace at 247:5
Can not call SetDefaultColor on AvgExp at 251:1
Can not call setlineweight on AvgExp at 252:1
 
i am new here how to scanner work bull and bear please give detail instruction.i try true and bar 2 but i dont get any result
thank you
 
If anyone wants it. Here is the code for the SuperTrend which was converted to match the video exactly

Code:
#JT_SuperTrend v1.0 (Replica From TradingView)

Declare Upper;

##################################################################
#                          Hull Suite                            #
##################################################################
def length = 60;

def HMA = wma(2 * wma(close, (length*3) / 2) - wma(close, (length*3)), round(sqrt((length*3))));

def HULL = HMA;
def MHULL = HULL[0];
def SHULL = HULL[2];

plot HMA1 = MHULL;
HMA1.AssignValueColor(if HULL > HULL[2] then COLOR.GREEN else COLOR.RED);
HMA1.SetLineWeight(1);

plot HMA2 = SHULL;
HMA2.AssignValueColor(if HULL > HULL[2] then COLOR.GREEN else COLOR.RED);
HMA2.SetLineWeight(1);

AddCloud (HMA1, HMA2);

##################################################################
#                         SuperTrend                             #
##################################################################
def AtrMult = 5;
def nATR = 50;
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);

##################################################################
#                             Cloud                              #
##################################################################
AddCloud(if close > long then long else double.nan, close, color.light_green, color.light_green);
AddCloud(if close< short then short else double.nan, close, color.pink, color.pink);
 
Is there a way in TOS to buy custom with conditioning order when Supertrend showing a buy signal ?
 
Yes. It is my main strategy I am using. Trading the ES and NQ, I like the 2 min and 1600T chart. Seeing some good wins!
Hey Chewie, Just came across your work and this is amazing. I was wondering if there is a way only to keep the most recent signals, rather than past signals and target line displayed all over the chart. Its nothing biggie to have it all colorful, but only having the most recent maybe 1 (max) would make it so much better.

Regards-
 
Hey Chewie, Just came across your work and this is amazing. I was wondering if there is a way only to keep the most recent signals, rather than past signals and target line displayed all over the chart. Its nothing biggie to have it all colorful, but only having the most recent maybe 1 (max) would make it so much better.

Regards-
Sure. You can use this version. http://tos.mx/5tpOtfR This has an input "numberofBars" at the top, default 20 bars to look back. Change this length as you wish. Also, if you want to hide additional plots, just add "okToPlot" to the plot lines in the code. Thanks.
 

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
410 Online
Create Post

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