75 lines
2.5 KiB
C#
75 lines
2.5 KiB
C#
#region Using declarations
|
|
using NinjaTrader.Cbi;
|
|
using NinjaTrader.NinjaScript.Indicators;
|
|
using System.ComponentModel.DataAnnotations;
|
|
#endregion
|
|
|
|
namespace NinjaTrader.NinjaScript.Strategies
|
|
{
|
|
public class DoubleSevensBot : Strategy
|
|
{
|
|
private MAX highestClose;
|
|
private MIN lowestClose;
|
|
private SMA longTermTrend;
|
|
|
|
protected override void OnStateChange()
|
|
{
|
|
if (State == State.SetDefaults)
|
|
{
|
|
Description = @"Taken from chapter 10 of Short Term Trading Strategies That Work";
|
|
Name = "Double 7's 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;
|
|
|
|
Period = 7;
|
|
LongTermTrendPeriod = 200;
|
|
}
|
|
else if (State == State.DataLoaded)
|
|
{
|
|
highestClose = MAX(Close, Period);
|
|
lowestClose = MIN(Close, Period);
|
|
longTermTrend = SMA(LongTermTrendPeriod);
|
|
}
|
|
}
|
|
|
|
protected override void OnBarUpdate()
|
|
{
|
|
if (CurrentBar < LongTermTrendPeriod)
|
|
return;
|
|
|
|
if (Close[0] == lowestClose[0] && Close[0] > longTermTrend[0])
|
|
EnterLong();
|
|
|
|
if (Close[0] == highestClose[0])
|
|
ExitLong();
|
|
}
|
|
|
|
public override string DisplayName
|
|
{
|
|
get { return Name; }
|
|
}
|
|
|
|
[NinjaScriptProperty]
|
|
[Display(Name = "Period", GroupName = "Double 7's Bot", Order = 1)]
|
|
public int Period { get; set; }
|
|
|
|
[NinjaScriptProperty]
|
|
[Display(Name = "Long-Term Trend Period", GroupName = "Double 7's Bot", Order = 2)]
|
|
public int LongTermTrendPeriod { get; set; }
|
|
}
|
|
}
|