ninjatrader/strategies/turtle-trading/TurtleTradingBot.cs

53 lines
1.4 KiB
C#

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