AddOrders executing 2 bars after event instead of 1?

T

TraderKevin

New member
Hey guys and gals,

I've been backtesting a new strategy and for some reason my orders are not executing on the 1st bar after the conditions are satisfied, but instead skipping a bar and executing 2 bars after the event. What makes it stranger is that sometimes it executes like it normally does and buys/sells on the bar after the conditions are satisfied, but this is a small percentage of the time.

I've narrowed the script down to be extremely simple (pardon my hiding the key variables for confidentiality) for testing:

def x= if high("XYZ") >= # then 1 else 0;
def y= if low("XYZ") <= # then 1 else 0;

AddOrder(OrderType.BUY_AUTO, x== 1, close, 300, tickcolor = GetColor(1), arrowcolor = GetColor(1));

AddOrder(OrderType.SELL_AUTO, y== 1, close, 300, tickcolor = GetColor(2), arrowcolor = GetColor(2));

This is literally it... no offsets, nothing. Buy when x==1 it doesn't buy on the next bar, but the following. Anyone else experienced this or know what might be causing it?
 
T

TraderKevin

New member
@TraderKevin instead of BUY on close, try open[-1]

This had no effect on which candle the buy/sell order executed, only on the price that it executed at. This is to be expected... that parameter of the addorder function only controls the price when backtesting I believe. If you put 100 in there, the buy/sell price will always be 100, no matter what's happening with the candle or the rest of the strategy, and won't change the candle the addorder function executes on.
 
T

TraderKevin

New member
Upon further testing, I've noticed that when backtesting the strat over the last 30 days, before June 26th it adds an extra candle before executing the buy/sell, but after June 26th it acts normally (buys/sells on the bar following the condition being met). So weird!

Any ideas?
 
D

Don

New member
@TraderKevin without seeing the code, I have no ideas! Keep trying to reload and/or diff stock symbols. Sorry and good luck!
 

Similar threads

Top