I've a stop and reverse study and would like to write it into efs.
It's similar to Parabolic SAR stop and reverse in nature but ulitizing a simple ATR trailing stop; 2.5 multiples of 5 ATR below the high, then when tripped by price it reverses and becomes the short stop above the lows.
Can anyone help? Point me in the right direction?
Rgds, James
It's similar to Parabolic SAR stop and reverse in nature but ulitizing a simple ATR trailing stop; 2.5 multiples of 5 ATR below the high, then when tripped by price it reverses and becomes the short stop above the lows.
Can anyone help? Point me in the right direction?
Rgds, James
PHP Code:
function init()
{
setTitle("Trailing Stop 1");
setSeriesColour(0, Colour.Yellow);
setSeriesLineStyle(0, Pen.Solid);
setRange(Range.Parent);
}
function getGraph(share, data)
{
var trail = new Array();
var at = 5; //ATR periods
var mult = 2.5; //ATR multiplier (smaller number = tighter stop)
var a_ma = new MA(at, MA.Simple);
var tr = new Array();
var tra = new Array();
var upper, lower, hi, lo;
var test = new Array();
trail[0] = data[0].close;
for (var i=1; i<data.length; i++)
{
hi = Math.max(data[i].high,data[i-1].close);
lo = Math.min(data[i].low,data[i-1].close);
tr[i] = hi - lo;
tra[i] = a_ma.getNext(tr[i]);
upper = data[i].low + mult*tra[i];
lower = data[i].high - mult*tra[i];
test[i] = lower;
if (data[i].high > trail[i-1] && data[i-1].high < trail[i-2]) trail[i] = lower;
else if (trail[i-1] > data[i].low && trail[i-2] < data[i-1].low) trail[i] = upper;
else if (data[i].low < trail[i-1]) trail[i] = Math.min(trail[i-1],upper);
else if (data[i].high > trail[i-1]) trail[i] = Math.max(trail[i-1],lower);
else trail[i] = trail[i-1];
}
return trail;//trail;
}
Comment