Supertrend Indicator by Mobius for ThinkorSwim

BenTen

BenTen

Administrative
Staff
VIP
Please post the whole script. Is this based on the Supertrend indicator?
 
StockT8er

StockT8er

Member
VIP
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 = yes;
input BubbleOn = no;
input ShowLabel = no;
input AlertOn = no;
input PlotLine = no;

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.yellow);
AddChartBubble(BubbleOn and c crosses below ST, l[1], l[1], Color.DARK_GRAY);
AddChartBubble(BubbleOn and c crosses above ST, h[1], h[1], Color.DARK_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, Color.WHITE);

# End Code SuperTrend
 
StockT8er

StockT8er

Member
VIP
def Diff_Condition = (if (Diff > 0) then if Average(Diff > Diff[1]) then 1 else 2 else if Average(Diff < Diff[1]) then 3 else 4);

AddLabel(Diff_Condition, if Diff_Condition == 2 or Diff_Condition == 3 then "* * S E L L _ A L E R T * * " else "* * * B U Y _ A L E R T * * *", if Diff_Condition == 4 then Color.GREEN else if Diff_Condition == 1 then Color.DARK_GREEN else if Diff_Condition == 2 then Color.RED else if Diff_Condition == 3 then Color.DARK_RED else Color.BLACK);
 
BenTen

BenTen

Administrative
Staff
VIP
@StockT8er Just to clarify, are you trying to add arrows or bubbles to the signals?
 
StockT8er

StockT8er

Member
VIP
OK I got it to place the # below every bar. How do I change that to just the current bar and to text
 
StockT8er

StockT8er

Member
VIP
def G = if Diff_Condition == 1 then 1 else Double.NaN;
def DG = if Diff_Condition == 2 then 2 else Double.NaN;
def R = if Diff_Condition == 3 then 3 else Double.NaN;
def DR = if Diff_Condition == 4 then 4 else Double.NaN;

plot G_Value = G;
G_Value.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
G_Value.SetDefaultColor(Color.YELLOW);

plot DG_Value = DG;
DG_Value.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
DG_Value.SetDefaultColor(Color.YELLOW);

plot R_Value = R;
R_Value.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
R_Value.SetDefaultColor(Color.YELLOW);

plot DR_Value = DR;
DR_Value.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
DR_Value.SetDefaultColor(Color.YELLOW);

This will Plot the # Above and Below all Bars. I want to change it to text and then only on the current bar or last bar
 
T

T-Dub

New member
Hello !
I'm new here, I was wondering how to implement the SuperTrend scanner for TOS, I was able to get the indicator to work but not the scanner. I can't find anywhere to enter code for scanners.
Any help would be greatly appreciated !
 
BenTen

BenTen

Administrative
Staff
VIP
@Mneef What do you mean "the last version"? Did you watch the video above? Did you use the script I linked?
 
F

fredfunk2020

New member
@BenTen - I have a question for you. Since the TOS issues of the past couple days I was trying to set a backup on my NinjaTrader for this indicator. Is that possible? And if so, how?
 
BenTen

BenTen

Administrative
Staff
VIP
@fredfunk2020 I'm not familiar with the NinjaTrader platform so I'm not sure.
 
F

fredfunk2020

New member
Thanks, appreciate it. I really like this indicator and haven't been able to use it the past 2 days as my TOS is f'd up. Do you happen to have any background information on this indicator?
 
StockT8er

StockT8er

Member
VIP
TOS's issues would be worth it if they add auto trading to there platform, yeah right not going to happen
 
B

Balaji

New member
@BenTen . Super trend indicator works fine but then I am not able to get alerts as you mentioned above.

Screenshot 1 :

I want the system should alert me when the price direction changes of Buy/Sell as shown below


2. Alert Screenshot : Even I am able to see an alert on the Edit studies and strategies



The alert is displayed as shown in the above picture. However it never make a chime/bell sound when the price direction changes.
 
Last edited:
B

Balaji

New member
The alert did not generate any sound even after I added at the bottom of the script. Could you please check and let me know.
 

Similar threads

Top