ninjatrader/strategies/10-day-low/TenDayLowBot.cs

80 lines
2.7 KiB
C#
Raw Permalink Normal View History

#region Using declarations
using NinjaTrader.Cbi;
using NinjaTrader.NinjaScript.Indicators;
2024-08-30 12:28:35 +00:00
using System.ComponentModel.DataAnnotations;
#endregion
namespace NinjaTrader.NinjaScript.Strategies
{
public class TenDayLowBot : Strategy
{
private MIN lows;
2024-08-30 12:28:35 +00:00
private SMA shortTermTrend;
private SMA longTermTrend;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Strategy taken from chapter 2 of Short Term Trading Strategies That Work";
Name = "10 Day Low 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 12:28:35 +00:00
LowPeriod = 10;
ShortTermTrendPeriod = 10;
LongTermTrendPeriod = 200;
}
else if (State == State.DataLoaded)
{
2024-08-30 12:28:35 +00:00
lows = MIN(Low, LowPeriod);
shortTermTrend = SMA(ShortTermTrendPeriod);
longTermTrend = SMA(LongTermTrendPeriod);
}
}
protected override void OnBarUpdate()
{
2024-08-30 12:28:35 +00:00
if (CurrentBar < LowPeriod)
return;
if (Low[0] == lows[0] && Close[0] > longTermTrend[0])
EnterLong();
2024-08-30 12:28:35 +00:00
if (Close[0] > shortTermTrend[0])
ExitLong();
}
public override string DisplayName
{
get { return Name; }
}
2024-08-30 12:28:35 +00:00
[NinjaScriptProperty]
[Display(Name = "Low Period", GroupName = "10-Day Low Bot", Order = 1)]
public int LowPeriod { get; set; }
[NinjaScriptProperty]
[Display(Name = "Short Term Trend Period", GroupName = "10-Day Low Bot", Order = 2)]
public int ShortTermTrendPeriod { get; set; }
[NinjaScriptProperty]
[Display(Name = "Long Term Trend Period", GroupName = "10-Day Low Bot", Order = 3)]
public int LongTermTrendPeriod { get; set; }
}
}