See the sample code below. (For simplicity, I have removed additional entry conditions.)
protected override void OnBarUpdate() { if( Position.MarketPosition == MarketPosition.Flat ) { if( Close[0] <= BuyPrice ) { // I have removed additional conditions like RSI check for simplicity. EnterLong(); Print("Long Position opened."); } } else { if( Close[0] >= TargetPrice ) { ExitLong(); Print("Long Position exited at profit."); } else if( Close[0] <= StopLossPrice ) { ExitLong(); Print("Long Position exited at stoploss."); } } }
However, say if a long position is open, and I remove and reattach the strategy, the Position.MarketPosition value is Flat instead of expected Long.
How do I ensure that when I reattach the strategy to the chart, I get the correct Position.MarketPosition ?
Comment