diff --git a/strategies/engulfing/EngulfingBot.cs b/strategies/engulfing/EngulfingBot.cs new file mode 100644 index 0000000..763995e --- /dev/null +++ b/strategies/engulfing/EngulfingBot.cs @@ -0,0 +1,51 @@ +#region Using declarations +using NinjaTrader.Cbi; +using NinjaTrader.NinjaScript.Indicators; +#endregion + +namespace NinjaTrader.NinjaScript.Strategies +{ + public class EngulfingBot : Strategy + { + private SMA LongTermTrend; + + protected override void OnStateChange() + { + if (State == State.SetDefaults) + { + Name = "Engulfing Bot"; + Description = @"Simple strategy based on the engulfing candle pattern"; + Calculate = Calculate.OnBarClose; + EntriesPerDirection = 1; + } + else if (State == State.DataLoaded) + { + LongTermTrend = SMA(200); + } + } + + protected override void OnBarUpdate() + { + if (CurrentBar < BarsRequiredToTrade) + return; + + if (High[0] > High[1] && Close[0] < Low[1]) + { + if (Close[0] >= LongTermTrend[0]) + EnterLong(); + else + EnterShort(); + } + + if (Position.MarketPosition == MarketPosition.Long && (Close[0] > Position.AveragePrice || Close[0] > High[1])) + ExitLong(); + else if (Position.MarketPosition == MarketPosition.Short && (Close[0] < Position.AveragePrice || Close[0] < Low[1])) + ExitShort(); + } + + public override string DisplayName + { + get { return Name; } + } + } +}