here is the error,
Error on calling 'OnBarUpdate' method for strategy 'MyCustomStrategy/16e4ec3489ac4e47a5dff5ac3572ba30': MyCustomStrategy.DrawLine: startBarsAgo out of valid range 0 through 250, was 418.
Here is the code,
#region Using declarations
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Indicator;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Strategy;
#endregion
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
/// <summary>
/// Enter the description of your strategy here
/// </summary>
[Description("Enter the description of your strategy here")]
public class MyCustomStrategy : Strategy
{
private double highY;
private double lowY;
private double closeY;
private int sessionCount;
protected override void Initialize()
{
Add(PeriodType.Minute, 60);
Add(PeriodType.Minute, 1);
CalculateOnBarClose = true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
DrawLine("highY" + sessionCount, false, Bars.BarsSinceSession, highY, 0, highY,Color.Black,DashStyle.Dash,2);
DrawLine("lowY" + sessionCount, false, Bars.BarsSinceSession, lowY, 0, lowY,Color.Black,DashStyle.Dash,2);
DrawLine("closeY"+ sessionCount, false, Bars.BarsSinceSession, closeY, 0, closeY,Color.Black,DashStyle.Dash,2);
if(BarsInProgress == 1)
return;
// If there is a new session add one to session count.
if(Bars.SessionBreak)
sessionCount++;
if(BarsInProgress == 2)
{
if(CurrentBar < 1)
return;
if(Bars.FirstBarOfSession)
{
highY = MAX(Highs[1],14)[0];
lowY = MIN(Lows[1],14)[0];
closeY = Closes[1][1];
}
}
}
}
}
Comment