Small help for AFL code

#1
Someone plz help me for below formula.

Formula is simple based on Inside bar as buy or sell candle. I want to buy only if high of inside bar broken and low of inside bar is not broken first.

So in short if low of Ib is broken first then no buy arrow will be shown when high is crossed later.

Green=C>O;Red=O>C;
IBb= H<Ref(H,-1) AND L>Ref(L,-1) and EMA(C,5)>EMA(C,15);
IBs= H<Ref(H,-1) AND L>Ref(L,-1) and EMA(C,5)<EMA(C,15);

barcolor = IIf( IBb, colorBlue,IIf(IBs, colorblack, IIf( Green, colorLime, colorRed)));
{ColorHighliter = barColor;
SetBarFillColor( ColorHighliter );}

BuySetupValue=ValueWhen(IBb,H,1);
SellsetupValue=ValueWhen(IBs,L,1);
Buy=Cross(C,BuySetupValue);
Sell=Cross(SellsetupValue,C);
Buy=ExRem(Buy,IBb OR IBs);
Sell=ExRem(Sell,IBb OR IBs);

PlotShapes( shapeUpArrow*Buy, colorGreen,0, H, 10) ;
PlotShapes( shapeDownArrow*Sell,colorRed,0, L, 10) ;
 

travi

Well-Known Member
#2
You'll need to work up another logic, bcos what you want to achieve is visually correct but to code
the challenge is ur computing on the current bar which is actively forming, so there are many chances that buy will be fired before Low is broken.

You can however try and add a NOT condition of CROSS(L,C) but this will only help before buy is fired.

Another workound is, you can go to lowest TF, then check condition.
Eg. if u plan to run this on 15m TF
then current bar IB will be worth 15x1m bars so
try
IBlow = TimeFrameGetPrice( "L", 15*60, 0 );
add a condition AND C >= IBLow to the IBb line
 
#3
can we do something like.....if low of IBb is broken first then that candle is disappeared from chart as IBb(and if high is broken first then buyarrow will come and that IBb will stay there)...like it happens in repainting afl.
 

Similar threads