There are two parameters:
int emalen; //values e.g. 2-20
double delta; //values e.g. 0-10
The first thing that is done in the AB code is 3 arrays (myema, trail, trailstop) are initialized by being totally filled starting with an EMA of the Low with a lookback length of emalen. The commands are:
//Initialize:
myema=EMA(L, emalen); emastop=myema-delta; trail=emastop;
for( i = emalen+1; i < BarCount-1; i++ )
{
if(myema[i]> myema[i-1])
trail[i]= emastop[i];
if(myema[i]<= myema[i-1])
trail[i]=trail[i-1];
}
protectedoverridevoid OnBarUpdate()
{
if (CurrentBar<emalen+1)
return;
for( int i = emalen+1; i < Count-1; i++ )
{
doublevalue = EMA(Low, emalen)[Count-(Count-i)+1];
myema[i]=value;
emastop[i]= emalow[i]-delta;
trail[i]= emastop[i];
}
for( int i = emalen+1; i < Count-1; i++ )
{
if(myema[i]>myema[i-1])
trail[i]= emastop[i];
if(myema[i]<= myema[i-1])
trail[i]=trail[i-1];
}
}
- Within OnBarUpdate, can I do math over all bars and fill the arrays using lookback lengths, or is OnBarUpdate essentially a loop which loops through the bars? If that’s true do I need the loops to do this?
- Within the second loop for NT8 code, do the [i] and [i-1] from AB need to be changed to [0] and [1] to pick off the ith and ith-1 elements, or is it ok as is?
- If emalen=10, I am not sure when I get the look back EMA for bar 10, whether my EMA(Low, emalen)[Count-(Count-i)+1] function in NT8 is actually getting the 10-period EMA for the 10th bar (the previous 10 bars?

Comment