I am trying to develop (using the strategy wizard) a variation on the SampleMAsCrossOver so that the Long trade will only be entered if and when the high of the crossover bar is touched (and, in the case of a Short, if and when the low of the crossover bar is touched).
Below is the code that I expected to work, but it doesn't. I also tried a number of other variations of trade types but non operated correctly.
Thanks
#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 MFMAsCrossOver2 : Strategy
{
#region Variables
// Wizard generated variables
private int mASlow = 4; // Default setting for MASlow
private int mAFast = 2; // Default setting for MAFast
private double sL = 0.001; // Default setting for SL
private double sLMove = 0.001; // Default setting for SLMove
// 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()
{
Add(SMA(MAFast));
Add(SMA(MASlow));
Add(SMA(MAFast));
Add(SMA(MASlow));
CalculateOnBarClose = true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Condition set 1
if (CrossAbove(SMA(MAFast), SMA(MASlow), 1))
{
EnterLongStop(DefaultQuantity, High[0], "Enter Long");
}
// Condition set 2
if (CrossBelow(SMA(MAFast), SMA(MASlow), 1))
{
EnterShortLimit(DefaultQuantity, Low[0], "Enter Short");
}
}
#region Properties
[Description("")]
[GridCategory("Parameters")]
public int MASlow
{
get { return mASlow; }
set { mASlow = Math.Max(2, value); }
}
[Description("")]
[GridCategory("Parameters")]
public int MAFast
{
get { return mAFast; }
set { mAFast = Math.Max(2, value); }
}
[Description("")]
[GridCategory("Parameters")]
public double SL
{
get { return sL; }
set { sL = Math.Max(0.000, value); }
}
[Description("")]
[GridCategory("Parameters")]
public double SLMove
{
get { return sLMove; }
set { sLMove = Math.Max(0.000, value); }
}
#endregion
}
}
Comment