There's a function called BarsSince. Hope this helps JOE L. // To demonstrate use of BarsSince and SelectedValue..
SignalArray = Cross(MA(C,10),MA(C,20)); if( SelectedValue(BarsSince(SignalArray)< 10)); { // your work a = 30; } A = SelectedValue(BarsSince(SignalArray)); Plot(C,"Close",colorBlack,styleThick); Plot(MA(C,20),"20MA",colorBlue,styleLine); Plot(MA(C,10),"10MA",colorGreen,styleLine); Title = "Crossing Point = " + WriteVal(Signalarray,8.3) + " Bars Since Crossing Point =" + WriteVal(A); BARSSINCE - bars since Trading system toolbox SYNTAX BarsSince( ARRAY ) RETURNS ARRAY FUNCTION Calculates the number of bars (time periods) that have passed since ARRAY was true (or 1) EXAMPLE barssince( macd() < 0 ) SEE ALSO ----- Original Message ----- From: itmwh To: amibroker@yahoogroups.com Sent: Sunday, May 20, 2007 5:20 AM Subject: [amibroker] How to express some conditin occurred in the last ten bars How to express in AFL that there is at least one occurance of crossing of ma1 and ma2 in the last ten bars ? thanks a lot