This strategy generates right orders when I am flat,
but if I have an open position and I get opposite signal it is ignored.
So is it possible to reverse open position?
I am a complete newbie.
thank you.
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Indicator;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Strategy;
#endregion
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
/// <summary>
/// Enter the description of your strategy here
/// </summary>
[Description("Enter the description of your strategy here")]
public class EMA10 : Strategy
{
#region Variables
// Wizard generated variables
// 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()
{
SetProfitTarget("", CalculationMode.Ticks, 50);
SetTrailStop("", CalculationMode.Ticks, 50, false);
CalculateOnBarClose = false;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
if(FirstTickOfBar)
{
// Condition set 1
if (Close[1] <= Open[1]
&& High[1] > EMA(50)[1]
&& Low[1] < EMA(50)[1])
{
EnterLongStop(DefaultQuantity, Close[1] + 10 * TickSize, "");
}
// Condition set 2
if (Close[1] >= Open[1]
&& High[1] > EMA(50)[1]
&& Low[1] < EMA(50)[1])
{
EnterShortStop(DefaultQuantity, Close[1] + -10 * TickSize, "");
}
}
}
#region Properties
#endregion
}
}
Comment