I want to monitor and do no more trades for day once a certain loss happens.
But when it gets to new day trades can once again happen.
I am getting following error after a number of days performing above goal
**NT** Error on calling 'OnPositionUpdate' method for strategy 'BobGoldStandardV22/a08c3141938c43c085f2a5126c6981e1': You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.
The code I think is causing it is:
protectedoverridevoid OnPositionUpdate(IPosition position)
{
if (Position.MarketPosition == MarketPosition.Flat)
{
if (Performance.AllTrades.LosingTrades.Count > 0)
{
Trade lastTrade = Performance.AllTrades.LosingTrades[Performance.AllTrades.Count - 1];
double profitDollars = lastTrade.ProfitCurrency;
if (profitDollars != null && profitDollars < 0)
{ //The plan is once you have a negative dollar amount for day especially first trade of day
//Stop trading until next day
//On Barupdate if flat will reset these on new day
bStopTrading = true;
DayOfWeek = (0 - Time[0].DayOfWeek ); // Day of failure
}
else
{
bStopTrading = false;
DayOfWeek = -99;
}
}
else
{
bStopTrading = false;
DayOfWeek = -99;
}
//Document current profit/loss
Print(Time[0] + "Profit/Loss "+ (Performance.RealtimeTrades.TradesPerformance.Gros sProfit +
Performance.RealtimeTrades.TradesPerformance.Gross Loss ) ) ;
Comment