From 9ec7cc29ff7fc45f0dd214de34a70f3ed7223bd0 Mon Sep 17 00:00:00 2001 From: moshferatu Date: Tue, 12 Nov 2024 07:26:09 -0800 Subject: [PATCH] Add high / low period parameters to Turtle Trading strategy --- strategies/turtle-trading/TurtleTradingBot.cs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/strategies/turtle-trading/TurtleTradingBot.cs b/strategies/turtle-trading/TurtleTradingBot.cs index 1f6e541..bad2d0f 100644 --- a/strategies/turtle-trading/TurtleTradingBot.cs +++ b/strategies/turtle-trading/TurtleTradingBot.cs @@ -1,5 +1,6 @@ #region Using declarations using NinjaTrader.Cbi; +using System.ComponentModel.DataAnnotations; #endregion namespace NinjaTrader.NinjaScript.Strategies @@ -14,6 +15,9 @@ namespace NinjaTrader.NinjaScript.Strategies Description = @"Based on the Turtle Trading method by Richard Dennis and William Eckhardt"; Calculate = Calculate.OnBarClose; EntriesPerDirection = 1; + + HighPeriod = 20; + LowPeriod = 10; } } @@ -22,12 +26,12 @@ namespace NinjaTrader.NinjaScript.Strategies if (CurrentBar < BarsRequiredToTrade) return; - if (Close[0] > MAX(High, 20)[1]) + if (Close[0] > MAX(High, HighPeriod)[1]) EnterLong(); if (Position.MarketPosition == MarketPosition.Long) { - if (Close[0] < MIN(Low, 10)[1]) + if (Close[0] < MIN(Low, LowPeriod)[1]) ExitLong(); } } @@ -36,5 +40,13 @@ namespace NinjaTrader.NinjaScript.Strategies { get { return Name; } } + + [NinjaScriptProperty] + [Display(Name = "High Period", GroupName = "Turtle Trading Bot", Order = 1)] + public int HighPeriod { get; set; } + + [NinjaScriptProperty] + [Display(Name = "Low Period", GroupName = "Turtle Trading Bot", Order = 2)] + public int LowPeriod { get; set; } } }