61 lines
2.0 KiB
C#
61 lines
2.0 KiB
C#
#region Using declarations
|
|
using System.ComponentModel.DataAnnotations;
|
|
using NinjaTrader.Cbi;
|
|
using NinjaTrader.NinjaScript.Indicators;
|
|
#endregion
|
|
|
|
// This strategy is intended to be run on a monthly chart.
|
|
namespace NinjaTrader.NinjaScript.Strategies
|
|
{
|
|
public class MonthlyMomentumBot : Strategy
|
|
{
|
|
private SMA sma;
|
|
|
|
protected override void OnStateChange()
|
|
{
|
|
if (State == State.SetDefaults)
|
|
{
|
|
Description = @"";
|
|
Name = "Monthly Momentum 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;
|
|
|
|
SMAPeriod = 12;
|
|
}
|
|
else if (State == State.DataLoaded)
|
|
{
|
|
sma = SMA(SMAPeriod);
|
|
}
|
|
}
|
|
|
|
protected override void OnBarUpdate()
|
|
{
|
|
if (CurrentBar < SMAPeriod)
|
|
return;
|
|
|
|
if (CrossAbove(Close, sma, 1))
|
|
EnterLong();
|
|
else if (CrossBelow(Close, sma, 1))
|
|
ExitLong();
|
|
}
|
|
|
|
[NinjaScriptProperty]
|
|
[Display(Name = "SMA Period", GroupName = "Monthly Momentum Bot", Order = 1)]
|
|
public int SMAPeriod { get; set; }
|
|
}
|
|
}
|