Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

atm

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

    #16
    You don't need to answer the above, it's already solved.
    Now I have a problem that I don't know how to solve, no matter how easy it may seem.
    private void CancelarOredenes()
    {
    submissionAccount.CancelAllOrders(instrumentSelect or.Instrument);

    foreach (var position in submissionAccount.Positions)
    {
    if (position.MarketPosition != MarketPosition.Flat)
    {
    position.MarketPosition = MarketPosition.Flat;
    }
    }
    }/// FALTA CANCELAR LA POSICION

    I have created a button with which I intend to close all the orders but it does not close the open positions, can you tell me how to do it?​

    Comment


      #17
      Originally posted by franatas View Post
      You don't need to answer the above, it's already solved.
      Now I have a problem that I don't know how to solve, no matter how easy it may seem.
      private void CancelarOredenes()
      {
      submissionAccount.CancelAllOrders(instrumentSelect or.Instrument);

      foreach (var position in submissionAccount.Positions)
      {
      if (position.MarketPosition != MarketPosition.Flat)
      {
      position.MarketPosition = MarketPosition.Flat;
      }
      }
      }/// FALTA CANCELAR LA POSICION

      I have created a button with which I intend to close all the orders but it does not close the open positions, can you tell me how to do it?​
      Thank you for your note.

      I apologize for the delay in regard to the previous post - I am glad to hear it is solved. As for closing open positions, you could add a check for if the position is long, then submit an order to Sell for the position's quantity or if the position is short, submit a BuyToCover order to buy the position's quantity. For example:

      Code:
      if (position.MarketPosition != MarketPosition.Flat)
      {​[INDENT]if (position.MarketPosition == MarketPosition.Long)
      {
      // create a Sell Market order for the position.Quantity
      // submit the Sell Market order
      }
      if (position.MarketPosition == MarketPosition.Short)
      {
      // create a BuyToCover Market order for the position.Quantity
      // submit the BuyToCover Market order
      }[/INDENT]
       }
      Please let us know if we may be of further assistance.

      Comment


        #18
        private void CancelarOredenes()
        {
        submissionAccount.CancelAllOrders(instrumentSelect or.Instrument);

        foreach (var position in submissionAccount.Positions)
        {
        if (position.MarketPosition == MarketPosition.Flat)
        {
        if (position.MarketPosition == MarketPosition.Long)
        {
        OrdenCierre = submissionAccount.CreateOrder(instrumentSelector.I nstrument, OrderAction.Sell, OrderType.Market, OrderEntry.Automated, TimeInForce.Day, position.Quantity, 0, 0, string.Empty, "CIERRE MANUAL", Globals.MaxDate, null);
        submissionAccount.Submit(new[] { OrdenCierre });
        }
        if (position.MarketPosition == MarketPosition.Short)
        {
        OrdenCierre = submissionAccount.CreateOrder(instrumentSelector.I nstrument, OrderAction.Buy, OrderType.Market, OrderEntry.Automated, TimeInForce.Day, position.Quantity, 0, 0, string.Empty, "CIERRE MANUAL", Globals.MaxDate, null);
        submissionAccount.Submit(new[] { OrdenCierre });
        }
        }
        }
        }​
        It doesn't work and I can't find the problem, you can review it to see where I went wrong.

        Comment


          #19
          if (position.MarketPosition != MarketPosition.Flat)
          Sorry to bother, sometimes you have it in front of you and you don't realize it,
          thanks for everything​

          Comment


            #20
            If I have two orders at different prices and only the first one is filled and reaches the profit, how do I ask this to cancel the second order?

            Comment


              #21
              Originally posted by franatas View Post
              If I have two orders at different prices and only the first one is filled and reaches the profit, how do I ask this to cancel the second order?

              You could track the order objects and set up conditions that once they are met result in the order being canceled with the Cancel() method:


              For the example you gave, you could track when the first order is executed and when the profit is executed, then if the other second order is still in a state of OrderState.Working you could cancel it with Cancel(). A list of different order states for Order objects may be found on the following page:


              Thanks for your time and patience.

              Comment


                #22
                Thank you very much, anyway I don't know if anything is done with all this work, I am trying this ATM in demo and everything goes perfectly, it places the sl and tp orders and it does everything well, now I just tried it in real and how The orders always fail, it only places the first order and the other remains in a working state on the board but it does not appear on the chart or in rithnic. This has happened to me with everything I did, everything goes well until it actually starts to do everything wrong, I don't know if it is due to the communication of the platform with rithmic or what, but it already seems to me that I am wasting my time

                Comment


                  #23
                  Originally posted by franatas View Post
                  Thank you very much, anyway I don't know if anything is done with all this work, I am trying this ATM in demo and everything goes perfectly, it places the sl and tp orders and it does everything well, now I just tried it in real and how The orders always fail, it only places the first order and the other remains in a working state on the board but it does not appear on the chart or in rithnic. This has happened to me with everything I did, everything goes well until it actually starts to do everything wrong, I don't know if it is due to the communication of the platform with rithmic or what, but it already seems to me that I am wasting my time
                  To understand the differences between the tests in a demo environment vs. the tests on a live account, I suggest adding print statements to narrow down and better understand your script's behavior:


                  Otherwise, you can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like our NinjaTrader Ecosystem team to follow up with you with a list of affiliate consultants who would be happy to create this script or any others at your request or provide one-on-one educational services.

                  Please let me know if I may be of further assistance.

                  Comment


                    #24
                    When the orders are filled they become null, so I don't know how to ask if the profit was executed, could you give me a hand?

                    Comment


                      #25
                      Hello franatas,

                      Thank you for your reply.

                      A best practice when handling order objects is to only set them to null when you see that they are executed via OnExecutionUpdate() or if the order is cancelled without a fill. This concept of handling order objects via OnOrderUpdate() and OnExecutionUpdate() is demonstrated in the Strategy reference sample at the link below, though it could still apply when working with Execution and Order updates in the Account class:


                      To see how this works in your script, you could even add a print so that when the profit target Order object is the order being executed in OnExecutionUpdate(), the print shows you that it has been filled. An execution is simply another name for the fill of an order. OnExecutionUpdate() is an event-driven method that is only called when an order is being filled or partially filled. If you want to print out general Execution information to get a better idea of how this works, I suggest adding the print in the snippet shown on the following page:


                      Please let me know if I may be of further assistance.

                      Comment


                        #26
                        How do I copy my .cs into .dll?

                        Comment


                          #27
                          Originally posted by franatas View Post
                          How do I copy my .cs into .dll?
                          I'm not sure of the context you are referring to. If you would like to export your script as a compiled assembly (DLL) then you could follow the steps for exporting NinjaScript as assembly here:


                          Please feel free to reach out with any additional questions or concerns.

                          Comment


                            #28
                            I follow the steps of exporting as asanblea.
                            It always gives me an invalid character in an assembly, the truth is that I have reviewed all the names of my scripts and I have removed any symbols such as dashes and periods, I don't know where else to check or where the problem is.

                            Comment


                              #29
                              Originally posted by franatas View Post
                              I follow the steps of exporting as asanblea.
                              It always gives me an invalid character in an assembly, the truth is that I have reviewed all the names of my scripts and I have removed any symbols such as dashes and periods, I don't know where else to check or where the problem is.
                              Please send a screenshot of the entire error message that you are receiving.
                              • To send a screenshot with Windows 10 or newer I would recommend using the Windows Snipping Tool.
                              • Alternatively to send a screenshot press Alt + PRINT SCREEN to take a screenshot of the selected window. Then go to Start--> Accessories--> Paint, and press CTRL + V to paste the image. Lastly, save it as a jpeg file and send the file as an attachment.
                              ​I look forward to your reply.

                              Comment


                                #30
                                there it is, that's the error
                                Attached Files

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                                0 responses
                                635 views
                                0 likes
                                Last Post Geovanny Suaza  
                                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                                0 responses
                                365 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by Mindset, 02-09-2026, 11:44 AM
                                0 responses
                                106 views
                                0 likes
                                Last Post Mindset
                                by Mindset
                                 
                                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                                0 responses
                                567 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by RFrosty, 01-28-2026, 06:49 PM
                                0 responses
                                571 views
                                1 like
                                Last Post RFrosty
                                by RFrosty
                                 
                                Working...
                                X