ninjatrader/strategies/TurtleTradingBot.cs

63 lines
2.1 KiB
C#
Raw Normal View History

#region Using declarations
using NinjaTrader.Cbi;
#endregion
//This namespace holds Strategies in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Strategies
{
public class TurtleTradingBot : Strategy
{
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Bot based on the Turtle trading method by Richard Dennis and William Eckhardt";
Name = "Turtle Trading Bot";
Calculate = Calculate.OnBarClose;
EntriesPerDirection = 1;
EntryHandling = EntryHandling.AllEntries;
IsExitOnSessionCloseStrategy = true;
ExitOnSessionCloseSeconds = 30;
IsFillLimitOnTouch = false;
MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
OrderFillResolution = OrderFillResolution.Standard;
Slippage = 0;
StartBehavior = StartBehavior.WaitUntilFlat;
TimeInForce = TimeInForce.Gtc;
TraceOrders = false;
RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
StopTargetHandling = StopTargetHandling.PerEntryExecution;
BarsRequiredToTrade = 20;
IsInstantiatedOnEachOptimizationIteration = true;
}
}
protected override void OnBarUpdate()
{
if (CurrentBar < BarsRequiredToTrade)
return;
if (Close[0] > MAX(High, 20)[1])
EnterLong();
/*else if (Close[0] < MIN(Low, 20)[1])
EnterShort();*/
if (Position.MarketPosition == MarketPosition.Long)
{
if (Close[0] < MIN(Low, 10)[1])
ExitLong();
}
/*else if (Position.MarketPosition == MarketPosition.Short)
{
if (Close[0] > MAX(High, 10)[1])
ExitShort();
}*/
}
public override string DisplayName
{
get { return Name; }
}
}
}