// ============================================================================================ // Vortex Floor Pivot Reversal (S1/R1) - free NinjaTrader 8 example strategy from Vortex Futures Trade Lab // https://vortexfuturestradelab.com // // FOR EDUCATION ONLY. NOT FINANCIAL ADVICE. USE AT YOUR OWN RISK. // Trading futures carries a substantial risk of loss. Past or simulated results do not predict future // results. This strategy is a teaching example of a well-known idea; we do not claim it makes money. // Test it on a simulated account first. Many prop firms ban automated trading: check your firm's // rules before running any strategy on an evaluation or funded account. // // Times below use your chart's time zone. The defaults assume US Eastern time. // Rules (same as the simulation on the strategy page): classic floor pivots from the previous regular session: P = (H + L + C) / 3, S1 = 2P - H, R1 = 2P - L. Buy when a bar trades down to S1 or below but closes back above it; sell short when a bar trades up to R1 or above but closes back below it. Target = the pivot P (at least 4 ticks away), stop = 2 x ATR(14). One trade a day, flat by the end time. // ============================================================================================ #region Using declarations using System; using System.ComponentModel; using System.ComponentModel.DataAnnotations; using NinjaTrader.Cbi; using NinjaTrader.Data; using NinjaTrader.NinjaScript; using NinjaTrader.NinjaScript.Indicators; #endregion namespace NinjaTrader.NinjaScript.Strategies { public class VortexPivotReversal : Strategy { private ATR atr; private double curH, curL, lastC, prevH, prevL, prevC; private bool dayTraded; protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"Floor pivot reversal teaching example. Fades the first S1/R1 touch back toward the pivot, ATR stop, one trade a day, flat before the close. Education only. Use the default CME US Index Futures ETH trading hours."; Name = "VortexPivotReversal"; Calculate = Calculate.OnBarClose; EntriesPerDirection = 1; EntryHandling = EntryHandling.AllEntries; IsExitOnSessionCloseStrategy = false; IsFillLimitOnTouch = false; OrderFillResolution = OrderFillResolution.Standard; Slippage = 0; StartBehavior = StartBehavior.WaitUntilFlat; TimeInForce = TimeInForce.Gtc; TraceOrders = false; RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose; StopTargetHandling = StopTargetHandling.PerEntryExecution; BarsRequiredToTrade = 120; TradeFromTime = 93500; LastEntryTime = 153000; FlatByTime = 155500; AtrPeriod = 14; AtrStopMultiple = 2.0; } else if (State == State.DataLoaded) { atr = ATR(AtrPeriod); } } private bool IsLong { get { return Position.MarketPosition == MarketPosition.Long; } } private bool IsShort { get { return Position.MarketPosition == MarketPosition.Short; } } protected override void OnBarUpdate() { if (BarsInProgress != 0) return; if (CurrentBar == 0 || Bars.IsFirstBarOfSession) { if (curH > 0) { prevH = curH; prevL = curL; prevC = lastC; } curH = 0; curL = double.MaxValue; dayTraded = false; } int tt0 = ToTime(Time[0]); if (tt0 >= 93500 && tt0 <= 160000) { curH = Math.Max(curH, High[0]); curL = Math.Min(curL, Low[0]); lastC = Close[0]; } if (CurrentBar < BarsRequiredToTrade) return; int t = ToTime(Time[0]); if (t >= FlatByTime) { if (IsLong) ExitLong(); else if (IsShort) ExitShort(); return; } if (t < TradeFromTime) return; bool canEnter = t <= LastEntryTime; if (dayTraded || prevH <= 0 || !canEnter || Position.MarketPosition != MarketPosition.Flat) return; double pp = (prevH + prevL + prevC) / 3.0; double s1 = 2 * pp - prevH; double r1 = 2 * pp - prevL; int stopTicks = Math.Max(4, (int)Math.Round(atr[0] * AtrStopMultiple / TickSize)); if (Low[0] <= s1 && Close[0] > s1 && pp - Close[0] >= 4 * TickSize) { SetStopLoss(CalculationMode.Ticks, stopTicks); SetProfitTarget(CalculationMode.Ticks, (int)Math.Round((pp - Close[0]) / TickSize)); EnterLong(); dayTraded = true; } else if (High[0] >= r1 && Close[0] < r1 && Close[0] - pp >= 4 * TickSize) { SetStopLoss(CalculationMode.Ticks, stopTicks); SetProfitTarget(CalculationMode.Ticks, (int)Math.Round((Close[0] - pp) / TickSize)); EnterShort(); dayTraded = true; } } #region Properties [NinjaScriptProperty] [Range(0, 235959)] [Display(Name = "Trade from (HHmmss)", Description = "No trades before this bar-close time. Chart time zone.", Order = 1, GroupName = "Hours")] public int TradeFromTime { get; set; } [NinjaScriptProperty] [Range(0, 235959)] [Display(Name = "Last entry (HHmmss)", Order = 2, GroupName = "Hours")] public int LastEntryTime { get; set; } [NinjaScriptProperty] [Range(0, 235959)] [Display(Name = "Flat by (HHmmss)", Description = "Open positions are closed from this time. No overnight trades.", Order = 3, GroupName = "Hours")] public int FlatByTime { get; set; } [NinjaScriptProperty] [Range(1, 100)] [Display(Name = "ATR period", Order = 20, GroupName = "Parameters")] public int AtrPeriod { get; set; } [NinjaScriptProperty] [Range(0.5, 10)] [Display(Name = "ATR stop multiple", Order = 21, GroupName = "Parameters")] public double AtrStopMultiple { get; set; } #endregion } }