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

How change values for order stop on OnOrderUpdate listener.

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

    How change values for order stop on OnOrderUpdate listener.

    I'm creating a copy trade, but when I update the stop order, and call the _receiveAccount.QueueChange method, it doesn't change as expected, only the limit order.

    _receiveAccount is type Account.

    #2
    Hello gabrielrodrigues,

    Thank you for your post.

    QueueChange() is not documented in the help guide, its purpose is only meant for internal use by the NinjaTrader application, and not for NinjaScript access.

    The Change() method is documented for use to change an Order object as mentioned in the help guide here:



    Please let us know if you have any further questions.
    Gaby V.NinjaTrader Customer Service

    Comment


      #3
      I also used change and it didn't work. This way. _receiveAccount.Change(new List<Order> { linkedOrder.OrderCopied });

      Nothing happens.

      Comment


        #4
        Hello gabrielarodrigues,

        Thank you for your response.

        Make sure you are specifying the order.StopPriceChanged before calling Change, as demonstrated on the Help Guide page.

        Code:
        Order stopOrder;
        stopOrder.StopPriceChanged = stopOrder.StopPrice - 4 * stopOrder.Instrument.MasterInstrument.TickSize;
        
        private void OnExecutionUpdate(object sender, ExecutionEventArgs e)
        {
        // Change the stop order if an execution results in a long position
        if(e.MarketPosition == MarketPosition.Long)
        myAccount.Change(new[] { stopOrder });
        }
        I also recommend taking a look at this AddOn sample script which demonstrates modifying orders through the addon approach.



        If you are still having issues, you will need to debug the script using prints. Make sure to also review the Log tab of the Control Center to check for any errors.



        Please let us know if you need further assistance.
        Gaby V.NinjaTrader Customer Service

        Comment


          #5
          Solved! When I did it I was using the value of the limitPrice property. Now I used StopPrice and StopPriceChanged and it worked.

          Thanks!!

          Comment


            #6
            When I change the limit order, it shows the change on the chart, but it is still filled first, with the original value before the change. Here are two example photos and the code snippet.

            Comment


              #7
              Hello,

              In order to better understand how the code is working, it will be necessary to use Print to see how the conditions are evaluating and enable TraceOrders to see if orders are being submitted, ignored, rejected, or cancelled.

              https://support.ninjatrader.com/s/article/Developer-Guide-Debugging-using-Print-and-TraceOrders

              Enable TraceOrders, print the time of the bar and all values used in the conditions that submit entry orders. Try also printing out the value you are changing the limit price to.

              Include labels for all values and comparison operators.

              Let me know if you need any assistance creating a print or enabling TraceOrders.

              Save the output from the output window to a text file and provide this with your reply.

              I'll be happy to assist with analyzing the output.​
              Gaby V.NinjaTrader Customer Service

              Comment


                #8
                I'll describe the problem better.
                When I enter, I use an ATM Strategy with 5 points of loss and 5 of gain. So I change the order to 13 points and it should reflect the change on the other account as well. However, it shows the change graphically, at the same point as the main account, but it is initially executed at 5 points. I've attached two images. The two profit-taking limit orders were executed at the wrong points.​

                Comment


                  #9
                  TraceOrders is not available for indicators, only strategies.

                  Comment


                    #10
                    Hello gabriel,

                    The output from prints would still be necessary in this case. print the time of the bar and all values used in the conditions that submit entry orders. Try also printing out the value you are changing the limit price to. Include labels for all values and comparison operators.​
                    Gaby V.NinjaTrader Customer Service

                    Comment


                      #11
                      ------- BEFORE CALL CHANGE METHOD -------

                      Log on: NinjaTrader.NinjaScript.TimeSeries

                      Account sender order:

                      orderId='94349980282' account='APEX1405530000015' name='Stop1' orderState=ChangeSubmitted instrument='MNQ SEP24' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=19871 quantity=4 tif=Gtc oco='99e5f704ccc44aeeba68554c9eccdc22' filled=0 averageFillPrice=0 onBehalfOf='' id=5500 time='2024-06-25 13:30:22' gtd='2099-12-01' statementDate='1800-01-01'

                      -------AFTER CALL CHANGE METHOD--------

                      Account receiver order:

                      orderId='194822415' account='S1Jun215044119' name='Stop1' orderState=Accepted instrument='MNQ SEP24' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=19871 quantity=4 tif=Gtc oco='73fd63e856f6414da9724fbee6599fbe' filled=0 averageFillPrice=0 onBehalfOf='' id=5502 time='2024-06-25 13:30:16' gtd='2099-12-01' statementDate='2024-06-25'

                      :::: OnOrderUpdate ::::

                      :::: OnOrderUpdate ::::


                      See that I changed the order and it still executed me at another point.

                      Comment


                        #12
                        Hello,

                        Are we looking at a stop order or a limit order? Your previous question is stating an issue with a limit order but this is output for a stop order.

                        Additionally, it's not clear to be from this output that the order was executed at a different point. The StopPrice is the same for both. And the order hasn't been filled/executed yet, your output only shows it in a working state.

                        You can use ExecutionUpdate to print out the price the order is being executed at. I also recommend printing the order object from OrderUpdate so we can keep track of the order. Printing the order object in OnOrderUpdate() will allow you to track the progression of the order from submitted, to working, to filled, cancelled, or rejected.



                        Gaby V.NinjaTrader Customer Service

                        Comment


                          #13
                          Both are having problems.

                          This problem does not occur with the direct sim account created by the platform, only with other accounts.
                          Last edited by gabrielrodrigues; 06-25-2024, 12:05 PM.

                          Comment


                            #14
                            Hello gabriel,

                            Please provide the output requested if you would like assistance. Without the output, there is not enough information in order to understand the behavior of the strategy.
                            Gaby V.NinjaTrader Customer Service

                            Comment


                              #15
                              ExecutionUpdate does not exist on Indicator. I'm not going to code anything else because the simulated account is working and the other one isn't, and I'm not willing to spend any dollars on a bug.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by NeoTraderBot, Yesterday, 10:55 PM
                              0 responses
                              6 views
                              0 likes
                              Last Post NeoTraderBot  
                              Started by OliverWaters, Yesterday, 10:35 PM
                              0 responses
                              6 views
                              0 likes
                              Last Post OliverWaters  
                              Started by Graci117, 07-06-2024, 09:32 AM
                              6 responses
                              37 views
                              0 likes
                              Last Post Graci117  
                              Started by AdamDJ8, 07-01-2024, 06:50 PM
                              2 responses
                              123 views
                              0 likes
                              Last Post AdamDJ8
                              by AdamDJ8
                               
                              Started by AdamDJ8, 07-01-2024, 05:55 PM
                              3 responses
                              32 views
                              0 likes
                              Last Post AdamDJ8
                              by AdamDJ8
                               
                              Working...
                              X