// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
/// <summary>
/// Using 2 EMAs, Stochastics and Momentum as Entry
/// </summary>
[Description("Using 2 EMAs, Stochastics and Momentum as Entry")]
public class MyCustomTIStrategy : Strategy
{
#region Variables
// Wizard generated variables
private int eMAFast = 8; // Default setting for EMAFast
private int eMASlow = 20; // Default setting for EMASlow
private int adxPedriod = 14; // Default setting for AdxPedriod
private int adxValue = 30; // Default setting for AdxValue
private int momentumPara = 14; // Default setting for MomentumPara
// User defined variables (add any user defined variables below)
#endregion
/// <summary>
/// This method is used to configure the strategy and is called once before any strategy method is called.
/// </summary>
protected override void Initialize()
{
Add(EMA(EMASlow));
Add(EMA(EMAFast));
Add(ADX(14));
Add(Momentum(14));
Add(EMA(EMASlow));
Add(EMA(EMAFast));
Add(ADX(14));
Add(Momentum(14));
SetProfitTarget("LongTI", CalculationMode.Percent, 0.01);
SetProfitTarget("ShortTI", CalculationMode.Percent, 0.01);
SetStopLoss("LongTI", CalculationMode.Price, 10, false);
SetStopLoss("ShortTI", CalculationMode.Price, 10, false);
CalculateOnBarClose = true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Condition set 1
if (CrossAbove(EMA(EMASlow), EMA(EMAFast), 1)
&& ADX(14)[0] > ADX(14)[1]
&& ADX(14)[0] > 20
&& Momentum(14)[0] > Momentum(14)[1])
{
EnterLong(100, "LongTI");
DrawDiamond("My diamond" + CurrentBar, false, 0, 1, Color.LimeGreen);
}
// Condition set 2
if (CrossBelow(EMA(EMASlow), EMA(EMAFast), 1)
&& ADX(14)[0] < ADX(14)[1]
&& ADX(14)[0] > 20
&& Momentum(14)[0] < Momentum(14)[1])
{
EnterShort(100, "ShortTI");
DrawDiamond("My diamond" + CurrentBar, false, 0, 1, Color.Red);
}
}
When I backtested this strategy, it kept exiting right at the same price on the same bar on stoploss order. Can you guys help me?
Comment