I got problem of getting correct position data inside OnPositionUpdate method when running from Strategies Tab. The problem is that IPosition object has exactly opposite values when runned on my MBTrading account than if runned at the Sim101 account.
Let's demonstrate it on simple strategy:
#region Using declarations using System; using System.ComponentModel; using NinjaTrader.Cbi; #endregion namespace NinjaTrader.Strategy { public class PositionDemo : Strategy { protected override void OnPositionUpdate( IPosition position ) { Print( position.ToString( ) ); } protected override void OnBarUpdate( ) { if( Historical ) { // just skip historical run return; } if( Position.MarketPosition == MarketPosition.Flat ) { Print( "EnterLong" ); EnterLong( ); } else { Print( "ExitLong" ); ExitLong( ); } } } }
When I run this on the Sim101 account, I get result as expected.
Instrument='NQ 12-12' Account='Sim101' Avg price=2856 Quantity=1 Market position=Long
ExitLong
Instrument='NQ 12-12' Account='Sim101' Avg price=0 Quantity=0 Market position=Flat
Instrument='NQ 12-12' Account='35009544' Avg price=0 Quantity=0 Market position=Flat
ExitLong
Instrument='NQ 12-12' Account='35009544' Avg price=2856,5 Quantity=1 Market position=Long
I use NinjaTrader 7.0.1000.11 with MBT Desktop 11.9.0.44.
Comment