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 TestStrategy : Strategy
{
#region Variables
private double highestHigh = 0;
private double lowestLow = 0;
private int barPeriod = 45;
#endregion
/// <summary>
/// This method is used to configure the strategy and is called once before any strategy method is called.
/// </summary>
protected override void Initialize()
{
CalculateOnBarClose = true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
if (Bars.FirstBarOfSession && FirstTickOfBar)
{
highestHigh = High[0];
lowestLow = Low[0];
}
// Stores the highest high from the first 30 bars
if (Bars.BarsSinceSession < 30 && High[0] > highestHigh)
{
highestHigh = High[0];
}
// Stores the lowest low from the first 30 bars
if (Bars.BarsSinceSession < 30 && Low[0] < lowestLow)
{
lowestLow = Low[0];
}
for (int i = 0; i < barPeriod; i++)
if (Open[0][i] < Close[0][i] && Rising(Current[0]))
{
EnterLong();
ExitShort();
}
else if (Currrent[0] >= highestHigh)
{
ExitLong();
EnterShort();
}
}
#region Properties
[Description("")]
[GridCategory("Parameters")]
public int MyInput0
{
get { return myInput0; }
set { myInput0 = Math.Max(1, value); }
}
#endregion
}
}
Comment