I want to implement a limit on daily losing long/short trades.
I have a code to determine last trade's PnL:
protected override void OnPositionUpdate(Position position, double averagePrice, int quantity, MarketPosition marketPosition) { if (Position.MarketPosition == MarketPosition.Flat && SystemPerformance.AllTrades.Count > 0) { LastPnL = SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count - 1].ProfitCurrency; }
After that, I would use this code [short trade example]:
if (LastPnL < 0 && ShortTrade) // Where ShortTrade is bool that I need to calculate DShortCount++; if (DShortCount == DLimitShort) { DAllowShort = false; }
Comment