This is what I have.
#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>
/// After n bars up, go short. After n bars down, go long. Testing whether 5-6 red bars is a good time for a swing trade in the opposite direction.
/// </summary>
[Description("After n bars up, go short. After n bars down, go long. Testing whether 5-6 red bars is a good time for a swing trade in the opposite direction.")]
public class nBarsOpposite : Strategy
{
#region Variables
// Wizard generated variables
private int nbars = 5; // Default setting for Nbars
// User defined variables (add any user defined variables below)
#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()
{
SetTrailStop("", CalculationMode.Ticks, 1.5, true);
CalculateOnBarClose = true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Condition set 1
if (NBarsDown(3, true, true, true)[0] == 1)
{
EnterLong(DefaultQuantity, "");
}
// Condition set 2
if (NBarsUp(3, true, true, true)[0] == 1)
{
EnterShort(DefaultQuantity, "");
}
}
#region Properties
[Description("How many bars to look back")]
[GridCategory("Parameters")]
public int Nbars
{
get { return nbars; }
set { nbars = Math.Max(1, value); }
}
#endregion
}
}

Comment