I have the following code to close the strategy based on amount of losses suffered for a day:
if (base.Bars.FirstBarOfSession)
{
priorCumProfit = Performance.AllTrades.TradesPerformance.Currency.CumProfit;
}
// *** Calculate the total profit (cumulative profit minus prior profit plus the current position profit
double myMaxLoss = maxloss;
double cumProfit = (double) Performance.AllTrades.TradesPerformance.Currency.CumProfit;
double curPosition = (double) Position.GetProfitLoss(Close[0], PerformanceUnit.Currency);
double totCumProfit = (double) (cumProfit - priorCumProfit) + curPosition ;
// *** STOP the strategy! if a total profit or loss exceeds the max
if (totCumProfit <= myMaxLoss )
{
if (Position.MarketPosition == MarketPosition.Long) {ExitLong("DMA: Exit Long ", "");}
if (Position.MarketPosition == MarketPosition.Short) {ExitShort("DMA: Exit Short", "");}
return;
}
Could this be achieved? Is there any workaround ?
Thank You

Comment