How did Position.Quantity get 18,490,000? Image attached.
when I only have 2 positions 10,000 + 10,000 = 20,000
when I EXIT LONG EURUSD (ProfitTarget).
//This namespace holds Strategies in this folder and is required. Do not change it. namespace NinjaTrader.NinjaScript.Strategies { public class LastEntryPrice : Strategy { private Order entryOrder; protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"Enter the description for your new custom Strategy here."; Name = "LastEntryPrice"; Calculate = Calculate.OnEachTick; EntriesPerDirection = 999999999; EntryHandling = EntryHandling.AllEntries; IsExitOnSessionCloseStrategy = false; ExitOnSessionCloseSeconds = 30; IsFillLimitOnTouch = false; MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix; OrderFillResolution = OrderFillResolution.Standard; Slippage = 9999999999; StartBehavior = StartBehavior.ImmediatelySubmit; TimeInForce = TimeInForce.Gtc; TraceOrders = false; RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose; StopTargetHandling = StopTargetHandling.PerEntryExecution; BarsRequiredToTrade = 0; // Disable this property for performance gains in Strategy Analyzer optimizations // See the Help Guide for additional information IsInstantiatedOnEachOptimizationIteration = true; } else if (State == State.Configure) { } else if (State == State.DataLoaded) { } } protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice, OrderState orderState, DateTime time, ErrorCode error, string nativeError) { if (order.Name == "EnterLong") entryOrder = order; } protected override void OnBarUpdate() { int Quantity = 10000; double Profit = ( PositionAccount.GetUnrealizedProfitLoss(PerformanceUnit.Currency, Close[0]) ); Account a = Account.All.First(t => t.Name == "Playback101"); // Account Display Name double Balance = a.Get(AccountItem.CashValue, Currency.UsDollar); double ProfitTarget = Balance*0.005; // Set 1 if ( (Open[0]-Low[0] >= 0.00003) ) { EnterLong(Quantity,"EnterLong"); } double lastentryprice = 0; if (entryOrder != null && entryOrder.OrderState == OrderState.Filled) lastentryprice = entryOrder.AverageFillPrice; Print(lastentryprice); if ( (lastentryprice >= Open[0]) && (PositionAccount.Quantity >= 1) && (BarsInProgress == 0) ) { EnterLong(0,Quantity,"EURUSD1"); } if ( Profit>= ProfitTarget ) { ExitLong(0,Position.Quantity,"EXIT LONG EURUSD (ProfitTarget)",""); } } } }
Comment