ninjatrader/strategies/end-of-month/EndOfMonthBot.cs

60 lines
2.0 KiB
C#

#region Using declarations
using NinjaTrader.Cbi;
using System.ComponentModel.DataAnnotations;
#endregion
namespace NinjaTrader.NinjaScript.Strategies
{
public class EndOfMonthBot : Strategy
{
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Taken from chapter 11 of Short Term Trading Strategies That Work";
Name = "End of Month 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;
EntryDay = 24;
DaysToExit = 5;
}
}
protected override void OnBarUpdate()
{
if (Time[0].Day == EntryDay)
EnterLong();
else if (BarsSinceEntryExecution() == DaysToExit)
ExitLong();
}
public override string DisplayName
{
get { return Name; }
}
[NinjaScriptProperty]
[Display(Name = "Entry Day of Month", GroupName = "End of Month Bot", Order = 1)]
public int EntryDay { get; set; }
[NinjaScriptProperty]
[Display(Name = "Days to Exit", GroupName = "End of Month Bot", Order = 2)]
public int DaysToExit { get; set; }
}
}