Error on calling 'OnBarUpdate' method on bar 5: Index was outside the bounds of the array.
All was working fine until i setup enum and switch in my strategy. I cant figure out why its throwing outside the bounds of array error. I added 1 tick data for more accurate backtesting
private RiskRewardRatio riskReward = RiskRewardRatio.OneToOne;
protected override void OnBarUpdate()
{
if (CurrentBars[0] <= BarsRequiredToTrade || CurrentBars[1] <= BarsRequiredToTrade )
return;
double longBarSizeTicks = Math.Abs(Close[1] - Low[1]) / TickSize;
double shortBarSizeTIcks = Math.Abs(High[1] - Close[1]) / TickSize;
double rr1to1 = longBarSizeTicks;
double rr1to2 = longBarSizeTicks * 2;
switch (riskReward)
{
case RiskRewardRatio.OneToOne:
{
Value[0] = rr1to1;
break;
}
case RiskRewardRatio.OneToTwo:
{
Value[0] = rr1to2;
break;
}
}
[NinjaScriptProperty]
[Display(GroupName = "04. Order Management", Order = 12, Description="04. Order Management")]
public RiskRewardRatio RiskReward
{
get { return riskReward; }
set { riskReward = value; }
}
public enum RiskRewardRatio
{
OneToOne,
OneToTwo,
}

Comment