From 46f36ea46ef286084cc79b37459030b7fdddaa3a Mon Sep 17 00:00:00 2001 From: moshferatu Date: Mon, 16 Dec 2024 13:01:11 -0800 Subject: [PATCH] Initial commit of Bearish Engulfing strategy --- .../bearish-engulfing/BearishEngulfingBot.cs | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 strategies/bearish-engulfing/BearishEngulfingBot.cs diff --git a/strategies/bearish-engulfing/BearishEngulfingBot.cs b/strategies/bearish-engulfing/BearishEngulfingBot.cs new file mode 100644 index 0000000..a57b78f --- /dev/null +++ b/strategies/bearish-engulfing/BearishEngulfingBot.cs @@ -0,0 +1,55 @@ +#region Using declarations +using NinjaTrader.Cbi; +using System; +#endregion + +namespace NinjaTrader.NinjaScript.Strategies +{ + public class BearishEngulfingBot : Strategy + { + protected override void OnStateChange() + { + if (State == State.SetDefaults) + { + Description = @""; + Name = "Bearish Engulfing Bot"; + Calculate = Calculate.OnBarClose; + EntriesPerDirection = 1; + EntryHandling = EntryHandling.AllEntries; + IsExitOnSessionCloseStrategy = true; + ExitOnSessionCloseSeconds = 30; + IsFillLimitOnTouch = false; + MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix; + OrderFillResolution = OrderFillResolution.Standard; + Slippage = 0; + StartBehavior = StartBehavior.WaitUntilFlat; + TimeInForce = TimeInForce.Gtc; + TraceOrders = false; + RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose; + StopTargetHandling = StopTargetHandling.PerEntryExecution; + BarsRequiredToTrade = 20; + IsInstantiatedOnEachOptimizationIteration = true; + } + else if (State == State.Configure) + { + } + } + + protected override void OnBarUpdate() + { + if (CurrentBar < BarsRequiredToTrade) + return; + + if (Close[1] > Open[1] && Open[0] > Close[1] && Close[0] < Open[1]) + EnterLong(); + + if (Position.MarketPosition == MarketPosition.Long && Close[0] > High[1]) + ExitLong(); + } + + public override string DisplayName + { + get { return Name; } + } + } +}