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

Automatically moving my stoploss

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

    Automatically moving my stoploss

    Hi I would like to listen order filled event from script and change the stoploss for that order based on some calculation. How to achieve that ?

    #2
    Hello nandhumca,

    It would depend on what type of script this is.

    If this is a NinjaScript Strategy, the OnExecutionUpdate() method will update for each execution (order fill).
    https://ninjatrader.com/support/help...tionupdate.htm

    Below is a link to an example ProfitChaseStopTrailExitOrdersExample_NT8 that demonstrates.
    Last edited by NinjaTrader_ChelseaB; 03-02-2022, 01:36 PM.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Can i use this method from my indicator ?

      Comment


        #4
        Hello nandhumca,

        From an Indicator you would need to find the Account and add a method handler to the ExecutionUpdate or OrderUpdate event.

        See the ProfitChaseStopTrailIndicatorExample_NT8 which demonstrates adding a handler to the OrderUpdate event.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          can you pls share me the link for ProfitChaseStopTrailExitOrdersExample_NT8 ?

          Looks like OnExecutionUpdate will capture the order placed by a strategy. Actually I want to access the OnExecutionUpdate of the order placed manually .

          Comment


            #6
            Can you pls pls provide sample for access order updates from indicator ?

            Comment


              #7
              Hello nandhumca,

              Below is a link to the ProfitChaseStopTrailIndicatorExample_NT8 which demonstrates adding an event handler method to the Account.OrderUpdate event, which updates for manually placed orders.
              Last edited by NinjaTrader_ChelseaB; 03-02-2022, 01:36 PM.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Thanks Chelsea for sharing the link. Actually I want to update the existing stoploss order placed by ATM with new stoploss price.

                Comment


                  #9
                  Hello nandhumca,

                  I had to edit my previous post. An incorrect link to the example was corrected.

                  <Account>.Change() is used to change the price of an account order.


                  The AddonFrameWork Basic demonstrates getting orders and information from atm active Atm.
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10

                    Hi Chelsea, I am trying to something similar in ProfitChaseStopTrailIndicatorExample. In that you creating new ProfitTarget ans StopLoss order and submitting it. In my use case, ProfitTarget and Stoploss will be placed by ATM and i want find the StopLoss order and update the price. I tried to access the current StopLoss order with OrderState=Accepted and OrderType=StopMarket. But it is not listing part of account.Orders.

                    Code:
                     foreach(Order order in account.Orders){
                    
                    //if(order.OrderState.GetType().Equals(OrderState.Ac cepted.GetType())){
                    Print ("===========");
                    Print(order);
                    Print(order.OrderState );
                    Print(order.OrderType );
                    
                    //}
                    
                    }

                    Comment


                      #11
                      Hello nandhumca,

                      The .GetType() is probably not what you intend to use. OrderState is an enum if you want to know the type. You want to use the enum values in the comparisons.

                      Attached is an example script that just prints account order updates and will print active orders when a button is clicked.

                      Try using an atm strategy and watch for the name="Stop loss" to appear in the orders listed and updates.
                      Attached Files
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #12
                        below code in your script will print all the orders for the day, not only the active orders currently working. If you see my previous reply , that code is printing all orders. In that only I couldn't find the ACTIVE Profit Target and Stop Loss orders. I tried with name "Stop Loss". It is helping me to filter all the stop loss orders for that account, not the active one and active one is not at all listed with account.Orders.

                        Code:
                        foreach (Order order in account.Orders)
                        Print(string.Format("{0} | {1}", order.Account.DisplayName, order));

                        Comment


                          #13
                          Hello nandhumca,

                          Stop loss orders will likely be in a Working state and not Active state.
                          To get only orders that are both working or active:
                          Code:
                          foreach (Order order in account.Orders.Where(o => o.OrderState == OrderState.Working || o.OrderState == OrderState.Accepted))
                          Print(string.Format("{0} | {1}", order.Account.DisplayName, order));
                          Run the script I provided you, and this will show you what orders exist and what state they are in.

                          What does the stop loss show as the last updated state?
                          Chelsea B.NinjaTrader Customer Service

                          Comment


                            #14
                            i will check this and update you.

                            Comment


                              #15
                              Thanks Chelsea. It is working as expected. I would like to collect the account name (not expecting user to enter) as input from dropdown for my indicator. What input type I supposed use ?

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by judysamnt7, 03-13-2023, 09:11 AM
                              4 responses
                              57 views
                              0 likes
                              Last Post DynamicTest  
                              Started by ScottWalsh, Today, 06:52 PM
                              4 responses
                              36 views
                              0 likes
                              Last Post ScottWalsh  
                              Started by olisav57, Today, 07:39 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post olisav57  
                              Started by trilliantrader, Today, 03:01 PM
                              2 responses
                              20 views
                              0 likes
                              Last Post helpwanted  
                              Started by cre8able, Today, 07:24 PM
                              0 responses
                              9 views
                              0 likes
                              Last Post cre8able  
                              Working...
                              X