2024-06-10 14:34:17 +00:00
|
|
|
#region Using declarations
|
|
|
|
using NinjaTrader.Cbi;
|
2024-11-12 15:26:09 +00:00
|
|
|
using System.ComponentModel.DataAnnotations;
|
2024-06-10 14:34:17 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
namespace NinjaTrader.NinjaScript.Strategies
|
|
|
|
{
|
|
|
|
public class TurtleTradingBot : Strategy
|
|
|
|
{
|
|
|
|
protected override void OnStateChange()
|
|
|
|
{
|
|
|
|
if (State == State.SetDefaults)
|
|
|
|
{
|
|
|
|
Name = "Turtle Trading Bot";
|
2024-11-11 16:00:04 +00:00
|
|
|
Description = @"Based on the Turtle Trading method by Richard Dennis and William Eckhardt";
|
2024-06-10 14:34:17 +00:00
|
|
|
Calculate = Calculate.OnBarClose;
|
|
|
|
EntriesPerDirection = 1;
|
2024-11-12 15:26:09 +00:00
|
|
|
|
|
|
|
HighPeriod = 20;
|
|
|
|
LowPeriod = 10;
|
2024-06-10 14:34:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnBarUpdate()
|
|
|
|
{
|
|
|
|
if (CurrentBar < BarsRequiredToTrade)
|
|
|
|
return;
|
|
|
|
|
2024-11-12 15:26:09 +00:00
|
|
|
if (Close[0] > MAX(High, HighPeriod)[1])
|
2024-06-10 14:34:17 +00:00
|
|
|
EnterLong();
|
|
|
|
|
|
|
|
if (Position.MarketPosition == MarketPosition.Long)
|
|
|
|
{
|
2024-11-12 15:26:09 +00:00
|
|
|
if (Close[0] < MIN(Low, LowPeriod)[1])
|
2024-06-10 14:34:17 +00:00
|
|
|
ExitLong();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public override string DisplayName
|
|
|
|
{
|
|
|
|
get { return Name; }
|
|
|
|
}
|
2024-11-12 15:26:09 +00:00
|
|
|
|
|
|
|
[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; }
|
2024-06-10 14:34:17 +00:00
|
|
|
}
|
|
|
|
}
|