Print("Position.Quantity: " + Position.Quantity);
if (Position.MarketPosition == MarketPosition.Long && Position.Quantity != 0)
{
Print("Trying to exit long");
ExitLong();
Print("After exit");
}
My output is as follows (with traceOrders ON):
Position.Quantity: 8
Trying to exit long
12/9/2024 11:46:59 AM Strategy 'PullBackStrategy/278923525': Entered internal SubmitOrderManaged() method at 12/9/2024 11:46:59 AM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=0 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal='LongPullback 1'
Strategy 'PullBackStrategy/278923525': Error on calling 'OnOrderUpdate' method on bar 4321: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.
Disabling NinjaScript strategy 'PullBackStrategy/278923525'
After exit
It says I am accessing an index with a value that is not valid...but it is crashing on the ExitLong();
I have tried inserting Position.Quantity and adding my entry signals, but it does not work. I have commented the ExitLong(); code out and it stopped producing the error. It closed out my pending target and stop orders, but as expected, the open position remains open.
I am entering the trades using EnterLong() and adding the stop and target orders later, but they are all using that original entry signal.
I am at a loss on what to do. Any help would be greatly appreciated.

Comment