Buy at open and exit on close

I have an issue, obviously, from not knowing how to properly code this. This is the general structure. The system is for buy/sell signals only.

SetBacktestMode(backtestRegular); 
SetTradeDelays( 1, 0, 0, 0 );

System rules. There are several entry and exit rules. 

BuyPrice = Open;
SellPrice= Close;

My problem is that if an exit of an open position is triggered for the close by one of the rules, the trade is properly exited at the close, but if a new entry signal was triggered at the previous close by another rule while the trade was open, a new entry is generated at the open of the day, i.e., the system goes back in time to the open of the day to put in another trade instead of respecting the delay of one bar after the close of the open trade and doing that at the next open. That trade overlaps with the one that is exited at the close and often introduces some look-ahead bias.

How can I fix the issue so there are no back signals generated after a trade is exited at the close? I know I am missing something here. Thanks in advance.

Have a look at the section "RESOLVING SAME BAR, SAME SYMBOL SIGNAL CONFLICTS" on this page: Portfolio-level back testing

I think I fixed it with exrem. Thanks

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.