Signals are not generated at desired price

Hello Friends !!
I have been stuck on a code for last few days and could not find a solution.
I wish to generate signal at my desired buy and sell condition but this AFL generates on the open of the current candle.

i = BarsSince( Day() );
StartBar = ValueWhen(TimeNum() == 091500, BarIndex());

buystop=(Ref(o,i))*.9996;
SellStop=(Ref(o,i))*1.0004;
BuyPrice=Max(buystop,L);
SellPrice=Min(SellStop,H);
ShortPrice=SellPrice ;
CoverPrice=BuyPrice ;

tn = TimeNum();
startTime = 092000; // start in HHMMSS format
endTime = 151000; // end in HHMMSS format
StopTime=151500;
timeOK = tn >= startTime AND tn <= endtime;
BuySignal=((Buy1 OR Buy2)AND Buyprice) AND timeOK;

SellSignal=((Sell1 OR Sell2) AND SellPrice) OR Cross(tn,EndTime);
ShortSignal=((Sell1 OR Sell2) AND ShortPrice) AND timeOK;
CoverSignal=((Buy1 or buy2 ) AND CoverPrice) OR Cross(tn,EndTime);
Buy=Ref(BuySignal,0);
Sell=Ref(SellSignal,0);
Short=Ref(ShortSignal,0);
Cover=Ref(CoverSignal,0);
ApplyStop( stopTypeLoss, stopModePercent, .50 );

Hello @DrVikas,
I guess you would like to generate orders for the next bar. You could read again the manual and use Backtester Settings or modify your code. A lot of sample AFL systems in the library show you all you need e.g http://www.amibroker.com/members/library/detail.php?id=545
So to make it short what you're looking for is probably SetTradeDelays...

PS: for everyone's sake, please use the Code button to include code in a message Code%20button%20in%20Discourse%20editor

3 Likes