Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy problems with enabled, enters orders

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

    Strategy problems with enabled, enters orders


    Hi Everyone,

    I am creating a strategy where a specific point is analyzed for the price, and an order is placed at a specific level. If the price approaches the order but it is not executed, the order is moved to another point. However, when I try to enable the strategy, I receive an error indicating issues with the SubmitOrderUnmanaged method.

    Can you help me?
    ​​Click image for larger version

Name:	image.png
Views:	103
Size:	14.2 KB
ID:	1326612
    My Code


    protected override void OnBarUpdate()
    {
    if (CurrentBar < 1 || State != State.Realtime)
    return;

    dailyHigh = Math.Max(dailyHigh, High[0]);
    dailyLow = Math.Min(dailyLow, Low[0]);

    entryPriceSell = dailyHigh + 10 * TickSize;
    entryPriceBuy = dailyLow - 10 * TickSize;

    if (double.IsNaN(entryPriceSell) || double.IsNaN(entryPriceBuy))
    return;

    if (Position.MarketPosition == MarketPosition.Flat)
    {
    CancelAllPendingOrders();

    SubmitOrderUnmanaged(0, OrderAction.Sell, OrderType.Limit, 1, entryPriceSell, 0, "", "SellLimit");
    SubmitOrderUnmanaged(0, OrderAction.Buy, OrderType.Limit, 1, entryPriceBuy, 0, "", "BuyLimit");
    }

    // Plota linhas de preço
    PlotOrderLines();
    }

    Thanks a lot!

    #2
    Hello tfa2806trader,

    To use SubmitOrderUnmanaged, the IsUnmanaged needs to be set to true.
    Join the official NinjaScript Developer Community for comprehensive resources, documentation, and community support. Build custom indicators and automated strategies for the NinjaTrader platforms with our extensive guides and APIs.


    I recommend setting IsUnmanaged to true in State.Configure.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Chelsea B.

      thanks you for your attention!

      My IsUnmanaged is true, but error continue.

      Click image for larger version

Name:	image.png
Views:	87
Size:	12.9 KB
ID:	1326643
      my code ​


      protected override void OnStateChange()
      {
      if (State == State.SetDefaults)
      {
      Description = "Robô para operar baseado na máxima e mínima do dia no NQ.";
      Name = "NQMaxMinBot";
      Calculate = Calculate.OnEachTick;
      EntriesPerDirection = 1;
      IsUnmanaged = true;
      IsInstantiatedOnEachOptimizationIteration = false;
      }
      else if (State == State.Configure)
      {
      SetStopLoss(CalculationMode.Ticks, 20); // Stop Loss de 20 ticks
      SetProfitTarget(CalculationMode.Ticks, 40); // Take Profit de 40 ticks
      }
      }​
      Attached Files

      Comment


        #4
        Hello tfa2806trader,

        You set this to true in State.SetDefaults instead of State.Configure as I suggested in post # 2.

        This means you will need to remove the script instance from the chart Strategies window, and add a new instance.

        (It would be easier to just set this in State.Configure as I have already suggested, and then compile and reload the script.)
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Sorry, I dont understand...

          Comment


            #6
            Hello tfa2806trader,

            In your code:

            protected override void OnStateChange()
            {
            if (State == State.SetDefaults)
            {
            Description = "Robô para operar baseado na máxima e mínima do dia no NQ.";
            Name = "NQMaxMinBot";
            Calculate = Calculate.OnEachTick;
            EntriesPerDirection = 1;
            IsUnmanaged = true;
            IsInstantiatedOnEachOptimizationIteration = false;
            }
            else if (State == State.Configure)
            {
            SetStopLoss(CalculationMode.Ticks, 20); // Stop Loss de 20 ticks
            SetProfitTarget(CalculationMode.Ticks, 40); // Take Profit de 40 ticks
            }
            }​
            I've suggested assigning IsUnmanaged to true in State.Configure.
            You have done this in the logic block for State.SetDefaults as shown in your code.
            Either assign this from State.Configure as suggested, or remove the instance of the strategy from the Strategies window of the chart and add a new instance.​
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              I Change my code, but other error in setstoploss. My setstopp is parameter in my code.

              My code is attach! Can you look and help me?​


              Click image for larger version

Name:	image.png
Views:	75
Size:	15.7 KB
ID:	1326666
              Attached Files

              Comment


                #8
                Hello tfa2806trader,

                This is an unmanaged strategy. You cannot use SetStopLoss() or any managed approach order methods.
                Unmanaged strategies use SubmitOrderUnmanaged() to submit orders only.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9

                  How do I use a managed order strategy?​

                  Comment


                    #10
                    Hello tfa2806trader,

                    SubmitOrderUnmanaged() cannot be used in a managed strategy.

                    You would need to use managed approach order methods (like EnterLong()/ExitLong()) and set IsUnmanaged to false in State.Configure.
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Can you give me an example? Please!

                      Comment


                        #12
                        Hello tfa2806trader,

                        Below is a link to managed strategies using Exit orders and unmanaged strategies.

                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          Nice! Thanks for your help!

                          Have a good day!

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by argusthome, 03-08-2026, 10:06 AM
                          0 responses
                          116 views
                          0 likes
                          Last Post argusthome  
                          Started by NabilKhattabi, 03-06-2026, 11:18 AM
                          0 responses
                          61 views
                          0 likes
                          Last Post NabilKhattabi  
                          Started by Deep42, 03-06-2026, 12:28 AM
                          0 responses
                          40 views
                          0 likes
                          Last Post Deep42
                          by Deep42
                           
                          Started by TheRealMorford, 03-05-2026, 06:15 PM
                          0 responses
                          43 views
                          0 likes
                          Last Post TheRealMorford  
                          Started by Mindset, 02-28-2026, 06:16 AM
                          0 responses
                          82 views
                          0 likes
                          Last Post Mindset
                          by Mindset
                           
                          Working...
                          X