AFL Coding - Buy / Sell Coding Help

Can someone help me adding buy and sell condition to this AFL.

Buy Condition :- IF Price closes above PDL from below after 9:30 am

Sell Condition :- IF Prices closes below PDH from above after 9:30 am

SL are Few points below PDH and PDL

To Clarify this is my complete requirement

I am looking for a failed breakout strategy where either the day opens below Previous day high.... Candles crossses above PDH during the day but anytime after 9:30 it comes and closes below PDH. I want the sell signal to be generated on the break of low of the candle which closes below PDH with a target profit till PDL and Stop few points above PDH or if it is a gapup then once crosses below PDH after 9:30 a sell signal should be generated and vice versa for gapdown

Appreciate if someone can help me in building the buy and sell condition in the attached AFL.... Appreciate your support!


_N(Title = StrFormat(EncodeColor( colorGold) + "{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));

Plot( C, "Price", colorDefault, styleCandle );

PDH = TimeFrameGetPrice("H",inDaily,-1);
PDL = TimeFrameGetPrice("L",inDaily,-1);

Plot(PDH,"Upper",colorGreen,styleLine | styleThick);
Plot(PDL,"Lower",colorRed,styleLine | styleThick);

Check out here

Thank you for posting the thread , the problem is not defining the timing function. The challenge I am facing is to define the buy and sell condition because that need to defined as a failed breakout . Candle Crosses over Previous Day High but failed to sustain above that and then come below Previous day high there I want sell to be initiated similarly for Buy condition... Hope this clarifies my requirement. Appreciate your support