I needed the atr indicator as trailing stop, but I couldnt find super trend in QC. So I tried to build one. And here it is.
Since I am not 100% sure the code is correct, please review the code before you use it. If theres any bugs or super trend already in QC, please let me know.
And the code is based on tradingview super trend in pinescript, and here is the code:
study("abc", overlay=true)
Periods = input(title="ATR Period", type=input.integer, defval=10)
Multiplier = input(title="ATR Multiplier", type=input.float, step=0.1, defval=2.0)
atr = atr(Periods)
atrDown = hl2 - (Multiplier*atr)
atrDown := close[1] > atrDown[1] ? max(atrDown, atrDown[1]) : atrDown
atrUp = hl2 + (Multiplier*atr)
atrUp := close[1] < atrUp[1] ? min(atrUp, atrUp[1]) : atrUp
atrTrend = 0
atrTrend := nz(atrTrend[1], atrTrend)
atrTrend := close > atrUp[1] ? 1 : close < atrDown[1] ? -1 : atrTrend[1]
upPlot = plot(atrTrend == -1 ? atrUp : na, style=plot.style_linebr, linewidth=2, color=color.red)
downPlot = plot(atrTrend == 1 ? atrDown : na, style=plot.style_linebr, linewidth=2, color=color.green)
closePlot = plot(close)
fill(upPlot, closePlot, color=color.red)
fill(downPlot, closePlot, color=color.green)
Tai Man Chan
Hi, please ignore the self.test in Update method of SuperTrend, it is for debugging only
Apollos Hill
You could try searching the forums for an implementation. I think someone has already tried using ATR trailing stop in their code here.
Sergej Gorev
Hey,
I accidentally came across this thread by searching for a SuperTrendIndicator. For the same reason actually - trailing stop.
However, i found a nice description of it with exact formula. And, since I need it as well, i gonna try to build it. I will drop the code here as soon as I am ready.
Sergej Gorev
Hey guys,
I needed consolidation for bigger resolutions, so i came up with this idea. I used consolidators to give me consolidated bars, so i could feed it into the indicator. SuperTrend.Value gives you the price where you can put your stop order.
Since SuperTrendIndicator is kind of a mixture of price action and ATR, it adjusts to price as well as to volatility. Pretty handy for some scenarios.
Anyways. Good Luck. And if you see some mistakes or have better idea, please notify me!
Muhammad Mudassar
Hi
Anyone implemented supertrend with multiple symbols using Universe selection ?
regards,
M.Moudassar
Angus MacDonald
Sergej Gorev have you compared the results of your implementation against what TradingView is generating for SuperTrend ?
Ахмед М. Ибраим
Sergej Gorev Thanks , it works fine
But I when i change the resolution to Hour , or test the ALGO on more than few months
like this
I get an error
would anyone help how to fix it ?
Vladimir
Ахмед М. Ибраим
Try the native QuantConnect SuperTrend indicator.
Vladimir
Tai Man Chan, Apollos Hill , Sergej Gorev, Muhammad Mudassar,Ахмед М. Ибраим,
It is time to try the native QuantConnect SuperTrend indicator.
Shner
Wow glad they finally add it, great addittion. hopefully they will add it here too!
Fred Painchaud
Hi Shner,
It's here.
Fred
Aalap Sharma
Can I use one of these with the Coarse and Fine UniverseSelection?
Derek Melchin
Hi Aalap,
Yes, see Indicator Universes.
Best,
Derek Melchin
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Andres Arizpe
Congrats to Derek and all the Quantconnect team for bringing this indicator to the platform.
I've been doing some testing and its worked flawlessly so I'm excited to put it to work soon.
Keep up the good work :-)
Cheers,
Andres
Tai Man Chan
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!