Initial commit of Down Days in a Row strategy
This commit is contained in:
parent
908be34feb
commit
a16dbf3cbd
55
strategies/up-and-down-days-in-a-row/DownDaysInARow.cs
Normal file
55
strategies/up-and-down-days-in-a-row/DownDaysInARow.cs
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
#region Using declarations
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
namespace NinjaTrader.NinjaScript.Strategies
|
||||||
|
{
|
||||||
|
public class DownDaysInARow : Strategy
|
||||||
|
{
|
||||||
|
private int downDayStreak;
|
||||||
|
|
||||||
|
protected override void OnStateChange()
|
||||||
|
{
|
||||||
|
if (State == State.SetDefaults)
|
||||||
|
{
|
||||||
|
Name = "Down Days in a Row";
|
||||||
|
Description = @"Based on chatper 4 of How Markets Really Work (2012) by Larry Connors";
|
||||||
|
Calculate = Calculate.OnBarClose;
|
||||||
|
EntriesPerDirection = 1;
|
||||||
|
|
||||||
|
DaysInARow = 3;
|
||||||
|
DaysToExit = 5;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnBarUpdate()
|
||||||
|
{
|
||||||
|
if (CurrentBar < DaysInARow)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (Close[0] < Close[1])
|
||||||
|
downDayStreak++;
|
||||||
|
else
|
||||||
|
downDayStreak = 0;
|
||||||
|
|
||||||
|
if (downDayStreak >= DaysInARow)
|
||||||
|
EnterLong();
|
||||||
|
|
||||||
|
if (BarsSinceEntryExecution() >= DaysToExit)
|
||||||
|
ExitLong();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string DisplayName
|
||||||
|
{
|
||||||
|
get { return Name; }
|
||||||
|
}
|
||||||
|
|
||||||
|
[NinjaScriptProperty]
|
||||||
|
[Display(Name = "Days in a Row", GroupName = "Down Days in a Row", Order = 1)]
|
||||||
|
public int DaysInARow { get; set; }
|
||||||
|
|
||||||
|
[NinjaScriptProperty]
|
||||||
|
[Display(Name = "Days to Exit", GroupName = "Down Days in a Row", Order = 2)]
|
||||||
|
public int DaysToExit { get; set; }
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user