From 4f266c731b02e2d67f648dd2636caf75cfa0cf3b Mon Sep 17 00:00:00 2001 From: moshferatu Date: Mon, 11 Nov 2024 06:48:56 -0800 Subject: [PATCH] Initial commit of TRIN Thrusts strategy --- strategies/trin-thrusts/TRINThrusts.cs | 70 ++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 strategies/trin-thrusts/TRINThrusts.cs diff --git a/strategies/trin-thrusts/TRINThrusts.cs b/strategies/trin-thrusts/TRINThrusts.cs new file mode 100644 index 0000000..dbc5398 --- /dev/null +++ b/strategies/trin-thrusts/TRINThrusts.cs @@ -0,0 +1,70 @@ +#region Using declarations +using NinjaTrader.NinjaScript.Indicators; +using System.ComponentModel.DataAnnotations; +#endregion + +namespace NinjaTrader.NinjaScript.Strategies +{ + public class TRINThrusts : Strategy + { + private const int PrimaryBars = 0; + private const int TRINBars = 1; + + private SMA LongTermTrend; + + protected override void OnStateChange() + { + if (State == State.SetDefaults) + { + Name = "TRIN Thrusts"; + Description = @"Take from Chapter 3 of Connors on Advanced Trading Strategies (1998) by Larry Connors"; + Calculate = Calculate.OnBarClose; + EntriesPerDirection = 1; + + LongTermTrendPeriod = 200; + PercentBelow = 40.0; + DaysToExit = 2; + } + else if (State == State.Configure) + { + AddDataSeries("^TRIN"); + } + else if (State == State.DataLoaded) + { + LongTermTrend = SMA(LongTermTrendPeriod); + } + } + + protected override void OnBarUpdate() + { + if (PrimaryBars != BarsInProgress) + return; + + if (CurrentBar < LongTermTrendPeriod || CurrentBars[TRINBars] < 1) + return; + + if (Close[0] > LongTermTrend[0] && Closes[TRINBars][0] < Closes[TRINBars][1] * (1 - PercentBelow / 100)) + EnterLong(); + + if (BarsSinceEntryExecution(PrimaryBars, "", 0) >= DaysToExit) + ExitLong(); + } + + public override string DisplayName + { + get { return Name; } + } + + [NinjaScriptProperty] + [Display(Name = "Long-Term Trend Period", GroupName = "TRIN Thrusts", Order = 1)] + public int LongTermTrendPeriod { get; set; } + + [NinjaScriptProperty] + [Display(Name = "Percent Below", GroupName = "TRIN Thrusts", Order = 2)] + public double PercentBelow { get; set; } + + [NinjaScriptProperty] + [Display(Name = "Days to Exit", GroupName = "TRIN Thrusts", Order = 3)] + public int DaysToExit { get; set; } + } +}