When I re-run the test on the same downloaded Market Replay data (same dates as the issue with live data), the issue does not occur on replay. Is it possible something strange is happening between Ninja Trader and Volatility of the session to where it gets confused and takes additional orders?
Is there any way to add a line of Code to the Strategy to tell it not to take an additional position, if already in one? Or maybe to wait X amount of candles/ticks before considering another position ?
Below is an example of a duplicate trade it took.. Quantity for the ATM strategy was set to 1.
Below is an example of my code for initiating the ATM strat with just the RSI...
protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
if (CurrentBars[0] < 1)
return;
if(State == State.Historical)
return;
// Set 1
if (orderId.Length == 0
&& atmStrategyId.Length == 0
&& (RSI1.Default[0] > 70)
&& (Position.MarketPosition == MarketPosition.Flat))
{
isAtmStrategyCreated = false; // reset atm strategy created check to false
atmStrategyId = GetAtmStrategyUniqueId();
orderId = GetAtmStrategyUniqueId();
AtmStrategyCreate(OrderAction.Buy, OrderType.Market, 0, 0, TimeInForce.Day, orderId, "AtmStrategyTemplate", atmStrategyId, (atmCallbackErrorCode, atmCallBackId) => {
//check that the atm strategy create did not result in error, and that the requested atm strategy matches the id in callback
if (atmCallbackErrorCode == ErrorCode.NoError && atmCallBackId == atmStrategyId)
isAtmStrategyCreated = true;
});
Draw.ArrowUp(this, @"ADXDMI2 Arrow up_1 " + Convert.ToString(CurrentBars[0]), true, 0, (High[0] + (20 * TickSize)) , Brushes.Green);
}
if (RSI1.Default[0] < 10
&& (PositionAccount.MarketPosition == MarketPosition.Long))
{
AtmStrategyClose(atmStrategyId);
}

Comment