I'm a beginner and I'm trying ti write a simple code as a learning experience. I'm doing something wrong as I get errors when I compile.
I'm adding a condition to go long if the current price is higher then the last bar and going short if the current price at bar close is lower the the last bar to the NINJATRADER SAMPLE STRATEGY MACROSSOVER
Is anyone able to see my problem and help me correct it so that I can move on with some backtesting.
Thank you very much!!! Dennis
#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 moving average cross over strategy.
/// </summary>
[Description("Simple moving average cross over strategy.")]
public class DKAMACrossOver : Strategy
{
#region Variables
private int fast = 10;
private int slow = 25;
#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()
{
SMA(Fast).Plots[0].Pen.Color = Color.Orange;
SMA(Slow).Plots[0].Pen.Color = Color.Green;
Add(SMA(Fast));
Add(SMA(Slow));
CalculateOnBarClose = true;
}
/// <summary>
/// Called on each bar update event (incoming tick).
/// </summary>
protected override void OnBarUpdate()
{
if (CrossAbove(SMA(Fast), SMA(Slow), 1)
&& (Close[1] > Close[0]) )
EnterLong();
else if (CrossBelow(SMA(Fast), SMA(Slow), 1)
&& (Close[1] < Close[0]))
EnterShort();
}[/COLOR]
#region Properties
/// <summary>
/// </summary>
[Description("Period for fast MA")]
[GridCategory("Parameters")]
public int Fast
{
get { return fast; }
set { fast = Math.Max(1, value); }
}
/// <summary>
/// </summary>
[Description("Period for slow MA")]
[GridCategory("Parameters")]
public int Slow
{
get { return slow; }
set { slow = Math.Max(1, value); }
}
#endregion
}
}
Comment