![Rank: 18](images/default/star_level3.gif) ![Rank: 18](images/default/star_level3.gif) ![Rank: 18](images/default/star_level3.gif) ![Rank: 18](images/default/star_level3.gif) ![Rank: 18](images/default/star_level2.gif)
![VIP初级贡献会员 VIP初级贡献会员](images/common/md_vg.gif) ![股版虎威勋章 股版虎威勋章](images/common/md_tiger.gif) ![精华帖主 精华帖主](images/common/md_jh.gif) ![VIP中级贡献会员 VIP中级贡献会员](images/common/md_vip2.gif)
|
[讨论] 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
}
} |
|