58 lines
1.6 KiB
C#
58 lines
1.6 KiB
C#
|
#region Using declarations
|
||
|
using NinjaTrader.NinjaScript.Indicators;
|
||
|
using System.ComponentModel.DataAnnotations;
|
||
|
#endregion
|
||
|
|
||
|
namespace NinjaTrader.NinjaScript.Strategies
|
||
|
{
|
||
|
public class ShortTermLows : Strategy
|
||
|
{
|
||
|
private MIN shortTermLows;
|
||
|
private SMA longTermTrend;
|
||
|
|
||
|
protected override void OnStateChange()
|
||
|
{
|
||
|
if (State == State.SetDefaults)
|
||
|
{
|
||
|
Name = "Short-Term Lows";
|
||
|
Description = @"Based on chatper 2 of How Markets Really Work (2012) by Larry Connors";
|
||
|
Calculate = Calculate.OnBarClose;
|
||
|
EntriesPerDirection = 1;
|
||
|
|
||
|
LowPeriod = 10;
|
||
|
LongTermTrendPeriod = 200;
|
||
|
}
|
||
|
else if (State == State.DataLoaded)
|
||
|
{
|
||
|
shortTermLows = MIN(Low, LowPeriod);
|
||
|
longTermTrend = SMA(LongTermTrendPeriod);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
protected override void OnBarUpdate()
|
||
|
{
|
||
|
if (CurrentBar < LowPeriod)
|
||
|
return;
|
||
|
|
||
|
if (Low[0] == shortTermLows[0])
|
||
|
EnterLong();
|
||
|
|
||
|
if (BarsSinceEntryExecution() >= 5)
|
||
|
ExitLong();
|
||
|
}
|
||
|
|
||
|
public override string DisplayName
|
||
|
{
|
||
|
get { return Name; }
|
||
|
}
|
||
|
|
||
|
[NinjaScriptProperty]
|
||
|
[Display(Name = "Low Period", GroupName = "Short-Term Lows", Order = 1)]
|
||
|
public int LowPeriod { get; set; }
|
||
|
|
||
|
[NinjaScriptProperty]
|
||
|
[Display(Name = "Long-Term Trend Period", GroupName = "Short-Term Lows", Order = 2)]
|
||
|
public int LongTermTrendPeriod { get; set; }
|
||
|
}
|
||
|
}
|