I have an experiment script that by all intents and purposes is coded to be unmanaged. Yet NT is staying it's managed and I can't figure out why. Can anyone help give some guidance when looking at this code?
-----
Code:
#region Using declarations
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Gui;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Gui.SuperDom;
using NinjaTrader.Gui.Tools;
using NinjaTrader.Data;
using NinjaTrader.NinjaScript;
using NinjaTrader.Core.FloatingPoint;
using NinjaTrader.NinjaScript.Indicators;
using NinjaTrader.NinjaScript.DrawingTools;
#endregion
//This namespace holds Strategies in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Strategies.PandaPower_Janu ary
{
public class DBot1 : Strategy
{
double ema_5;
double ema_10;
double ema_5_Prev;
double ema_10_Prev;
byte orderCount;
byte orderStop;
private Order longOrder = null;
private Order shortOrder = null;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"A very simple strategy that trades the EMA5 crossover";
Name = "DBot1";
Calculate = Calculate.OnEachTick;
EntriesPerDirection = 1;
EntryHandling = EntryHandling.AllEntries;
IsExitOnSessionCloseStrategy = true;
ExitOnSessionCloseSeconds = 30;
IsFillLimitOnTouch = true;
MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
OrderFillResolution = OrderFillResolution.Standard;
Slippage = 0;
StartBehavior = StartBehavior.WaitUntilFlat;
TimeInForce = TimeInForce.Gtc;
TraceOrders = false;
RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
StopTargetHandling = StopTargetHandling.PerEntryExecution;
BarsRequiredToTrade = 20;
IsUnmanaged = true; // added for unmanaged trade state
// Disable this property for performance gains in Strategy Analyzer optimizations
// See the Help Guide for additional information
IsInstantiatedOnEachOptimizationIteration = true;
}
else if (State == State.Configure)
// Configure is called after a user adds an object to the applied list of objects.
// • Add additional data series via AddDataSeries()
// • Declare custom resources
{
}
}
protected override void OnBarUpdate()
{
if (IsFirstTickOfBar) // If this is the first tick of a new bar, start all this material
{
if (CurrentBars[0] < BarsRequiredToTrade)
return;
ema_5 = Math.Round(EMA(5)[1],2);
ema_5_Prev = Math.Round(EMA(5)[2],2);
ema_10 = Math.Round(EMA(10)[1],2);
ema_10_Prev = Math.Round(EMA(10)[2],2);
// If our order is stopped, wait until the EMA lines are looking strong in either direction.
if (orderStop == 1)
{
if ((ema_5 > ema_5_Prev
&& ema_10 > ema_10_Prev
&& ema_5 - ema_10 > .10)
||
(ema_5 < ema_5_Prev
&& ema_10 < ema_10_Prev
&& ema_10 - ema_5 > .10))
{
orderStop = 0;
}
}
// If we're not in the market, get into position once the ema_5 is above or below the ema10 line
if (Position.MarketPosition == MarketPosition.Flat && orderStop != 1)
{
if (ema_5 > ema_10)
{
longOrder = SubmitOrderUnmanaged(0, OrderAction.Buy, OrderType.Market, 50, 0, 0, "", "");
orderCount++;
}
else if (ema_5 < ema_10)
{
shortOrder = SubmitOrderUnmanaged(0, OrderAction.Sell, OrderType.Market, 50, 0, 0, "", "");
orderCount++;
}
}
// If we're long, get out if we cross the ema_10 downward.
// Otherwise, reduce the orderCount for every tick we stay in the order.
else if (Position.MarketPosition == MarketPosition.Long)
{
if (ema_5 < ema_10)
{
shortOrder = SubmitOrderUnmanaged(0, OrderAction.Sell, OrderType.Market, Position.Quantity, 0, 0, "", "");
orderCount++;
}
else
{
orderCount--;
}
}
// If we're short, get out if we cross the ema_10 upward.
// Otherwise, reduce the orderCount for every tick we stay in the order.
else if (Position.MarketPosition == MarketPosition.Short)
{
if (ema_5 > ema_10)
{
longOrder = SubmitOrderUnmanaged(0, OrderAction.Buy, OrderType.Market, Position.Quantity, 0, 0, "", "");
orderCount++;
}
else
{
orderCount--;
}
}
// If we get in and out of an order in two straight ticks, put a cap on it and wait till both are in alignment.
if (orderCount >= 2)
{
orderCount = 0;
orderStop = 1;
}
}
}
}
}

Comment