I attempted to adda trade counter to this so it doesnt trade if there have been more than 3 trades in the session. It compiles ok, but when I ran it no orders came up after the first 20 minutes as expected. Is there something wrong with the the orders part of this that someone can see?
Any help would be much appreciated.
Thanks
//
// Copyright (C) 2007, NinjaTrader LLC <[URL="http://www.ninjatrader.com"]www.ninjatrader.com[/URL]>.
// 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;
private double lowestLow = 0;
private int tradeCounter = 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 and lowest low at the start of every new session
if (Bars.FirstBarOfSession && FirstTickOfBar)
{ tradeCounter = 0;
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];
//Enter Long at highest high + 1 of first 30 min. trade if number of trades today is less than 3
//Enter Short at lowest low - 1 of first 30 min. trade if number of trades today is less than 3
if (tradeCounter < 3)
{
EnterLongStop(highestHigh + TickSize);
tradeCounter++;
EnterShortStop(lowestLow - TickSize);
tradeCounter++;
}
}
}
}

Comment