HPotter

Average True Range Trailing Stops Strategy

Average True Range Trailing Stops Strategy, by Sylvain Vervoort
The related article is copyrighted material from Stocks & Commodities Jun 2009
Rimuovi dagli script preferiti Aggiungi agli script preferiti
////////////////////////////////////////////////////////////
//  Copyright by HPotter v1.0 16/09/2014
// Average True Range Trailing Stops Strategy, by Sylvain Vervoort 
// The related article is copyrighted material from Stocks & Commodities Jun 2009 
////////////////////////////////////////////////////////////
study(title="Average True Range Trailing Stops Strategy, by Sylvain Vervoort", overlay = true)
nATRPeriod = input(5)
nATRMultip = input(3.5)
xATR = atr(nATRPeriod)
nLoss = nATRMultip * xATR
xATRTrailingStop = iff(close > nz(xATRTrailingStop[1], 0) and close[1] > nz(xATRTrailingStop[1], 0), max(nz(xATRTrailingStop[1]), close - nLoss),
                    iff(close < nz(xATRTrailingStop[1], 0) and close[1] < nz(xATRTrailingStop[1], 0), min(nz(xATRTrailingStop[1]), close + nLoss), 
                        iff(close > nz(xATRTrailingStop[1], 0), close - nLoss, close + nLoss)))
pos =	iff(close[1] < nz(xATRTrailingStop[1], 0) and close > nz(xATRTrailingStop[1], 0), 1,
	    iff(close[1] > nz(xATRTrailingStop[1], 0) and close < nz(xATRTrailingStop[1], 0), -1, nz(pos[1], 0))) 
barcolor(pos == -1 ? red: pos == 1 ? green : blue )
plot(xATRTrailingStop, color=red, title="ATR Trailing Stop")

DONATE/TIP

BTC: 3FKWwtaYrf5NHZzaCi1fyAfQj7XSgtyCqe
@HPotter i added the 2 lines you said above 'barcolor' but it doesnt alert when ATR line flips on the other side - what shall i change please? Thanks! :)

alertcondition(pos != pos and pos == 1, title='ENTER LONG', message="ENTER LONG")
alertcondition(pos != pos and pos == -1, title='ENTER SHORT', message="ENTER SHORT")
Rispondi
Hi! Thanks for your work. How could I simulate the strategy to see the performance?
Rispondi
HPotter AlfaCharts
Rispondi
@HPotter, Many thanks
+1 Rispondi
HPotter AlfaCharts
@AlfaCharts, You are welcome
Rispondi
hello how to alert of average true strategy?
Rispondi
HPotter kutibey
@kutibey, You can add this lines before barcolor

alertcondition(pos != pos and pos == 1, title='Signal Buy', message="Buy")
alertcondition(pos != pos and pos == -1, title='Signal Sell', message="Sell")
Rispondi
kutibey HPotter
@HPotter, a very successful strategy does not repaint.thank you very much.
Rispondi
HPotter kutibey
@kutibey, You are welcome
Rispondi
@HPotter, how do i add it? source is locked
Rispondi
Home Screener azioni Screener forex Screener cripto Calendario economico Show Come funziona Caratteristiche Grafico Costi Regolamento Moderatori Soluzioni per broker & siti web Widget Librerie grafiche Libreria grafica leggera Centro di supporto Invita un amico Suggerisci funzionalità Blog & Novità FAQ Wiki Twitter
Profilo Impostazioni profilo Account e fatturazione Invita un amico I miei ticket di supporto Centro di supporto Idee pubblicate Follower Seguiti Messaggi Privati Chat Esci