Archived: Supertrend Indicator by Mobius for ThinkorSwim

Status
Not open for further replies.
it looks like an atr trailing stop with different settings or different time frames, so a quicker setting and a longer setting. a recomendation would be line 5, 3.5, and then for the longer time period, play around with it.
Hi, TOS already has an ATR indicator, only I don't know how to get more that one timeframe to plot similar to Abletrend. I tried adding the ATR twice, however after tweaking the settings it doesn't plot correctly. Any ideas?
 
change
plot scan = count > 1; and change 1 to whatever number you want the count to be greater than....


if you dont want the count as a watch list and want to scan in the scanner then it would be:


Code:
# SuperTrend for WatchList
# Mobius
# 8.8.2017

input AtrMult = .7;
input nATR = 4;
input AvgType = AverageType.Hull;

def h = high;
def l = low;
def c = close;
def ATR = MovingAverage(AvgType, TrueRange(h, c, l), nATR);
def UP = hl2 + (ATRmult * ATR);
def DN = hl2 + (-ATRmult * ATR);
def ST = if c < ST[1]
         then Round(UP / TickSize(), 0) * TickSize()
         else Round(DN / TickSize(), 0) * TickSize();
def count = if c crosses below ST
            then 1
            else if c < ST
                 then count[1] + 1
                 else if c crosses above ST
                      then 1
                      else if c > ST[1]
                           then count[1] + 1
                           else count[1];
plot scan = count > 1;
 
Can someone help me change this so that normal green bars are green and the red bars which are painted green are painted dark_green instead?
Likewise with the red bars, normal red bars are red and red bars which are painted green painted dark_green.

Code:
# Mobius

# SuperTrend

# Chat Room Request

# V03.10.2015

# Added Bubbles to mark entry and exit prices. Doesn't give much time to follow into trade, but better than guessing.

# Altered default settings for values that made more sense on Intraday Futures. Added Color and ColorBars.

#Hint:Supertrend Indicator: shows trend direction and gives buy or sell signals according to that. It is based on a combination of the average price rate in the current period along with a volatility indicator. The ATR indicator is most commonly used as volatility indicator. The values are calculated as follows:

# Up = (HIGH + LOW) / 2 + Multiplier * ATR

# Down = (HIGH + LOW) / 2 – Multiplier * ATR

# When the change of trend occurs, the indicator flips

 

input AtrMult = 1.0;

input nATR = 4;

input AvgType = AverageType.HULL;

input PaintBars = yes;

 

def ATR = MovingAverage(AvgType, TrueRange(high, close, low), nATR);

def UP = HL2 + (AtrMult * ATR);

def DN = HL2 + (-AtrMult * ATR);

def ST = if close < ST[1] then UP else DN;

plot SuperTrend = ST;

SuperTrend.AssignValueColor(if close < ST then Color.RED else Color.GREEN);

AssignPriceColor(if PaintBars and close < ST 

                 then Color.RED 

                 else if PaintBars and close > ST 

                      then Color.GREEN 

                      else Color.CURRENT);

plot bullish = if close crosses above ST then low[1] else double.nan;
plot bearish = if close crosses below ST then low[1] else double.nan;
bullish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_wedge_UP);
bullish.SetDefaultColor(Color.GREEN);
bullish.SetLineWeight(3);
bearish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_wedge_DOWN);
bearish.SetDefaultColor(Color.RED);
bearish.SetLineWeight(3);




# End Code SuperTrend
 
Can someone help me change this so that normal green bars are green and the red bars which are painted green are painted dark_green instead?
Likewise with the red bars, normal red bars are red and red bars which are painted green painted dark_green.

Code:
# Mobius

# SuperTrend

# Chat Room Request

# V03.10.2015

# Added Bubbles to mark entry and exit prices. Doesn't give much time to follow into trade, but better than guessing.

# Altered default settings for values that made more sense on Intraday Futures. Added Color and ColorBars.

#Hint:Supertrend Indicator: shows trend direction and gives buy or sell signals according to that. It is based on a combination of the average price rate in the current period along with a volatility indicator. The ATR indicator is most commonly used as volatility indicator. The values are calculated as follows:

# Up = (HIGH + LOW) / 2 + Multiplier * ATR

# Down = (HIGH + LOW) / 2 – Multiplier * ATR

# When the change of trend occurs, the indicator flips



input AtrMult = 1.0;

input nATR = 4;

input AvgType = AverageType.HULL;

input PaintBars = yes;



def ATR = MovingAverage(AvgType, TrueRange(high, close, low), nATR);

def UP = HL2 + (AtrMult * ATR);

def DN = HL2 + (-AtrMult * ATR);

def ST = if close < ST[1] then UP else DN;

plot SuperTrend = ST;

SuperTrend.AssignValueColor(if close < ST then Color.RED else Color.GREEN);

AssignPriceColor(if PaintBars and close < ST

                 then Color.RED

                 else if PaintBars and close > ST

                      then Color.GREEN

                      else Color.CURRENT);

plot bullish = if close crosses above ST then low[1] else double.nan;
plot bearish = if close crosses below ST then low[1] else double.nan;
bullish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_wedge_UP);
bullish.SetDefaultColor(Color.GREEN);
bullish.SetLineWeight(3);
bearish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_wedge_DOWN);
bearish.SetDefaultColor(Color.RED);
bearish.SetLineWeight(3);




# End Code SuperTrend
Replace the Assignpricecolor code above with this:

Code:
AssignPriceColor(if PaintBars and close < ST

                 then if close > open then Color.DARK_RED else Color.RED

                 else if PaintBars and close > ST

                      then if close < open then Color.DARK_GREEN else Color.GREEN

                      else Color.CURRENT);
 
Hi,

I am trying to use the scanner for supertrend Mobius for daily fresh signals. But for some reason the scanner is not working..I am using the code given
in the Supertrend indicator post. Can someone please help me with the setup.

Thanks
Sara
 
Hi,

Thankyou for answering my question..I did setup the scanner as shown in the video..but still I am not getting any results..I dont know where I am going wrong..

Thanks
Sara
 
Hi,

I am trying to use the scanner for supertrend Mobius for daily fresh signals. But for some reason the scanner is not working..I am using the code given
in the Supertrend indicator post. Can someone please help me with the setup.

Thanks
Sara
# Mobius
# SuperTrend
# Chat Room Requestdef c = close;
def h = high;
def l = low;
def pricedata = hl2;

input AtrMult = 1.0;
input nATR = 4;
input AvgType = AverageType.HULL;
input PaintBars = yes;
def ATR = MovingAverage(AvgType, TrueRange(high, close, low), nATR);
def UP = HL2 + (AtrMult * ATR);
def DN = HL2 + (-AtrMult * ATR);
def ST = if close < ST[1] then UP else DN;

#plot BearScan = if (close crosses below ST)
# then close
# else Double.NaN;
plot BullScan = if (close crosses above ST)
then close
else Double.NaN;
# End Code SuperTrend

____________________
paste in scanner thinker editor
 
hey mate, thank you for pointing me in the right direction. I tested this just now and this Supertrend comes pretty close to this customised trend indicator.

This customised trend indicator has some additional, please the see the image here. Indicator named Greatest

Qac5VrO.png


Would you be able to decode these additional parameters?

Thanks in advance
hey I have the indicator you were looking for. Exact same thing.

After you paste in the code, go into the settings of the indicator, scroll all the way down, click super trend box, and then uncheck the 'show plot' box to have a working version that is the exact code you are looking for.

Code:
#Public Indicator
#Special Thanks to Morbius who created original super trend indicator. This is a spin off of his work. All credits go to him. This software is free.
#CREATED 09/12/2020


input AtrMult = 0.7;
input nATR = 4;
input AvgType = AverageType.HULL;
input PaintBars = yes;
def ATR = MovingAverage(AvgType, TrueRange(high, close, low), nATR);
def UP = HL2 + (AtrMult * ATR);
def DN = HL2 + (-AtrMult * ATR);
def ST = if close < ST[1] then UP else DN;
plot SuperTrend = ST;

SuperTrend.AssignValueColor(if close < ST then Color.GREEN else color.RED);

AssignPriceColor(if PaintBars and close < ST

                 then Color.RED

                 else if PaintBars and close > ST

                      then Color.GREEN

                      else Color.CURRENT);

#AddChartBubble(close crosses below ST, low[1], low[1], #color.Dark_Gray);
#AddChartBubble(close crosses above ST, high[1], high[1], #color.Dark_Gray, no);
# End Code SuperTrend# Mobius
# SuperTrend
# Chat Room Request

plot SuperTrendUp = close crosses above ST;
plot SuperTrendDown = close crosses below ST;
SuperTrend.AssignValueColor(if close < ST then Color.RED else Color.GREEN);
SuperTrendUp.SetDefaultColor(Color.YELLOW);
SuperTrendUp.setPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
SuperTrendDown.SetDefaultColor(Color.PINK);
SuperTrendDown.setPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

def bullish = close crosses below ST;
def bearish = close crosses above ST;

# Alerts
Alert(bullish, " ", Alert.Bar, Sound.Chimes);
Alert(bearish, " ", Alert.Bar, Sound.Bell);





#ProjectionPivots_v03_JQ
#03.04.2019
#Original Code and Concept by Mobius:
# V01.08.2012 Projection Pivots
# mobius

# Notes:
# 03.04.2019 added linits on extensions
# 03.05.2019 adjusted limits on extensions by adding user input upper and lower extenion percent limits

#declare Once_Per_Bar;
#Inputs
input n = 21;
input showLines = yes;
input showValues = no;
input showBarNumbers = no;
input ExtensionLengthBars = 20; # added to control length of Entension
input UpperExtensionPercentLimit = 5;
input LowerExtensionPercentLimit = 5;
input DisplayLabel = yes;    #JQ 7.8.2018 added
    addlabel (DisplayLabel, "Projection Pivots n:" + n + " " , color.WHITE);    #JQ 7.8.2018 added


# Universal Header _v030429019 _JQ
#     code from various sources including Mobius, NoLongerNube and others
# Comment out unnecessary portions to preserve tos memory and enhance speed

# Universal Definitions using Padawan variable naming convention (JQ) v03.04.2019
# iData Definitions
    def vHigh = high;  # creates the variable vHigh.  Use of the variable reduce data calls to tos iData server
#    def initHigh =  CompoundValue(1, high, high);  # creates and initialized variable for High
    def vLow = low;
#    def initLow = CompoundValue(1, low, low);
    def vOpen = open;
#    def initOpen = CompoundValue(1, open, open);
    def vClose = close;
#    def initClose = CompoundValue(1, close, close);
    def vVolume = volume;
#    def initVolume = CompoundValue(1, volume, volume);
    def nan = Double.NaN;
# Bar Time & Date
    def bn = BarNumber();
    def currentBar = HighestAll(if !IsNaN(vHigh) then bn else nan);
#    def Today = GetDay() ==GetLastDay();
#    def time = GetTime();
#    def GlobeX = GetTime() < RegularTradingStart(GetYYYYMMDD());
    # def globeX_v2 = if time crosses below RegularTradingEnd(GetYYYYMMDD()) then bn else GlobeX[1];
#    def RTS  = RegularTradingStart(GetYYYYMMDD());
#    def RTE  = RegularTradingEnd(GetYYYYMMDD());
#    def RTH = GetTime() > RegularTradingStart(GetYYYYMMDD());
#    def RTH_v2 = if time crosses above RegularTradingStart(GetYYYYMMDD()) then bn else RTH[1];

# bars that start and end the sessions  #(borrowed from nube)
#    def rthStartBar    = CompoundValue(1,
#                         if   !IsNaN(vClose)
#                         &&   time crosses above RegularTradingStart(GetYYYYMMDD())
#                         then bn
#                         else rthStartBar[1], 0);
#    def rthEndBar      = CompoundValue(1,
#                         if   !IsNaN(vClose)
#                         &&   time crosses above RegularTradingEnd(GetYYYYMMDD())
#                         then bn
#                         else rthEndBar[1], 1);
#    def globexStartBar = CompoundValue(1,
#                         if   !IsNaN(vClose)
#                         &&   time crosses below RegularTradingEnd(GetYYYYMMDD())
#                         then bn
#                         else globexStartBar[1], 1);
#    def rthSession = if   bn crosses above rthStartBar #+ barsExtendedBeyondSession
#                     then 1
#                     else if   bn crosses above rthEndBar #+ barsExtendedBeyondSession
#                          then 0
#                     else rthSession[1];

# Bubble Locations
    def x_AxisLastExpansionBar = BarNumber() == HighestAll(BarNumber());  #corrected 11.12.2018 (JQ)
        # syntax: addChartBubble(x_AxisLastExpansionBar, y-axis coordinate," text", Color.LIME); #verified 12.25.2018 (JQ)

def PH;
   def PL;
   def hh = fold i = 1 to n + 1
            with p = 1
            while p
            do vHigh > getValue(vHigh, -i);
       PH = if (bn > n and
                vHigh == highest(vHigh, n) and
                hh)
            then vHigh
            else double.NaN;
   def ll = fold j = 1 to n + 1
            with q = 1
            while q
            do vLow < getValue(low, -j);
       PL = if (bn > n and
                vLow == lowest(vLow, n) and
                ll)
            then vLow
            else double.NaN;
   def PHBar = if !isNaN(PH)
               then bn
               else PHBar[1];
   def PLBar = if !isNaN(PL)
               then bn
               else PLBar[1];
   def PHL = if !isNaN(PH)
             then PH
             else PHL[1];
   def priorPHBar = if PHL != PHL[1]
                    then PHBar[1]
                    else priorPHBar[1];
   def PLL = if !isNaN(PL)
             then PL
             else PLL[1];
   def priorPLBar = if PLL != PLL[1]
                    then PLBar[1]
                    else priorPLBar[1];
   def HighPivots = bn >= highestAll(priorPHBar);
   def LowPivots = bn >= highestAll(priorPLBar);
   def FirstRpoint = if HighPivots
                     then bn - PHBar
                     else 0;
   def PriorRpoint = if HighPivots
                     then bn - PriorPHBar
                     else 0;
   def RSlope = (getvalue(PH, FirstRpoint) - getvalue(PH, PriorRpoint))
                       / (PHBar - PriorPHBar);
   def FirstSpoint = if LowPivots
                     then bn - PLBar
                     else 0;
   def PriorSpoint = if LowPivots
                     then bn - PriorPLBar
                     else 0;
   def SSlope = (getvalue(PL, FirstSpoint) - getvalue(PL, PriorSpoint))
                   / (PLBar - PriorPLBar);
   def RExtend = if bn == highestall(PHBar)
                 then 1
                 else RExtend[1];
   def SExtend = if bn == highestall(PLBar)
                 then 1
                 else SExtend[1];

  plot pivotHigh = if HighPivots
                   then PH
                   else double.NaN;
       pivotHigh.SetDefaultColor(GetColor(1));
       pivotHigh.setPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
       pivotHigh.setHiding(!showValues);

  plot pivotHighLine = if PHL > 0 and
                          HighPivots
                       then PHL
                       else double.NaN;
       pivotHighLine.SetPaintingStrategy(PaintingStrategy.DASHES);  # Mobius original was DASHES
       pivotHighLine.setDefaultColor(color.uptick);    #JQ 7.8.2018 added
       pivotHighLine.setHiding(!showLines);

  plot RLine = pivotHigh;
       RLine.enableApproximation();
       RLine.SetDefaultColor(Color.LIGHT_GRAY);
       RLine.SetStyle(Curve.Short_DASH);

# Added code to limit resistance estension line (JQ 03.04.2019)
  def calc_ResistanceExtension = if RExtend
                    then (bn - PHBar) * RSlope + PHL
                    else double.NaN;
  plot line_ResistanceExtension = if bn <= (Currentbar + ExtensionLengthBars)
                                   and calc_ResistanceExtension[1] >=  (lowestall(vLow) * (1-(lowerExtensionPercentLimit/100)))
                                   and calc_ResistanceExtension[1] <= (Highestall(vHigh) * (1 + (upperExtensionPercentLimit/100)))
                               then calc_ResistanceExtension else double.nan;
       line_ResistanceExtension.SetStyle(Curve.Short_DASH);
       line_ResistanceExtension.SetDefaultColor(color.LIGHT_GRAY); #was 7
       line_ResistanceExtension.setLineWeight(1);

# Low Plots
  plot pivotLow = if LowPivots
                  then PL
                  else double.NaN;
       pivotLow.setDefaultColor(GetColor(4));
       pivotLow.setPaintingStrategy(PaintingStrategy.VALUES_BELOW);
       pivotLow.setHiding(!showValues);

  plot pivotLowLine = if PLL > 0 and
                         LowPivots
                      then PLL
                      else double.NaN;
       pivotLowLine.SetPaintingStrategy(PaintingStrategy.DASHES);  # Mobius original was DASHES
       pivotLowLine.setDefaultColor(color.DOWNTICK);#  #  JQ 7.8.2018 added
       pivotLowLine.setHiding(!showLines);

  plot SupportLine = pivotLow;
       SupportLine.enableApproximation();
       SupportLine.SetDefaultColor(color.LIGHT_GRAY);
       SUpportLine.SetStyle(Curve.Short_DASH);

# Added code to limit support estension line (JQ 03.04.2019)
  def calc_SupportExtension = if SExtend
                          then (bn - PLBar) * SSlope + PLL
                          else double.NaN;
  plot line_SupportExtension = if bn <= (Currentbar + ExtensionLengthBars)
                                   and calc_SupportExtension[1] >= (lowestall(vLow) * (1-(lowerExtensionPercentLimit/100)))
                                   and calc_SupportExtension[1] <= (Highestall(vHigh) * (1 + (upperExtensionPercentLimit/100)))
                               then calc_supportExtension else double.nan;
       line_SupportExtension.SetDefaultColor(color.LIGHT_GRAY); #was 7
       line_SupportExtension.SetStyle(Curve.Short_DASH);
       line_SupportExtension.setLineWeight(1);

  plot BarNumbersBelow = bn;
       BarNumbersBelow.SetDefaultColor(GetColor(0));
       BarNumbersBelow.setHiding(!showBarNumbers);
       BarNumbersBelow.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);

  plot PivotDot = if !isNaN(pivotHigh)
                  then pivotHigh
                  else if !isNaN(pivotLow)
                  then pivotLow
                  else double.NaN;
       pivotDot.SetDefaultColor(GetColor(7));
       pivotDot.SetPaintingStrategy(PaintingStrategy.POINTS);
       pivotDot.SetLineWeight(3);
##



# End Code
 
is there a way to only show the most recent bubbles in this code that was posted above?

AddChartBubble(close crosses below ST, low[1], low[1], color.Dark_Gray);
AddChartBubble(close crosses above ST, high[1], high[1], color.Dark_Gray, no);
 
is there a way to only show the most recent bubbles in this code that was posted above?

AddChartBubble(close crosses below ST, low[1], low[1], color.Dark_Gray);
AddChartBubble(close crosses above ST, high[1], high[1], color.Dark_Gray, no);
not sure, someone got rid of those lines im pretty sure and replaced them with arrows in the code.
 
not sure, someone got rid of those lines im pretty sure and replaced them with arrows in the code.
I found that and it is an improvement for sure but for learning purposes I am trying to figure out how to only show the most recent BUY and SELL Bubble or Arrow.. I've been stuck trying to figure it out. No matter what I'm trying I'm doing it wrong.. I know it has to do with the barnumber() but am unable to grasp how to use that to only show what I want.. I can show only the current bubble if it happens to be the current barnumber() but as soon as that is not the current barnumber() it will disappear.. That's not what I'm trying to do! I want the Bubble or Arrow to stay with that barnumber() until the next even happens and then move to the current event barnumber() like the High and Lows bubbles do! Can you help this old brain figure it out? I'm just working with the Mobius SuperTrend or the modified one with the Arrows instead of bubbles..

This is what I'm doing and it's not correct for sure..


Def mHighest = highestAll(Close > st)within 200 bars and HighestAll(Barnumber()) ;
addChartBubble(if mHighest then 1 else 0, low, "Buy@",color.upTICK, no);
 
I found that and it is an improvement for sure but for learning purposes I am trying to figure out how to only show the most recent BUY and SELL Bubble or Arrow.. I've been stuck trying to figure it out. No matter what I'm trying I'm doing it wrong.. I know it has to do with the barnumber() but am unable to grasp how to use that to only show what I want.. I can show only the current bubble if it happens to be the current barnumber() but as soon as that is not the current barnumber() it will disappear.. That's not what I'm trying to do! I want the Bubble or Arrow to stay with that barnumber() until the next even happens and then move to the current event barnumber() like the High and Lows bubbles do! Can you help this old brain figure it out? I'm just working with the Mobius SuperTrend or the modified one with the Arrows instead of bubbles..

This is what I'm doing and it's not correct for sure..


Def mHighest = highestAll(Close > st)within 200 bars and HighestAll(Barnumber()) ;
addChartBubble(if mHighest then 1 else 0, low, "Buy@",color.upTICK, no);

See if this helps. It limits the plots of arrows and/or bubbles to user specified number input at 'count'.
Code:
# Mobius
# SuperTrend
# Chat Room Request
# Sleepyz modified per request to limit plots of bubbles/arrows to user specified number

input AtrMult = 1.0;
input nATR = 4;
input AvgType = AverageType.HULL;
input PaintBars = yes;
def ATR = MovingAverage(AvgType, TrueRange(high, close, low), nATR);
def UP = HL2 + (AtrMult * ATR);
def DN = HL2 + (-AtrMult * ATR);
def ST = if close < ST[1] then UP else DN;
plot SuperTrend = ST;
SuperTrend.AssignValueColor(if close < ST then Color.RED else Color.GREEN);
AssignPriceColor(if PaintBars and close < ST

                 then Color.RED

                 else if PaintBars and close > ST

                      then Color.GREEN

                      else Color.CURRENT);

#Plots Limited to Count
input Count = 2;
def cond = if close crosses ST then 1 else Double.NaN;
def dataCount = CompoundValue(1, if !IsNaN(cond) then dataCount[1] + 1 else dataCount[1], 0);
def data = if HighestAll(dataCount) - dataCount <= Count - 1 then 1 else Double.NaN;

#Limited Arrow Plots
input showarrows = yes;
plot arrowup = if showarrows and data and close crosses above ST then low[1] else Double.NaN;
arrowup.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
arrowup.SetDefaultColor(Color.DARK_GREEN);
arrowup.SetLineWeight(5);
plot arrowdn = if showarrows and data and close crosses below ST then high[1] else Double.NaN;
arrowdn.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
arrowdn.SetDefaultColor(Color.DARK_RED);
arrowdn.SetLineWeight(5);

#Limited Chart Bubble Plots
input showbubbles = yes;
AddChartBubble(if showbubbles and cond then data else Double.NaN,
               if close crosses above ST then high[1] else low[1],
               if close crosses above ST then high[1] else low[1],
               if close crosses above ST then Color.DARK_GREEN else Color.DARK_RED,
               if close crosses above ST then no else yes);

#AddChartBubble(close crosses below ST, low[1], low[1], color.Dark_Gray);
#AddChartBubble(close crosses above ST, high[1], high[1], color.Dark_Gray, no);
# End Code SuperTrend
 
hey I have the indicator you were looking for. Exact same thing.

After you paste in the code, go into the settings of the indicator, scroll all the way down, click super trend box, and then uncheck the 'show plot' box to have a working version that is the exact code you are looking for.

Code:
#Public Indicator
#Special Thanks to Morbius who created original super trend indicator. This is a spin off of his work. All credits go to him. This software is free.
#CREATED 09/12/2020


input AtrMult = 0.7;
input nATR = 4;
input AvgType = AverageType.HULL;
input PaintBars = yes;
def ATR = MovingAverage(AvgType, TrueRange(high, close, low), nATR);
def UP = HL2 + (AtrMult * ATR);
def DN = HL2 + (-AtrMult * ATR);
def ST = if close < ST[1] then UP else DN;
plot SuperTrend = ST;

SuperTrend.AssignValueColor(if close < ST then Color.GREEN else color.RED);

AssignPriceColor(if PaintBars and close < ST

                 then Color.RED

                 else if PaintBars and close > ST

                      then Color.GREEN

                      else Color.CURRENT);

#AddChartBubble(close crosses below ST, low[1], low[1], #color.Dark_Gray);
#AddChartBubble(close crosses above ST, high[1], high[1], #color.Dark_Gray, no);
# End Code SuperTrend# Mobius
# SuperTrend
# Chat Room Request

plot SuperTrendUp = close crosses above ST;
plot SuperTrendDown = close crosses below ST;
SuperTrend.AssignValueColor(if close < ST then Color.RED else Color.GREEN);
SuperTrendUp.SetDefaultColor(Color.YELLOW);
SuperTrendUp.setPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
SuperTrendDown.SetDefaultColor(Color.PINK);
SuperTrendDown.setPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

def bullish = close crosses below ST;
def bearish = close crosses above ST;

# Alerts
Alert(bullish, " ", Alert.Bar, Sound.Chimes);
Alert(bearish, " ", Alert.Bar, Sound.Bell);





#ProjectionPivots_v03_JQ
#03.04.2019
#Original Code and Concept by Mobius:
# V01.08.2012 Projection Pivots
# mobius

# Notes:
# 03.04.2019 added linits on extensions
# 03.05.2019 adjusted limits on extensions by adding user input upper and lower extenion percent limits

#declare Once_Per_Bar;
#Inputs
input n = 21;
input showLines = yes;
input showValues = no;
input showBarNumbers = no;
input ExtensionLengthBars = 20; # added to control length of Entension
input UpperExtensionPercentLimit = 5;
input LowerExtensionPercentLimit = 5;
input DisplayLabel = yes;    #JQ 7.8.2018 added
    addlabel (DisplayLabel, "Projection Pivots n:" + n + " " , color.WHITE);    #JQ 7.8.2018 added


# Universal Header _v030429019 _JQ
#     code from various sources including Mobius, NoLongerNube and others
# Comment out unnecessary portions to preserve tos memory and enhance speed

# Universal Definitions using Padawan variable naming convention (JQ) v03.04.2019
# iData Definitions
    def vHigh = high;  # creates the variable vHigh.  Use of the variable reduce data calls to tos iData server
#    def initHigh =  CompoundValue(1, high, high);  # creates and initialized variable for High
    def vLow = low;
#    def initLow = CompoundValue(1, low, low);
    def vOpen = open;
#    def initOpen = CompoundValue(1, open, open);
    def vClose = close;
#    def initClose = CompoundValue(1, close, close);
    def vVolume = volume;
#    def initVolume = CompoundValue(1, volume, volume);
    def nan = Double.NaN;
# Bar Time & Date
    def bn = BarNumber();
    def currentBar = HighestAll(if !IsNaN(vHigh) then bn else nan);
#    def Today = GetDay() ==GetLastDay();
#    def time = GetTime();
#    def GlobeX = GetTime() < RegularTradingStart(GetYYYYMMDD());
    # def globeX_v2 = if time crosses below RegularTradingEnd(GetYYYYMMDD()) then bn else GlobeX[1];
#    def RTS  = RegularTradingStart(GetYYYYMMDD());
#    def RTE  = RegularTradingEnd(GetYYYYMMDD());
#    def RTH = GetTime() > RegularTradingStart(GetYYYYMMDD());
#    def RTH_v2 = if time crosses above RegularTradingStart(GetYYYYMMDD()) then bn else RTH[1];

# bars that start and end the sessions  #(borrowed from nube)
#    def rthStartBar    = CompoundValue(1,
#                         if   !IsNaN(vClose)
#                         &&   time crosses above RegularTradingStart(GetYYYYMMDD())
#                         then bn
#                         else rthStartBar[1], 0);
#    def rthEndBar      = CompoundValue(1,
#                         if   !IsNaN(vClose)
#                         &&   time crosses above RegularTradingEnd(GetYYYYMMDD())
#                         then bn
#                         else rthEndBar[1], 1);
#    def globexStartBar = CompoundValue(1,
#                         if   !IsNaN(vClose)
#                         &&   time crosses below RegularTradingEnd(GetYYYYMMDD())
#                         then bn
#                         else globexStartBar[1], 1);
#    def rthSession = if   bn crosses above rthStartBar #+ barsExtendedBeyondSession
#                     then 1
#                     else if   bn crosses above rthEndBar #+ barsExtendedBeyondSession
#                          then 0
#                     else rthSession[1];

# Bubble Locations
    def x_AxisLastExpansionBar = BarNumber() == HighestAll(BarNumber());  #corrected 11.12.2018 (JQ)
        # syntax: addChartBubble(x_AxisLastExpansionBar, y-axis coordinate," text", Color.LIME); #verified 12.25.2018 (JQ)

def PH;
   def PL;
   def hh = fold i = 1 to n + 1
            with p = 1
            while p
            do vHigh > getValue(vHigh, -i);
       PH = if (bn > n and
                vHigh == highest(vHigh, n) and
                hh)
            then vHigh
            else double.NaN;
   def ll = fold j = 1 to n + 1
            with q = 1
            while q
            do vLow < getValue(low, -j);
       PL = if (bn > n and
                vLow == lowest(vLow, n) and
                ll)
            then vLow
            else double.NaN;
   def PHBar = if !isNaN(PH)
               then bn
               else PHBar[1];
   def PLBar = if !isNaN(PL)
               then bn
               else PLBar[1];
   def PHL = if !isNaN(PH)
             then PH
             else PHL[1];
   def priorPHBar = if PHL != PHL[1]
                    then PHBar[1]
                    else priorPHBar[1];
   def PLL = if !isNaN(PL)
             then PL
             else PLL[1];
   def priorPLBar = if PLL != PLL[1]
                    then PLBar[1]
                    else priorPLBar[1];
   def HighPivots = bn >= highestAll(priorPHBar);
   def LowPivots = bn >= highestAll(priorPLBar);
   def FirstRpoint = if HighPivots
                     then bn - PHBar
                     else 0;
   def PriorRpoint = if HighPivots
                     then bn - PriorPHBar
                     else 0;
   def RSlope = (getvalue(PH, FirstRpoint) - getvalue(PH, PriorRpoint))
                       / (PHBar - PriorPHBar);
   def FirstSpoint = if LowPivots
                     then bn - PLBar
                     else 0;
   def PriorSpoint = if LowPivots
                     then bn - PriorPLBar
                     else 0;
   def SSlope = (getvalue(PL, FirstSpoint) - getvalue(PL, PriorSpoint))
                   / (PLBar - PriorPLBar);
   def RExtend = if bn == highestall(PHBar)
                 then 1
                 else RExtend[1];
   def SExtend = if bn == highestall(PLBar)
                 then 1
                 else SExtend[1];

  plot pivotHigh = if HighPivots
                   then PH
                   else double.NaN;
       pivotHigh.SetDefaultColor(GetColor(1));
       pivotHigh.setPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
       pivotHigh.setHiding(!showValues);

  plot pivotHighLine = if PHL > 0 and
                          HighPivots
                       then PHL
                       else double.NaN;
       pivotHighLine.SetPaintingStrategy(PaintingStrategy.DASHES);  # Mobius original was DASHES
       pivotHighLine.setDefaultColor(color.uptick);    #JQ 7.8.2018 added
       pivotHighLine.setHiding(!showLines);

  plot RLine = pivotHigh;
       RLine.enableApproximation();
       RLine.SetDefaultColor(Color.LIGHT_GRAY);
       RLine.SetStyle(Curve.Short_DASH);

# Added code to limit resistance estension line (JQ 03.04.2019)
  def calc_ResistanceExtension = if RExtend
                    then (bn - PHBar) * RSlope + PHL
                    else double.NaN;
  plot line_ResistanceExtension = if bn <= (Currentbar + ExtensionLengthBars)
                                   and calc_ResistanceExtension[1] >=  (lowestall(vLow) * (1-(lowerExtensionPercentLimit/100)))
                                   and calc_ResistanceExtension[1] <= (Highestall(vHigh) * (1 + (upperExtensionPercentLimit/100)))
                               then calc_ResistanceExtension else double.nan;
       line_ResistanceExtension.SetStyle(Curve.Short_DASH);
       line_ResistanceExtension.SetDefaultColor(color.LIGHT_GRAY); #was 7
       line_ResistanceExtension.setLineWeight(1);

# Low Plots
  plot pivotLow = if LowPivots
                  then PL
                  else double.NaN;
       pivotLow.setDefaultColor(GetColor(4));
       pivotLow.setPaintingStrategy(PaintingStrategy.VALUES_BELOW);
       pivotLow.setHiding(!showValues);

  plot pivotLowLine = if PLL > 0 and
                         LowPivots
                      then PLL
                      else double.NaN;
       pivotLowLine.SetPaintingStrategy(PaintingStrategy.DASHES);  # Mobius original was DASHES
       pivotLowLine.setDefaultColor(color.DOWNTICK);#  #  JQ 7.8.2018 added
       pivotLowLine.setHiding(!showLines);

  plot SupportLine = pivotLow;
       SupportLine.enableApproximation();
       SupportLine.SetDefaultColor(color.LIGHT_GRAY);
       SUpportLine.SetStyle(Curve.Short_DASH);

# Added code to limit support estension line (JQ 03.04.2019)
  def calc_SupportExtension = if SExtend
                          then (bn - PLBar) * SSlope + PLL
                          else double.NaN;
  plot line_SupportExtension = if bn <= (Currentbar + ExtensionLengthBars)
                                   and calc_SupportExtension[1] >= (lowestall(vLow) * (1-(lowerExtensionPercentLimit/100)))
                                   and calc_SupportExtension[1] <= (Highestall(vHigh) * (1 + (upperExtensionPercentLimit/100)))
                               then calc_supportExtension else double.nan;
       line_SupportExtension.SetDefaultColor(color.LIGHT_GRAY); #was 7
       line_SupportExtension.SetStyle(Curve.Short_DASH);
       line_SupportExtension.setLineWeight(1);

  plot BarNumbersBelow = bn;
       BarNumbersBelow.SetDefaultColor(GetColor(0));
       BarNumbersBelow.setHiding(!showBarNumbers);
       BarNumbersBelow.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);

  plot PivotDot = if !isNaN(pivotHigh)
                  then pivotHigh
                  else if !isNaN(pivotLow)
                  then pivotLow
                  else double.NaN;
       pivotDot.SetDefaultColor(GetColor(7));
       pivotDot.SetPaintingStrategy(PaintingStrategy.POINTS);
       pivotDot.SetLineWeight(3);
##



# End Code
@guacamole Looks great man! Will try this out. Do you know if this repaints?
 
@MerryDay Thank you. Any idea what this latest code from Mobius that i found in TOS OneNote is doing compared to @BenTen https://usethinkscript.com/threads/supertrend-indicator-by-mobius-for-thinkorswim.7/. Which one do you use and what is recommended please

Code:
# Mobius

# SuperTrend 

# Chat Room Request

# V03.10.2015

# Written as Strategy: Added alerts and label for cycle counts. 

# Altered default settings for values that made more sense on Intraday Futures. Added Color and ColorBars.

#Hint:Supertrend Indicator: shows trend direction and gives buy or sell signals according to that. It is based on a combination of the average price rate in the current period along with a volatility indicator. The ATR indicator is most commonly used as volatility indicator. The values are calculated as follows:

# Up = (HIGH + LOW) / 2 + Multiplier * ATR

# Down = (HIGH + LOW) / 2 – Multiplier * ATR

# When the change of trend occurs, the indicator flips

 

# For RP: Add AR trend, Aberrant Vol, R State, PTR

 

input AtrMult = .70;

input nATR = 4;

input AvgType = AverageType.HULL;

input PaintBars = no;

input BubbleOn = yes;

input ShowLabel = yes;

input AlertOn = no;

input PlotLine = yes;

 

def h = high;

def l = low;

def c = close;

def v = volume;

def bar = barNumber();

def EOD = if SecondsTillTime(1545) == 0 and

             SecondsFromTime(1545) == 0

          then 1

          else 0;

def NotActive = if SecondsFromTime(1545) > 0

                then 1

                else 0;

def ATR = MovingAverage(AvgType, TrueRange(h, c, l), nATR);

def UP = HL2 + (AtrMult * ATR);

def DN = HL2 + (-AtrMult * ATR);

def ST = if c < ST[1] 

         then Round(UP / tickSize(), 0) * tickSize()

         else Round(DN / tickSize(), 0) * tickSize();

plot SuperTrend = ST;

SuperTrend.SetHiding(!PlotLine);

SuperTrend.AssignValueColor(if c < ST then Color.RED else Color.GREEN);

SuperTrend.SetPaintingStrategy(PaintingStrategy.Line);

AssignPriceColor(if PaintBars and c < ST 

                 then Color.RED 

                 else if PaintBars and c > ST 

                      then Color.GREEN 

                      else Color.CURRENT);

plot ST_point = if isNaN(close[-1])

                then ST

                else double.nan;

ST_point.SetStyle(Curve.Points);

ST_point.SetLineWeight(3);

ST_point.SetDefaultColor(Color.Yellow);

plot ST_value = if isNaN(close[-1])

                then ST_point

                else double.nan;

ST_value.SetPaintingStrategy(PaintingStrategy.Values_Below);

ST_value.SetDefaultColor(color.white);

AddChartBubble(BubbleOn and c crosses below ST, l[1], l[1], Color.light_GRAY);

AddChartBubble(BubbleOn and c crosses above ST, h[1], h[1], Color.light_GRAY, no);

Alert(AlertOn and c crosses below ST, "c " + c, Alert.BAR, Sound.Chimes);

Alert(AlertOn and c crosses above ST, "c" + c, Alert.Bar, Sound.Ring);

def upBars = if c < ST

             then upBars[1] + 1

             else upBars[1];

def upCycles = if c < ST and c[1] > ST[1]

               then upCycles[1] + 1

               else upCycles[1];

def dnBars = if c > ST

             then dnBars[1] + 1

             else dnBars[1];

def dnCycles = if c > ST and c[1] < ST[1]

               then dnCycles[1] + 1

               else dnCycles[1];

def upCycleCount = upBars / upCycles;

def dnCycleCount = dnBars / dnCycles;

def thisCycle = if c < ST and c[1] > ST[1]

                then 1

                else if c < ST

                then thisCycle[1] + 1

                else if c > ST and c[1] < ST[1]

                     then 1

                     else if c > ST

                          then thisCycle[1] + 1

                          else thisCycle[1];

def Volup = (fold i = 0 to thisCycle

             do if i > 0

                then VolUp[1] + v

                else Volup[1]) / thisCycle;

AddLabel(ShowLabel, "Up Bars = " + upBars + "; " +

                  "  Up Cycles = " + upCycles + "; " +

                  "  Dn Bars = " + dnBars + "; " +

                  "  Dn Cycles = " + dnCycles + "; " +

                  "  Avg Up Cycle Count = " + Round(upCycleCount, 0) + 

                  "  Avg Dn Cycle Count = " + Round(dnCycleCount, 0) +

                  "  This Cycle = " + thisCycle, (if c < ST 

                 then Color.RED else Color.GREEN ));   #.... This portion of code modofies by jhf

 

# End Code SuperTrend
 
@sunnybabu It is the same script as the one posted at the beginning of this thread with an addition of a label.
The label is a cycle counter. I believe it is counting the number of candles in the historical and current trends. These are interesting statistics. For a swing trader knowing whether the total number of trend cycles are bullish or not, the average length of most of the trends for this equity, etc.. could potentially be useful. And identifying strong long-term trending equities on higher aggregations (weekly/monthly) is key to many of the strategies currently used by retail investors.

PS: don't you just love reading through TOS OneNote? The single greatest resources for TOS: this forum by @BenTen and JohnnyQuotron (JQ) TOS Onenote. Unbelievable that so much work is shared so unselfishly
 
Status
Not open for further replies.

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
314 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

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

Frequently Asked Questions

What is useThinkScript?

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

How do I get started?

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

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

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