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

63 lines
2.0 KiB
C#

#region Using declarations
using NinjaTrader.Cbi;
using NinjaTrader.NinjaScript.Indicators;
#endregion
namespace NinjaTrader.NinjaScript.Strategies
{
public class TenDayLowBot : Strategy
{
private MIN lows;
private SMA sma;
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;
}
else if (State == State.DataLoaded)
{
lows = MIN(Low, 10);
sma = SMA(10);
longTermTrend = SMA(200);
}
}
protected override void OnBarUpdate()
{
if (CurrentBar < 10)
return;
if (Low[0] == lows[0] && Close[0] > longTermTrend[0])
EnterLong();
if (Close[0] > sma[0])
ExitLong();
}
public override string DisplayName
{
get { return Name; }
}
}
}