Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Stumped: "SubmitOrderUnmanaged' method can't be called on managed strategies."

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Stumped: "SubmitOrderUnmanaged' method can't be called on managed strategies."

    Okay, I'm stuck.

    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:

    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;
    }
    }
    }
    }
    }

    #2
    Hello Spiderbird,

    Thanks for the post.

    Have you removed and re applied the strategy since you added the IsUnmanaged = true? I see the strategy working on my end.

    I look forward to being of further assistance.


    JesseNinjaTrader Customer Service

    Comment


      #3
      Oddly enough, that did the trick. I also created a managed script and that worked as well.

      I think it was because I was adding a data series to the script that caused it to give that error (besides the primary one). I'll have to experiment with that going forward to see if that's going to junk up unmanaged scripts I write.

      Thank you for the prompt reply!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Mupulen, 04-16-2024, 11:26 AM
      1 response
      54 views
      0 likes
      Last Post techbech  
      Started by Quanto, Today, 02:17 PM
      1 response
      7 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by cmtjoancolmenero, 04-25-2024, 03:58 PM
      24 responses
      126 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by Skifree, Today, 11:21 AM
      3 responses
      11 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by manueldecastro, Today, 01:16 PM
      3 responses
      14 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Working...
      X