2024-08-30 15:01:00 +00:00
|
|
|
#region Using declarations
|
|
|
|
using NinjaTrader.Cbi;
|
2024-08-30 15:25:56 +00:00
|
|
|
using System.ComponentModel.DataAnnotations;
|
2024-08-30 15:01:00 +00:00
|
|
|
#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;
|
2024-08-30 15:25:56 +00:00
|
|
|
|
|
|
|
BarsToExit = 5;
|
2024-08-30 15:01:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnBarUpdate()
|
|
|
|
{
|
|
|
|
if (CurrentBar < 3)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (Close[0] < Close[1] && Close[1] < Close[2] && Close[2] < Close[3])
|
|
|
|
EnterLong();
|
|
|
|
|
2024-08-30 15:25:56 +00:00
|
|
|
if (BarsSinceEntryExecution() >= BarsToExit)
|
2024-08-30 15:01:00 +00:00
|
|
|
ExitLong();
|
|
|
|
}
|
|
|
|
|
|
|
|
public override string DisplayName
|
|
|
|
{
|
|
|
|
get { return Name; }
|
|
|
|
}
|
2024-08-30 15:25:56 +00:00
|
|
|
|
|
|
|
[NinjaScriptProperty]
|
|
|
|
[Display(Name = "Bars to Exit", GroupName = "Knife Catcher Bot", Order = 1)]
|
|
|
|
public int BarsToExit { get; set; }
|
2024-08-30 15:01:00 +00:00
|
|
|
}
|
|
|
|
}
|