
Originally Posted by Shrees

Can somebody correct this AFL for TUTTLE SOUP.
What I am missing?
Code:
_SECTION_BEGIN("TurtleSoup");
CONDBUY=barssince(Ref(LLV(L,20),1) >3 );
CONDSELL=barssince(Ref(HHV(H,20),1)>3 );
Buy =Cross(Ref(LLV(L,20),1),L) AND CONDBUY;
Sell=Cross(H,Ref(HHV(H,20),1)) AND CONDSELL;
Filter=Buy OR Sell;
PlotShapes (IIf(Buy,shapeUpArrow,shapeNone),coloraqua,0,L,15);
PlotShapes (IIf(Sell,shapeDownArrow,shapeNone),coloryellow,0,H,15);
AddColumn( Buy, "Buy", 1.2 );
AddColumn( Sell, "Sell", 1.2 );
_SECTION_END();

@Shrees,
The reason why your code is not working is wrong logic used. You are using BarsSince() to find the number of candles since a HHV or LLV occurred. The statement you used is:
CONDBUY=barssince(Ref(LLV(L,20),1) >3 );
CONDSELL=barssince(Ref(HHV(H,20),1)>3 );
Here, barssince is candle number (rather difference in candle numbers) whereas LLV(...) and HHV(...) are prices. Effectively you are trying to find the difference between price and candle number. This is not possible as the two quantities are of different kind. It is similar to subtracting 4 apples from 10 oranges. The correct way is to find the number of bars since the event (LLV or HHV) occurred. Therefore, the statements to find the bars since the LLV or HHV should be written as:
barssince(LLV(L,20) == L)
barssince(HHV(H,20) == H)
There is some more coding logic involved to get the correct results. I need to explain it with chart. I would do it in another post. Till then just try to understand what I have posted now and if you (or any member of this forum) find anything incorrect just let me know.
Anant