ninjatrader/strategies/knife-catcher/KnifeCatcherBot.cs

52 lines
1.7 KiB
C#

#region Using declarations
using NinjaTrader.Cbi;
#endregion
namespace NinjaTrader.NinjaScript.Strategies
{
public class KnifeCatcherBot : Strategy
{
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Strategy taken from chapter 3 of Short Term Trading Strategies That Work";
Name = "Knife Catcher 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 < 3)
return;
if (Close[0] < Close[1] && Close[1] < Close[2] && Close[2] < Close[3])
EnterLong();
if (BarsSinceEntryExecution() >= 5)
ExitLong();
}
public override string DisplayName
{
get { return Name; }
}
}
}