Supertrend Indicator by Mobius for ThinkorSwim

T

tutianlong

New member
VIP
BenTen

BenTen

Administrative
Staff
VIP
@tutianlong Not possible in the mobile app. That’s why we have it as a lower study.
 
T

tutianlong

New member
VIP
@tutianlong Not possible in the mobile app. That’s why we have it as a lower study.
then is it possible i plot rmi in the same study n it only spike if the candle goes below/above the supertrend line n rmi hits oversold/overbought region ? just trying to see how to weave 2 indicators together
 
BenTen

BenTen

Administrative
Staff
VIP
@tutianlong What's RMI? I don't have any experience with tweaking indicators so they can work with the mobile app.
 
T

tutianlong

New member
VIP
relative momentum index. i tweaked a version of it so i can set the ob/os levels as the default rmi indicator do not allow you change it. it worked just fine on both mobile n desktop version.
 
U

Utajiri

New member
Hey @BenTen or anyone in the house..... I need help with a pretty simple script? I want to plot the previous OHLC price that draws a line across the chart (end to end) - with multiple time aggregation periods. Such that I can overlay (for instance) the 4hr previous closing price (drawn as a line) and overlay it on the 3min time frame for instance. Also want to be able to turn on/off which of the price types (of the previous OHLC) I want to use at any time. I appreciate the help
 
BenTen

BenTen

Administrative
Staff
VIP
@Utajiri Is this related to the SuperTrend indicator? If not, please create a new request in the Questions forum.
 
T

tutianlong

New member
VIP
@BenTen you are right. I am watching it now for the /ES open and you must wait for the candle to close for confirmation of the entry/exit (bubble).

During the time interval that you are using (i.e 5 min) the bubble will show at times, but can revert depending on the price. So, one will know whether to enter/exit only when the candle closes.


I must say, this thing is accurate! Up 3 points since entry in /ES right now. Brilliant indicator, seriously. Best one I have found yet.
hi corello, what other indicators do ubuse ?
 
M

mh786

New member
@tutianlong Not possible in the mobile app. That’s why we have it as a lower study.
Hey @BenTen
I think that I have managed to create the study on top of the chart for the mobile app. Could you please have a look here?

Code:
# Mobius
# SuperTrend
# Chat Room Request
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 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);
 
BenTen

BenTen

Administrative
Staff
VIP
@mh786 Thank you for that. Just tested it :) Looks good on the ToS app. Also made a note in the original thread ;)
 
J

jrob0124

New member
@BenTen I am having trouble with the scanner. I have read this thread and using the code from the first post. I am getting false positives or signals for ST that has been running for a few days. What I am looking for is a scan that will provide a new ST bullish signal. Below is what I am using for a scan.

Stock Hacker filters

Here is the study code.

Code:
# SuperTrend Scan
# Mobius
# V01.10.2015
# Comment out (#) the direction NOT to use for a scan

input AtrMult = .70;
input nATR = 4;
input AvgType = AverageType.HULL;
def h = high;
def l = low;
def c = close;
def v = volume;
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 SuperTrendUP = if ST crosses below close then 1 else 0;
#plot SuperTrendDN = if ST crosses above close then 1 else 0;
# End Code SuperTrend
This returns 57 results, with around half that are false signals. Here are a few examples:

False signal with ST showing existing Bearish Trend

Existing Bullish Trend

Please let me know if I am doing something wrong to get these false signals. Thank you for your time!
 
H

HighBredCloud

Active member
VIP
@BenTen I am having trouble with the scanner. I have read this thread and using the code from the first post. I am getting false positives or signals for ST that has been running for a few days. What I am looking for is a scan that will provide a new ST bullish signal. Below is what I am using for a scan.

Stock Hacker filters

Here is the study code.

Code:
# SuperTrend Scan
# Mobius
# V01.10.2015
# Comment out (#) the direction NOT to use for a scan

input AtrMult = .70;
input nATR = 4;
input AvgType = AverageType.HULL;
def h = high;
def l = low;
def c = close;
def v = volume;
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 SuperTrendUP = if ST crosses below close then 1 else 0;
#plot SuperTrendDN = if ST crosses above close then 1 else 0;
# End Code SuperTrend
This returns 57 results, with around half that are false signals. Here are a few examples:

False signal with ST showing existing Bearish Trend

Existing Bullish Trend

Please let me know if I am doing something wrong to get these false signals. Thank you for your time!
My suggestion is that you search for stocks using Average Daily Volume...not regular Volume as your setting now with the volume will not show results UNTIL 1,000,000 volume is hit for the given day...By then it could be way too late to even make any moves.
 
J

jrob0124

New member
My suggestion is that you search for stocks using Average Daily Volume...not regular Volume as your setting now with the volume will not show results UNTIL 1,000,000 volume is hit for the given day...By then it could be way too late to even make any moves.
Thank you @HighBredCloud for the suggestion.

Is this the code you would use to accomplish that?

Code:
Average("data" = VOLUME, "length" = 10) is greater than 1000000
Also, I don't think that explains the false positives I am receiving with the scan. Any thoughts on that?
 
H

HighBredCloud

Active member
VIP
Thank you @HighBredCloud for the suggestion.

Is this the code you would use to accomplish that?

Code:
Average("data" = VOLUME, "length" = 10) is greater than 1000000
Also, I don't think that explains the false positives I am receiving with the scan. Any thoughts on that?
Add a study filter in the upper right...and its under volume. I normally set to greater than 500K
 
Zillion

Zillion

New member
@corello Here is the code for that. It comes in 2 parts.

Step 1: Create a new Strategy (not a Study) > Copy and Paste the original code in the first page into it.

Step 2: Add the following code to the end of the script:

Code:
# The following code is for backtesting
def SuperTrendUP = if ST crosses below close then 1 else 0;
def SuperTrendDN = if ST crosses above close then 1 else 0;
Step 3a: If you want to test out bullish strategy then add this code after the code from Step 2:

Code:
# Bullish Orders
AddOrder(OrderType.BUY_TO_OPEN, condition = SuperTrendUp, price = close,100, tickcolor = Color.GREEN, arrowcolor = Color.GREEN, name = "BUY");
AddOrder(OrderType.SELL_TO_CLOSE, condition = SuperTrendDN, price = open,100, tickcolor = Color.RED, arrowcolor = Color.RED, name = "SELL");
Step 3b: If you want to test out bearish strategy then add this code after the code from Step 2:

Code:
# Bearish Orders
AddOrder(OrderType.SELL_TO_OPEN, condition = SuperTrendDN, price = open,100, tickcolor = Color.RED, arrowcolor = Color.RED, name = "SELL");
AddOrder(OrderType.BUY_TO_CLOSE, condition = SuperTrendUp, price = close,100, tickcolor = Color.GREEN, arrowcolor = Color.GREEN, name = "BUY");
Do not place both codes from 3a and 3b into the same script.

Any reason as to why both can not be used? Or would there be a way to add a mode for bullish or bearish? (I attempted but failed using the following)
def bull;
def bear;
switch (mode) {
case "Bull":
buy =SuperTrendUp;
sell =SuperTrendDN ;
case "Bear":
buy = SuperTrendDN;
sell = SuperTrendUp;
}
;

AddOrder(OrderType.SELL_TO_OPEN, condition = buy, price = open,1, tickcolor = Color.RED, arrowcolor = Color.RED, name = "SELL");
AddOrder(OrderType.BUY_TO_CLOSE, condition = sell, price = close,1, tickcolor = Color.GREEN, arrowcolor = Color.GREEN, name = "BUY");

I think I can see the issue but am confused as to why it allows you to have both bullish and bearish orders even if it's only displaying (or sems like it is only displaying )1 of the 2 .....I hope that makes sense 😬 Thanks!!
 
B

Bhavesh

New member
@Jenny Here is the code for that. Just add it to the bottom of your Supertrend script.

Code:
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);
Is there a way to get mobile alert from these code? Thanks in advance.
 
Billions

Billions

Member
2019 Donor
Warehouse
@BenTen Do we have this one:
Code:
//@version=4
study("Supertrend", overlay = true)

Periods = input(title="ATR Period", type=input.integer, defval=10)
Multiplier = input(title="ATR Multiplier", type=input.float, step=0.1, defval=3.0)
changeATR= input(title="Change ATR Calculation Method ?", type=input.bool, defval=true)
showsignals = input(title="Show Buy/Sell Signals ?", type=input.bool, defval=true)
highlighting = input(title="Highlighter On/Off ?", type=input.bool, defval=true)
atr2 = sma(tr, Periods)
atr= changeATR ? atr(Periods) : atr2
up=hl2-(Multiplier*atr)
up1 = nz(up[1],up)
up := close[1] > up1 ? max(up,up1) : up
dn=hl2+(Multiplier*atr)
dn1 = nz(dn[1], dn)
dn := close[1] < dn1 ? min(dn, dn1) : dn
trend = 1
trend := nz(trend[1], trend)
trend := trend == -1 and close > dn1 ? 1 : trend == 1 and close < up1 ? -1 : trend
upPlot = plot(trend == 1 ? up : na, title="Up Trend", style=plot.style_linebr, linewidth=2, color=color.green)
buySignal = trend == 1 and trend[1] == -1
plotshape(buySignal ? up : na, title="UpTrend Begins", location=location.absolute, style=shape.circle, size=size.tiny, color=color.green, transp=0)
plotshape(buySignal and showsignals ? up : na, title="Buy", text="Buy", location=location.absolute, style=shape.labelup, size=size.tiny, color=color.green, textcolor=color.white, transp=0)
dnPlot = plot(trend == 1 ? na : dn, title="Down Trend", style=plot.style_linebr, linewidth=2, color=color.red)
sellSignal = trend == -1 and trend[1] == 1
plotshape(sellSignal ? dn : na, title="DownTrend Begins", location=location.absolute, style=shape.circle, size=size.tiny, color=color.red, transp=0)
plotshape(sellSignal and showsignals ? dn : na, title="Sell", text="Sell", location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.red, textcolor=color.white, transp=0)
mPlot = plot(ohlc4, title="", style=plot.style_circles, linewidth=0)
longFillColor = highlighting ? (trend == 1 ? color.green : color.white) : color.white
shortFillColor = highlighting ? (trend == -1 ? color.red : color.white) : color.white
fill(mPlot, upPlot, title="UpTrend Highligter", color=longFillColor)
fill(mPlot, dnPlot, title="DownTrend Highligter", color=shortFillColor)
alertcondition(buySignal, title="SuperTrend Buy", message="SuperTrend Buy!")
alertcondition(sellSignal, title="SuperTrend Sell", message="SuperTrend Sell!")
changeCond = trend != trend[1]
alertcondition(changeCond, title="SuperTrend Direction Change", message="SuperTrend has changed direction!")
 
Last edited by a moderator:

Top