i am looking to have my ATM strategy to be triggered by a Ninja Script, which is very simple.
Go long or short on cross above of two EMA's and exit long or short on a cross of the opposite direction.
when the position is open i need this position to be managed by my ATM strategy. and whatever shares are left open to be closed by NT on the opposite cross.
So far the script i have triggers on the crossover, and the ATM strategy i need. But it does not close the position in the opposite cross. Please have a look at my script below and advise me how to rectify this problem
Your time and efforts are greatly appreciated. PLEASE let me know.
Thanks
NT SCRIPT:
#region Using declarations
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 LONG & EXIT LONG ONLY
/// </summary>
[Description("ENTER LONG & EXIT LONG ONLY")]
public class LONG : Strategy
{
#region Variables
// Wizard generated variables
private int fAST = 15; // Default setting for FAST
private int sLOW = 35; // Default setting for SLOW
// 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()
{
CalculateOnBarClose = true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Condition set 1
if (CrossAbove(EMA(15), EMA(35), 1))
{
//string a = "b12345";
string a = GetAtmStrategyUniqueId();
string orderId = GetAtmStrategyUniqueId();
AtmStrategyCreate(Action.Buy, OrderType.Market, 0, 0,TimeInForce.Day, orderId, "TNA 50 SHARES",GetAtmStrategyUniqueId());
Alert("CROSS ABOVE", Priority.High, "TNA ENTER LONG", "", 0, Color.White, Color.Black);
}
// Condition set 2
//if (atmStrategyId.Length > 0 && GetAtmStrategyMarketPosition(atmStrategyId) == Cbi.MarketPosition.Flat)
if (CrossBelow(EMA(15), EMA(35), 1))
{
//AtmStrategyClose(a);
//AtmStrategyChangeStopTarget(0, EMA(15)[0], "STOP1",GetAtmStrategyUniqueId() );
//ExitLong();
Alert("EXIT LONG", Priority.High, "TNA EXIT LONG", "", 0, Color.White, Color.Black);
}
}
#region Properties
[Description("")]
[Category("Parameters")]
public int FAST
{
get { return fAST; }
set { fAST = Math.Max(18, value); }
}
[Description("")]
[Category("Parameters")]
public int SLOW
{
get { return sLOW; }
set { sLOW = Math.Max(25, value); }
}
#endregion
}
}
Comment