Initial commit of Monthly Momentum Bot
This commit is contained in:
parent
8c6f91379c
commit
8445774d7c
60
strategies/MonthlyMomentumBot.cs
Normal file
60
strategies/MonthlyMomentumBot.cs
Normal file
@ -0,0 +1,60 @@
|
||||
#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; }
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user