How can I make my strategy include this part of my script in backtest:
if (Bars.FirstBarOfSession)
{
// Store the strategy's prior cumulated realized profit and number of trades
priorTradesCount = Performance.RealtimeTrades.Count;
priorTradesCumProfit = Performance.RealtimeTrades.TradesPerformance.Curre ncy.CumProfit;
}
/* Prevents further trading if the current session's realized profit exceeds $1000 or if realized losses exceed $1500.
Also prevent trading if 20 trades have already been made in this session. */
if (Performance.RealtimeTrades.TradesPerformance.Curr ency.CumProfit - priorTradesCumProfit >= 1000
|| Performance.RealtimeTrades.TradesPerformance.Curre ncy.CumProfit - priorTradesCumProfit <= -1500
|| Performance.RealtimeTrades.Count - priorTradesCount > 20)
return;
NB:
I am replacing all Performance.RealtimeTrades with Performance.AllTrades.
I am trying to reset the private double priorTradesCumProfit before the session begins.
Regards,
Kiriru
Comment