volatility-based trailing stop

Posted By: webradio

volatility-based trailing stop - 09/21/14 13:29

I am about to port my ATR-based trailing stop from MT4 to Zorro. I do enjoy programming, but I wonder if a similar source code already exists. At least, I coundn't find it on ta-lib.org and tadoc.org, nor in indicators.c. Sometimes this indicator is called Supertrend. It looks familiar to you, for sure:
Posted By: webradio

Re: volatility-based trailing stop - 09/25/14 21:36

I gave it a try
Code:
function run()
{
	set(PLOTNOW);
	PlotDate = 20140810;
	PlotHeight1 = 900;
	
	vars Top = series(2.0*priceHigh()-priceLow());
	vars Btm = series(2.0*priceLow()-priceHigh());
	var width = 3.0*EMA(series(ATR(2)), 10);
	var center = (priceHigh()+priceLow()+priceClose())/3.0;
	if (priceHigh()>Top[1]) {
		Top[0] = center+width;
	} else {
		Top[0] = min(Top[1], center+width);
	}
	if (priceLow()<Btm[1]) {
		Btm[0] = center-width;
	} else {
		Btm[0] = max(Btm[1], center-width);
	}
	
	plot("Top", Top[0],DOT,GREEN);
	plot("Btm", Btm[0],DOT,RED);
}

example from NinjaTrader
this script
this script, diffeent parameters
© 2024 lite-C Forums