public void OnProcessPosition(EventType eventType) { Tick tick = Strategy.Data.Ticks[0]; if (stopTradingToday || stopTradingThisWeek || stopTradingThisMonth) { return; } if ((strategySignal > 0) != strategy.Position.IsLong || (strategySignal < 0) != strategy.Position.IsShort) { strategySignal = strategy.Position.Current; entryPrice = strategy.Position.Price; maxPnl = 0; position.Copy(strategy.Position); trailStop = 0; breakEvenStop = 0; CancelOrders(); } if (position.HasPosition) { // copy signal in case of increased position size double exitPrice; if (strategySignal > 0) { exitPrice = tick.IsQuote ? tick.Bid : tick.Price; pnl = (exitPrice - entryPrice).Round(); } else { exitPrice = tick.IsQuote ? tick.Ask : tick.Price; pnl = (entryPrice - exitPrice).Round(); } maxPnl = pnl > maxPnl ? pnl : maxPnl; if (stopLoss > 0) { processStopLoss(tick); } } }
public void OnProcessPosition() { Tick tick = Strategy.Data.Ticks[0]; // Handle ActiveNow orders. if (stopTradingToday || stopTradingThisWeek || stopTradingThisMonth) { return; } if ((strategySignal > 0) != context.Position.IsLong || (strategySignal < 0) != context.Position.IsShort) { strategySignal = context.Position.Current; entryPrice = context.Position.Price; maxPnl = 0; position.Copy(context.Position); trailStop = 0; breakEvenStop = 0; CancelOrders(); } if (position.HasPosition) { // copy signal in case of increased position size double exitPrice; if (strategySignal > 0) { exitPrice = tick.IsQuote ? tick.Bid : tick.Price; pnl = (exitPrice - entryPrice).Round(); } else { exitPrice = tick.IsQuote ? tick.Ask : tick.Price; pnl = (entryPrice - exitPrice).Round(); } maxPnl = pnl > maxPnl ? pnl : maxPnl; if (stopLoss > 0) { processStopLoss(tick); } if (trailStop > 0) { processTrailStop(tick); } if (breakEven > 0) { processBreakEven(tick); } if (targetProfit > 0) { processTargetProfit(tick); } if (dailyMaxProfit > 0) { processDailyMaxProfit(tick); } if (dailyMaxLoss > 0) { processDailyMaxLoss(tick); } if (weeklyMaxProfit > 0) { processWeeklyMaxProfit(tick); } if (weeklyMaxLoss > 0) { processWeeklyMaxLoss(tick); } if (monthlyMaxProfit > 0) { processMonthlyMaxProfit(tick); } if (monthlyMaxLoss > 0) { processMonthlyMaxLoss(tick); } } context.Position.Copy(position); }