The Super Trend Indicator(Python)

Back

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)

 

Update Backtest








 
0

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.


Hi, please ignore the self.test in Update method of SuperTrend, it is for debugging only

2

You could try searching the forums for an implementation. I think someone has already tried using ATR trailing stop in their code here. 

0

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.

 

0

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!

0


Hi
Anyone implemented supertrend with multiple symbols using Universe selection ?
regards,
M.Moudassar

0

Update Backtest





0

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.


Loading...

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!