Initial commit of Short strategy
This commit is contained in:
parent
bfa9070a48
commit
652d9eac3f
86
strategies/short/ShortBot.cs
Normal file
86
strategies/short/ShortBot.cs
Normal file
@ -0,0 +1,86 @@
|
||||
#region Using declarations
|
||||
using NinjaTrader.Cbi;
|
||||
using NinjaTrader.NinjaScript.Indicators;
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
#endregion
|
||||
|
||||
namespace NinjaTrader.NinjaScript.Strategies
|
||||
{
|
||||
public class ShortBot : Strategy
|
||||
{
|
||||
private SMA longTermTrend;
|
||||
private SMA shortTermTrend;
|
||||
|
||||
protected override void OnStateChange()
|
||||
{
|
||||
if (State == State.SetDefaults)
|
||||
{
|
||||
Description = @"";
|
||||
Name = "Short 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;
|
||||
|
||||
LongTermTrendPeriod = 200;
|
||||
ShortTermTrendPeriod = 5;
|
||||
UpStreakPeriod = 4;
|
||||
}
|
||||
else if (State == State.DataLoaded)
|
||||
{
|
||||
longTermTrend = SMA(LongTermTrendPeriod);
|
||||
shortTermTrend = SMA(ShortTermTrendPeriod);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnBarUpdate()
|
||||
{
|
||||
if (CurrentBar < Math.Max(LongTermTrendPeriod, ShortTermTrendPeriod))
|
||||
return;
|
||||
|
||||
if (Position.MarketPosition == MarketPosition.Short && Close[0] < shortTermTrend[0])
|
||||
ExitShort();
|
||||
|
||||
if (Close[0] < longTermTrend[0])
|
||||
{
|
||||
for (int i = 0; i < UpStreakPeriod; i++)
|
||||
{
|
||||
if (Close[i] < Open[i])
|
||||
return;
|
||||
}
|
||||
|
||||
EnterShort();
|
||||
}
|
||||
}
|
||||
|
||||
public override string DisplayName
|
||||
{
|
||||
get { return Name; }
|
||||
}
|
||||
|
||||
[NinjaScriptProperty]
|
||||
[Display(Name = "Long-Term Trend Period", GroupName = "Short Bot", Order = 1)]
|
||||
public int LongTermTrendPeriod { get; set; }
|
||||
|
||||
[NinjaScriptProperty]
|
||||
[Display(Name = "Short-Term Trend Period", GroupName = "Short Bot", Order = 2)]
|
||||
public int ShortTermTrendPeriod { get; set; }
|
||||
|
||||
[NinjaScriptProperty]
|
||||
[Display(Name = "Up Streak Period", GroupName = "Short Bot", Order = 3)]
|
||||
public int UpStreakPeriod { get; set; }
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user