Initial commit of Engulfing strategy
This commit is contained in:
parent
ddb80ecd9e
commit
fea62f40df
51
strategies/engulfing/EngulfingBot.cs
Normal file
51
strategies/engulfing/EngulfingBot.cs
Normal file
@ -0,0 +1,51 @@
|
||||
#region Using declarations
|
||||
using NinjaTrader.Cbi;
|
||||
using NinjaTrader.NinjaScript.Indicators;
|
||||
#endregion
|
||||
|
||||
namespace NinjaTrader.NinjaScript.Strategies
|
||||
{
|
||||
public class EngulfingBot : Strategy
|
||||
{
|
||||
private SMA LongTermTrend;
|
||||
|
||||
protected override void OnStateChange()
|
||||
{
|
||||
if (State == State.SetDefaults)
|
||||
{
|
||||
Name = "Engulfing Bot";
|
||||
Description = @"Simple strategy based on the engulfing candle pattern";
|
||||
Calculate = Calculate.OnBarClose;
|
||||
EntriesPerDirection = 1;
|
||||
}
|
||||
else if (State == State.DataLoaded)
|
||||
{
|
||||
LongTermTrend = SMA(200);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnBarUpdate()
|
||||
{
|
||||
if (CurrentBar < BarsRequiredToTrade)
|
||||
return;
|
||||
|
||||
if (High[0] > High[1] && Close[0] < Low[1])
|
||||
{
|
||||
if (Close[0] >= LongTermTrend[0])
|
||||
EnterLong();
|
||||
else
|
||||
EnterShort();
|
||||
}
|
||||
|
||||
if (Position.MarketPosition == MarketPosition.Long && (Close[0] > Position.AveragePrice || Close[0] > High[1]))
|
||||
ExitLong();
|
||||
else if (Position.MarketPosition == MarketPosition.Short && (Close[0] < Position.AveragePrice || Close[0] < Low[1]))
|
||||
ExitShort();
|
||||
}
|
||||
|
||||
public override string DisplayName
|
||||
{
|
||||
get { return Name; }
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user