ninjatrader/strategies/super-bot/SuperBot.cs

57 lines
1.7 KiB
C#

#region Using declarations
using NinjaTrader.Cbi;
using NinjaTrader.NinjaScript.Indicators;
using System.ComponentModel.DataAnnotations;
#endregion
namespace NinjaTrader.NinjaScript.Strategies
{
public class SuperBot : Strategy
{
private SuperSmoother superSmoother;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Name = "SuperBot";
Description = @"Strategy based on John F. Ehlers' SuperSmoother";
Calculate = Calculate.OnBarClose;
EntriesPerDirection = 1;
SuperSmootherPeriod = 10;
}
else if (State == State.Configure)
{
superSmoother = SuperSmoother(SuperSmootherPeriod);
}
}
protected override void OnBarUpdate()
{
if (CurrentBar < BarsRequiredToTrade)
return;
if(CrossAbove(Close, superSmoother.Value[0], 1) || (Open[0] > superSmoother.Value[0] && Close[0] > Open[0]))
{
if (Position.MarketPosition != MarketPosition.Long)
EnterLong();
}
else if (CrossBelow(Close, superSmoother.Value[0], 1) || (Open[0] < superSmoother.Value[0] && Close[0] < Open[0]))
{
if (Position.MarketPosition != MarketPosition.Short)
EnterShort();
}
}
public override string DisplayName
{
get { return Name; }
}
[NinjaScriptProperty]
[Display(Name = "SuperSmoother Period", GroupName = "SuperBot", Order = 1)]
public int SuperSmootherPeriod { get; set; }
}
}