I've pasted a section of script from a "stop and reverse" which I'd like to use the hl2 point as datum for the ATR adjustment.
I've commented the bits I've added i.e. eval the hl2 the getValue below. It works, but is it the right way to do it?
I've commented the bits I've added i.e. eval the hl2 the getValue below. It works, but is it the right way to do it?
PHP Code:
//called on each new bar
if ( getBarState() == BARSTATE_NEWBAR ) {
//save the prior ATR value
nATR_1 = nATR;
//calculate the Average True Range via Wilder's formula
nV1 = Math.abs( high(-1)-low(-1) );
nV2 = Math.abs( close(-2)-high(-1) );
nV3 = Math.abs( close(-2)-low(-1) );
source = eval(hl2()); //added eval of source
nTrToday = Math.max( nV1, nV2, nV3 );
nATR = ( ( Period-1 ) * nATR_1 + nTrToday ) / Period;
//determine the ratchet, if any
nRatchet = 1.0 - ( nBarsInTrade * nRatchetInc );
//adjust long stop
if ( nStatus == 1 ) {
nVal = ATRs * nATR;
nTmp = source.getValue(-1) - ( nVal * nRatchet );// using getValue
if (nTmp>nStopPrice) nStopPrice = nTmp;
Comment