标题: [讨论] Farshine, do you need to write these? [打印本页] 作者: not4weak 时间: 2011-9-15 22:47 标题: Farshine, do you need to write these?
namespace NinjaTrader.Strategy
{
/// <summary>
/// Simple moving average cross over strategy.
/// </summary>
[Description("Simple moving average cross over strategy.")]
public class SampleMACrossOver : 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))
EnterLong();
else if (CrossBelow(SMA(Fast), SMA(Slow), 1))
EnterShort();
}
#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
}
}作者: farshine 时间: 2011-9-15 22:55
you can use Wizard to generate most code, after that, unlock the code, added your own code/function. Very easy.