Add high / low period parameters to Turtle Trading strategy

This commit is contained in:
moshferatu 2024-11-12 07:26:09 -08:00
parent d796bace40
commit 9ec7cc29ff

View File

@ -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; }
}
}