Circular Referencing

I have a system where there is a buy signal that depends on the the lowest close since the previous sell and a sell signal that depends on the highest close since the previous buy signal. When I say buy and sell I mean the actual signals after removing the excessive signals.

On paper this is easy however I am not being able to write this in AFL. Can anyone please help me out?

I am attaching an example of what I mean - all blue arrows are signals that should have been buys but were not. This is just an example, I would just to know how AFL handles these cases.



Buy = C>MA(C,20) AND (C>=0.9*HHV(C,40) OR C>=1.2*LLV(C,BarsSince(Sell==1)));
Sell = Cross(HHV(C,40)*0.9,C);


// this will show the missed signals

Y=Flip(Sell,Buy) AND Cross(C,1.2*LLV(C,BarsSince(Sell))) AND C>MA(C,20);


PlotShapes(Sell*shapeDownArrow,colorRed ,0,High );

Already explained:

The way I understand the issue is because the entire array is processed at once so the buy signal that comes first in the code doesn’t take into account the sell data that came after it in the code which is why this section is avoided completely:


I'm sorry but I still can't figure out a way to make this work. Can you please help?

As written in topic I referenced, exact route to implement circular references depends on details of what you want to achieve. Typically you either use built in functions that implement circular references (again see the post I linked) or you use loop. In your particular case I would use a loop as explained in the Knowledge Base as it contains exactly the code dealing with buy/sell signals.

1 Like