From 92a6c244f14e9096cf50f38bfa1484de654bab95 Mon Sep 17 00:00:00 2001 From: moshferatu Date: Thu, 14 Nov 2024 05:53:22 -0800 Subject: [PATCH] Initial commit of Turnaround strategy --- strategies/turnaround/TurnaroundBot.cs | 49 ++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 strategies/turnaround/TurnaroundBot.cs diff --git a/strategies/turnaround/TurnaroundBot.cs b/strategies/turnaround/TurnaroundBot.cs new file mode 100644 index 0000000..e0f9eda --- /dev/null +++ b/strategies/turnaround/TurnaroundBot.cs @@ -0,0 +1,49 @@ +#region Using declarations +using NinjaTrader.Cbi; +using System; +#endregion + +namespace NinjaTrader.NinjaScript.Strategies +{ + public class TurnaroundBot : Strategy + { + protected override void OnStateChange() + { + if (State == State.SetDefaults) + { + Description = @"Turnaround Tuesday / Wednesday"; + Name = "Turnaround 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; + } + } + + protected override void OnBarUpdate() + { + if (CurrentBar < BarsRequiredToTrade) return; + + // Entry + if ((Time[0].DayOfWeek == DayOfWeek.Monday || Time[0].DayOfWeek == DayOfWeek.Tuesday) && + Close[0] < Close[1] && Close[1] < Close[2]) + EnterLong(); + + // Exit + if (Position.MarketPosition == MarketPosition.Long && Close[0] > High[1]) + ExitLong(); + } + } +}