I did not have the following problem during backtesting, only during live trading.
I nested my entry conditions in OnBarUpdate, like so:
protected override void OnBarUpdate() { { if (BarsInProgress == 0) if (Position.MarketPosition == MarketPosition.Flat && LLA == null && Laguerre(0.6).LaguerreOut[0] > 0.6 && Laguerre(0.6).LaguerreOut[0] > Laguerre(0.6).LaguerreOut[1] ) { LLA = EnterLong(0, DefaultQuantity, "LLA"); DrawArrowUp("My up arrow" + CurrentBar, false, 0, Low[0] + -65 * TickSize, Color.Lime); } } }
How is this possible considering that
- I clearly stipulate that one of the conditions is being flat
- LLA gets a value from the moment a position is opened and I want LLA to be null in order to open a position ?? (the resetting of this LLA back to null is done elsewhere in my code, when being flat, so it should not be null until the first position is closed!)
I spent hours debugging with print statements already, but cannot figure out why this is happening.
First I thought that the time difference between submitting an order and the effective opening of it had to do something with it, but proved this to be wrong. I noticed orders being open for minutes already, and still a second one opened. Does not seem logical.
Then I suspected there was a mistake with the nesting of my conditions (that I closed the curly brackets too late and they fell in the smaller, 2 seconds timeframe), but that does not seem to be the case either.
Please help
Comment