Announcement

Collapse
No announcement yet.

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.


    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 NullPointStrategies, Today, 05:17 AM
      0 responses
      52 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      130 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      70 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      44 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      48 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X