Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Is it possible to attach an order to an indicator via a script?

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

    Is it possible to attach an order to an indicator via a script?

    A question to all Ninja scripters. Is it possible to attach an order to an indicator via a script?

    Here is what i'd like to do:

    I have a couple of scenarios where i open a buy/sell limit order way below/above the actual prices manually. When a certain pattern occurs, i'd like to attach the opened order to an indicator. Ideally, i'd like to press a button to do this. I know we can do this manually by right-clicking on the order and attach it to a specific indicator plot and specify an offset but it is not quick to do this whole operation and i can easily make an error. If i could just press a button to attach the working order to any given plot it would be way more efficient.

    Any idea if i can do this via a script? Thanks

    #2
    Hello trendisyourfriend,

    Thanks for your post.

    Yes, this should be possible and complicated, although I do not have an example to provide.

    In general, you would need to add a button to the chart or to the chart trader to provide the "action", you may need a selector to select the plot to work with from the chart, add an account property to allow finding the order, connecting the order to the indicator. Each of these generalities is actually quite a bit of work.

    Hopefully, this would improve over the existing functionality of right mouse click and a few selections.

    I'll work on creating an example as a learning exercise however there are a lot of moving parts to work with so it will take quite some time between the other support work, when possible. I will update this thread when I have something to advise.

    Comment


      #3
      Originally posted by NinjaTrader_PaulH View Post
      H...connecting the order to the indicator. ...
      Thank you for your prompt reply. Connecting the order to the indicator is the part which i am not too sure how to proceed. Can you give me a few pointers for this part?

      Comment


        #4
        Hello trendisyourfriend,

        Thanks for your reply.

        I'm still working through that myself.

        Thanks in advance for your patience.

        Comment


          #5
          Hello trendisyourfriend,

          Thanks for your patience.

          In the attached example indicator, I added a property for an indicator name so when you apply the indicator you can enter the name (string) of the indicator on the chart that you would attach the order to. The indicator provides a button on the chart trader called move order. The indicator will also report the value of the indicator (that you want to attach the order to) in the charts upper right corner for feedback/confirmation that the correct indicator has been selected.

          Once the "move order" button is pressed the indicator will loop through the account order looking for one that matches the instrument and the order state of working or accepted (limits or stops).
          It will then create an order object of that order and set a bool. In the OnBarUpdate() when the bool is switched, the orders stop price or limit price is changed to the value of the indicator and then account.Change() is used.
          Reference: https://ninjatrader.com/support/help...t8/?change.htm

          Please note that the indicator example provide is a rough example of what you would need to and should not be used as is other than for demonstration on a simulation account. There is no protection for placing an order on the wrong side of the market.


          AttachOrderToIndicatorExample.zip




          Comment


            #6
            Originally posted by NinjaTrader_PaulH View Post
            Hello trendisyourfriend,

            Thanks for your patience.

            In the attached example indicator, I added a property for an indicator name so when you apply the indicator you can enter the name (string) of the indicator on the chart that you would attach the order to. The indicator provides a button on the chart trader called move order. The indicator will also report the value of the indicator (that you want to attach the order to) in the charts upper right corner for feedback/confirmation that the correct indicator has been selected.

            Once the "move order" button is pressed the indicator will loop through the account order looking for one that matches the instrument and the order state of working or accepted (limits or stops).
            It will then create an order object of that order and set a bool. In the OnBarUpdate() when the bool is switched, the orders stop price or limit price is changed to the value of the indicator and then account.Change() is used.
            Reference: https://ninjatrader.com/support/help...t8/?change.htm

            Please note that the indicator example provide is a rough example of what you would need to and should not be used as is other than for demonstration on a simulation account. There is no protection for placing an order on the wrong side of the market.


            [ATTACH]n1135878[/ATTACH]



            Hi Paul,

            I put in the name of the indicator "SMA" but I get a text error on the chart.

            What else do I need to input as the name (string) of the indicator?

            Thanks
            Irv

            Comment


              #7
              Hello ij001,

              Thanks for your note.

              The error you are reporting indicates that you likely do not have the SMA indicator applied to the chart, resulting in the error 'Indicator not found. Check spelling, make sure it is on chart.'

              To resolve this, you would need to simply add the SMA indicator to the same chart window as the AttachOrderToIndicatorExample script as stated in the error message. Once the SMA indicator is added, the error message in the center of the chart will not appear.

              Please let us know if we may assist further.
              <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              639 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              366 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              107 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              569 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              572 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X