Join useThinkScript to post your question to a community of 21,000+ developers and traders.
Unfortunately, I don't think you can reference the code from, or include it in, a Conditional Order... You can try, but don't get your hopes up... You won't get errors most of the time from Conditional Orders that TOS can't handle, just orders that immediately Buy and then immediately Sell after saving the OCO order... Been there, done that...!!!I want to try this Supertrend Indicator, to scalping tool, as soon as trend changes, and post its number, then automatically buy and sell for you with OCO bracket on it. Is there a way to do it.
@BenTen or whoever. Can you please help with this scanner? I've watched the video and tried all different settings, but I can never yield a result. Is there something with the code? Any help would be much appreciated.
Hello barbros, I know this has been a while since you were on this thread, but I just wanted to ask if this repaints after the close of the bar?If anyone is interested, I modified this a little to show a label for the selected timeframe. You can add more than one to show different timeframes in the same chart. Make sure the timeframes you select are higher than the chart setting.
Python:# SuperTrend Yahoo Finance Replica - Modified from Modius SuperTrend - MTF Labels Version # Modified Modius ver. by RConner7 # Modified by barbaros for multi time frame label # Works similar to how Yahoo Finance Supertrend works and displays. Holds supertrend value until cross. input agg1 = AggregationPeriod.HOUR; input AtrMult = 1.00; input nATR = 6; input AvgType = AverageType.HULL; def ATR = MovingAverage (AvgType, TrueRange(high(period = agg1), close(period = agg1), low(period = agg1)), nATR); def UP_Band_Basic = HL2(period = agg1) + (AtrMult * ATR); def LW_Band_Basic = HL2(period = agg1) + (-AtrMult * ATR); def UP_Band = if ((UP_Band_Basic < UP_Band[1]) or (close(period = agg1)[1] > UP_Band[1])) then UP_Band_Basic else UP_Band[1]; def LW_Band = if ((LW_Band_Basic > LW_Band[1]) or (close(period = agg1)[1] < LW_Band[1])) then LW_Band_Basic else LW_Band[1]; def ST = if ((ST[1] == UP_Band[1]) and (close(period = agg1) < UP_Band)) then UP_Band else if ((ST[1] == UP_Band[1]) and (close(period = agg1) > Up_Band)) then LW_Band else if ((ST[1] == LW_Band[1]) and (close(period = agg1) > LW_Band)) then LW_Band else if ((ST[1] == LW_Band) and (close(period = agg1) < LW_Band)) then UP_Band else LW_Band; AddLabel(yes, if agg1== aggregationPeriod.MONTH then "M" else if agg1== aggregationPeriod.WEEK then "W" else if agg1== aggregationPeriod.FOUR_DAYS then "4D" else if agg1== aggregationPeriod.THREE_DAYS then "3D" else if agg1== aggregationPeriod.TWO_DAYS then "2D" else if agg1== aggregationPeriod.DAY then "D" else if agg1== aggregationPeriod.FOUR_HOURS then "4H" else if agg1== aggregationPeriod.TWO_HOURS then "2H" else if agg1== aggregationPeriod.HOUR then "1H" else if agg1== aggregationPeriod.THIRTY_MIN then "30m" else if agg1== aggregationPeriod.TWENTY_MIN then "20m" else if agg1== aggregationPeriod.FIFTEEN_MIN then "15m" else if agg1== aggregationPeriod.TEN_MIN then "10m" else if agg1== aggregationPeriod.FIVE_MIN then "5m" else if agg1== aggregationPeriod.FOUR_MIN then "4m" else if agg1== aggregationPeriod.THREE_MIN then "3m" else if agg1== aggregationPeriod.TWO_MIN then "2m" else if agg1== aggregationPeriod.MIN then "1m" else "", if close(period = agg1) < ST then Color.RED else if close(period = agg1) > ST then Color.GREEN else Color.DARK_GRAY); # End Code SuperTrend Yahoo Finance Replica - MTF Labels Version
Hello barbros, I know this has been a while since you were on this thread, but I just wanted to ask if this repaints after the close of the bar?
not really trending...its just market sentiment...So it can be trending...or in a channel...I tried using this technique on SPY and it does seem to be very text book...MACD set to 15 min will help filter out the fake moves that may not end up going anywhere on lower timeframes...Try implementing all of the criteria by using multiple scanners all in ONE scan and trade stocks other that it generates other than
I know the original Super mtf lower study did have those issues, but not really on Afterhours. I was able to pair this study with you and chucks BB study as a strat and had again very positive results, would you be able to check it out and see if this is realistic?I don’t recall since I stopped using this, but since it has multi time frame component, probably repaints.
Also from what I read in other forums the real problem with MTF repainting was due to using the second aggregation in the form of script() code as stated by Mobius and then posted on the forum by @tomsk (not that I know what that means) as I was going through your code, I did not spot any of that, so I'm not sure if this is also a positive sign.I don’t recall since I stopped using this, but since it has multi time frame component, probably repaints.
Bro, I have been using this, Quite helpful. I use the 3min chart to trade. Have yo backtested what nATR works best esp for scalping under $20 stocks. I have tried 1 and 3I've created the popular SuperTrend indicator that works and displays very similar to how the Yahoo Finance SuperTrend works. This was modified from the version that Modius originally created.
Painted bars:
Yahoo Finance version
Code:# SuperTrend Yahoo Finance Replica - Modified from Modius SuperTrend # Modified Modius ver. by RConner7 # Works similar to how Yahoo Finance Supertrend works and displays. Holds supertrend value until cross. input AtrMult = 1.00; input nATR = 6; input AvgType = AverageType.HULL; input PaintBars = yes; 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 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 ArrowDown = Supertrend crosses above close; ArrowDown.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN); ArrowDown.SetDefaultColor(Color.RED); ArrowDown.SetLineWeight(3); plot ArrowUp = Supertrend crosses below close; ArrowUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP); ArrowUp.SetDefaultColor(Color.GREEN); ArrowUp.SetLineWeight(3); # End Code SuperTrend Yahoo Finance Replica
# 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 AtrMult = 1.00;
input nATR = 6;
input AvgType = AverageType.HULL;
input PaintBars = yes;
input ShowBubbles = yes;
input ShowLabels = yes;
input UseEmaCross = yes;
input EMA1 = 10;
input EMA2 = 20;
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;
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.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);
def LongConfirm = (UseEmaCross and close > ST and EMADirection == 1) or (!UseEmaCross and LongTrigger);
def ShortConfirm = (UseEmaCross and close < ST and EMADirection == -1) or (!UseEmaCross and ShortTrigger);
def LongAlert = LongConfirm and LongConfirm[1] != LongConfirm;
def ShortAlert = ShortConfirm and ShortConfirm[1] != ShortConfirm;
AddLabel(ShowLabels, "ST: " + (if close > ST then "Bullish" else if close < ST then "Bearish" else "Neutral"),
if close > ST then Color.GREEN else if close < ST then Color.RED else Color.GRAY);
AddLabel(ShowLabels and UseEmaCross, "EMA: " + (if EMADirection == 1 then "Bullish" else if EMADirection == -1 then "Bearish" else "Neutral"),
if EMADirection == 1 then Color.GREEN else if EMADirection == -1 then Color.RED else Color.GRAY);
AddChartBubble(ShowBubbles and LongAlert, ST, "BUY", Color.GREEN, no);
AddChartBubble(ShowBubbles and ShortAlert, ST, "SELL", Color.RED, yes);
AssignPriceColor(if PaintBars and close < ST and (!UseEmaCross or EMADirection == -1) then Color.RED
else if PaintBars and close > ST and (!UseEmaCross or EMADirection == 1) then Color.GREEN
else if PaintBars then Color.GRAY
else Color.CURRENT);
Alert(LongAlert, "Long", Alert.BAR, Sound.Ding);
Alert(ShortAlert, "Short", Alert.BAR, Sound.Ding);
# End Code SuperTrend Yahoo Finance Replica
https://usethinkscript.com/threads/supertrend-yahoo-finance-type-for-thinkorswim.1998/#post-20153I use this scan for my chart on thinkorswim but when I try to copy and paste it in the scanner it says... Addlabel not allowed in this content. I want the scan to be just like the chart. Any help on getting the below code to work on the scanner would be much much appreciated.
Code:# SuperTrend Yahoo Finance Replica - Modified from Modius SuperTrend # Modified Modius ver. by RConner7 # Modified by Barbaros to replicate look from TradingView version # Modified by Barbaros to add EMA cross for bubbles and alerts # Modified by Barbaros to update bar color painting # v3.3 input AtrMult = 1.00; input nATR = 6; input AvgType = AverageType.HULL; input PaintBars = yes; input ShowBubbles = yes; input ShowLabels = yes; input UseEmaCross = yes; input EMA1 = 10; input EMA2 = 20; 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; 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.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); def LongConfirm = (UseEmaCross and close > ST and EMADirection == 1) or (!UseEmaCross and LongTrigger); def ShortConfirm = (UseEmaCross and close < ST and EMADirection == -1) or (!UseEmaCross and ShortTrigger); def LongAlert = LongConfirm and LongConfirm[1] != LongConfirm; def ShortAlert = ShortConfirm and ShortConfirm[1] != ShortConfirm; AddLabel(ShowLabels, "ST: " + (if close > ST then "Bullish" else if close < ST then "Bearish" else "Neutral"), if close > ST then Color.GREEN else if close < ST then Color.RED else Color.GRAY); AddLabel(ShowLabels and UseEmaCross, "EMA: " + (if EMADirection == 1 then "Bullish" else if EMADirection == -1 then "Bearish" else "Neutral"), if EMADirection == 1 then Color.GREEN else if EMADirection == -1 then Color.RED else Color.GRAY); AddChartBubble(ShowBubbles and LongAlert, ST, "BUY", Color.GREEN, no); AddChartBubble(ShowBubbles and ShortAlert, ST, "SELL", Color.RED, yes); AssignPriceColor(if PaintBars and close < ST and (!UseEmaCross or EMADirection == -1) then Color.RED else if PaintBars and close > ST and (!UseEmaCross or EMADirection == 1) then Color.GREEN else if PaintBars then Color.GRAY else Color.CURRENT); Alert(LongAlert, "Long", Alert.BAR, Sound.Ding); Alert(ShortAlert, "Short", Alert.BAR, Sound.Ding); # End Code SuperTrend Yahoo Finance Replica
I have it saved for my charts and it works great. I also seem to have it saved as an indicator because when I search for it while trying to build a scan, it's there but when I load it, the values are all blank. As value, is true, is false, crosses over, crosses under etc. Do I need to select one or more of those or is it already in the code for a scan? The scanner isn't finding anything but sometimes when it's late, it doesn't work. Thank you
Thread starter | Similar threads | Forum | Replies | Date |
---|---|---|---|---|
S | Smart Supertrend For ThinkOrSwim | Indicators | 13 | |
M | SuperTrend Oscillator [LUX] For ThinkOrSwim | Indicators | 7 | |
B | SuperTrend TradingView Look-A-Like For ThinkOrSwim | Indicators | 64 | |
SuperTrend Of MACD and AVG RSI For ThinkOrSwim | Indicators | 21 | ||
T | SuperTrend CCI ATR Trend for ThinkorSwim | Indicators | 61 |
Start a new thread and receive assistance from our community.
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.
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.