I found this code in the TASC articles in the member section. I was trying to
add some code to be able to run an explore to possible divergences. When I plot
the indicator it seems to be correct but in the columns both conditions show
true. It is a simple code mistake but at the moment it escapes me why. Can
anyone point out the obvious to me?
Thanks
DM
/*TWO-POINT PROBLEM OF THE RATE OF CHANGE
In the "Two-point problem of the Rate Of Change" article Martti Luoma AND Jussi
Nikkinen
present the modification of classic ROC indicator that can be constructed two
ways in AmiBroker.
First way does NOT require writing any single line of code. You can construct
ROCadj AND other
indicators using AmiBroker's powerful drag AND drop technology. To create
ROCadj, select Chart tab,
go to Indicators folder, double click on ROC - Rate Of Change - this will
create new chart pane with ROC.
Then go to Averages folder, click AND drag EMA - Exponential Moving Average
onto ROC chart.
Your indicator is ready. Now simply adjust ROC period to 1 AND EMA smoothing
period to 21 using
Parameters window. Second way is to use the formula presented in Listing 1.
Just type it into
Formula Editor AND press Insert Chart button.
*/
periods = Param("Periods", 21, 2, 200, 1 );
ROCadj = periods * EMA( ROC( C, 1 ), periods );
/*Added Divergence to original formula*/
RocSlope=LinRegSlope(ROC(C,periods),periods);
MARocSlope=LinRegSlope(ROCadj,periods);
PosDiv=MARocSlope>=RocSlope;
NegDiv=MARocSlope<RocSlope;
//Plots
Plot( ROCadj, "ROCadj "+periods, colorRed, styleThick );
// the line below adds standard ROC overlay
Plot( ROC( C, periods ), "ROC "+periods, colorBlue );
Plot(PosDiv,"Positive",colorLime,styleOwnScale);
Plot(NegDiv,"Positive",colorRed,styleOwnScale);
IIf(PosDiv>0,AddTextColumn("Positive","Positive Divergence",1.2,colorLime),0);
IIf(NegDiv>0,AddTextColumn("Negative","Negative Divergence",1.2,colorRed),0);
Filter=1;