//
// Copyright (C) 2007, NinjaTrader LLC <www.ninjatrader.com>.
// NinjaTrader reserves the right to modify or overwrite this NinjaScript component with each release.
//
#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.Strategy;
#endregion
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
/// <summary>
/// Simple strategy that monitors for a breakout.
/// </summary>
[Description("Simple strategy that monitors for a breakout.")]
public class SampleBreakoutStrategy : Strategy
{
#region Variables
private double highestHigh = 0;
#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()
{
// Resets the highest high at the start of every new session
if (Bars.FirstBarOfSession)
highestHigh = High[0];
// Stores the highest high from the first 30 bars
if (Bars.BarsSinceSession < 30 && High[0] > highestHigh)
highestHigh = High[0];
// Entry Condition: Submit a buy stop order one tick above the first 30 bar high. Cancel if not filled within 10 bars.
if (Bars.BarsSinceSession > 30 && Bars.BarsSinceSession < 40)
{
// EnterLongStop() can be used to generate buy stop orders.
EnterLongStop(highestHigh + TickSize);
}
// Exit Condition: Close positions after 10 bars have passed
if (BarsSinceEntry() > 10)
ExitLong();
// Resets the lowest low at the start of every new session
if (Bars.FirstBarOfSession)
lowestLow = Low[0];
// Stores the lowest low from the first 30 bars
if (Bars.BarsSinceSession < 30 && Low[0] > lowestLow)
lowestLow = Low[0];
// Entry Condition: Submit a buy stop order one tick above the first 30 bar low. Cancel if not filled within 10 bars.
if (Bars.BarsSinceSession > 30 && Bars.BarsSinceSession < 40)
{
// EnterShortStop() can be used to generate buy stop orders.
EnterShorStop(lowestLow + TickSize);
}
// Exit Condition: Close positions after 10 bars have passed
if (BarsSinceEntry() > 10)
ExitShort();
}
}
}



Comment