Hello,
I found a strange thing when I use "Trade NEXT BAR on OPEN,the stops exit on NEXT BAR OPEN ".

I use below afl to generate buy, sell signals:
SetOption("InitialEquity", 100000);
SetOption("MaxOpenPositions",5);
SetOption("CommissionMode", 3); //count hand cost by how much future
SetOption("CommissionAmount", 0.005); //one future hand cost 50 dollars
SetBacktestMode( backtestRotational );
SetOption("AllowPositionShrinking", True );
//The number of issues to hold at a time
NumberHeld=5;//Optimize("NumberHeld",1,1,10,2);
//Allocate funds equally among all issues
PositionSize = -100/(NumberHeld);
SetOption("WorstRankHeld",5);
LookBack =76;//Optimize("LookBack ",76,10,200,2);
Score = ROC(C,LookBack);
PositionScore = Score;
It will generate Open Long below:

It enter Long "REGN" on 7/21 but price is 7/21's open price.
It buyprice should 7/22's open price.

It might have bug on "Trade NEXT BAR on OPEN,the stops exit on NEXT BAR OPEN ".
Thank you.
I’d be very careful about throwing accusations of Amibroker bugs around on this forum. The program author generally doesn’t take kindly to those sorts of remarks. A better question would be “what am I missing here?”.
In your case, I’d say since you have the BuyDelay set to 1 and the BuyPrice set to open, the entry signal and execution is delayed by one bar until the bar you see in the Detailed Log. If you set the BuyDelay to 0 you should be able to verify that it happens one bar sooner.
1 Like
@chengyensheng as I can already find an unrelated error in your code I would think it is you that has made a mistake and not a "Bug".
I would suggest that you "debug" your code (it has been posted by Tomasz that the statistics gathered by AmiBroker customer support show a 0.1% incidence of "Bug" in AmiBroker). So you are more likely not understanding your own system.
So Explore your code, find out when did REGN enter your top 5 in rankings and then you can determine when it should have been purchased?
http://www.amibroker.com/kb/2014/09/29/debugging-techniques-part-1-exploration/
With regards to your code, I assume you are trying to create a Long Only rotational strategy. So read this,
http://www.amibroker.com/kb/index.php?s=rotation
If REGN entered your top 5 at the Close of trading on 7/20, then the entry should take place on the OPEN of 7/21.
I can see from your own screen capture that MELI was exited to allow the purchase of REGN

At the Close of 7/20 your score for MELI is below the score for REGN (33.39 vs 34.48)
1 Like