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

put setprofittarget in secondary data series

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

    #16
    Hello diorfo57,

    Each time an order method is called, the TraceOrders will state if the order is submitted, ignored, or rejected.

    May I have the TraceOrders and prints output text file so that I may assist with analyzing the output?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #17
      Originally posted by NinjaTrader_ChelseaB View Post
      Hello diorfo57,

      Each time an order method is called, the TraceOrders will state if the order is submitted, ignored, or rejected.

      May I have the TraceOrders and prints output text file so that I may assist with analyzing the output?
      Attached one log sample.

      After the 22:03:27 the script stops placing orders and only put new orders after begin of new session, place about 3 orders, stops again and so on.

      I couldn't find any other error in my code that can contribute to this issue.
      Attached Files

      Comment


        #18
        Hello diorfo57,

        Are you certain the order methods are being called?

        If there is no trace orders message, that would imply that no order method was called.

        To understand further, I would need the prints I have advised you to add in post # 2.

        You could also add a print to same action block as the order method one line above the order method that prints "order submitted".
        Chelsea B.NinjaTrader Customer Service

        Comment


          #19
          Originally posted by NinjaTrader_ChelseaB View Post
          Hello diorfo57,

          Are you certain the order methods are being called?

          If there is no trace orders message, that would imply that no order method was called.

          To understand further, I would need the prints I have advised you to add in post # 2.

          You could also add a print to same action block as the order method one line above the order method that prints "order submitted".
          Hi Chelsea,

          How can I print the value/status from one order?

          for instance: If i have one order "Buy" (private Order Buy = null)

          Because I noticed when I force the orders to "null" in a certain time, the script start back placing orders.

          So looks like in certain moment the orders aren't getting empty as should be even I'm setting the right parameters:

          Code:
          protected override void OnOrderUpdate(Cbi.Order order, double limitPrice, double stopPrice,
                      int quantity, int filled, double averageFillPrice,
                      Cbi.OrderState orderState, DateTime time, Cbi.ErrorCode error, string comment)
           {
                      if (Buy == null && order.Name == "Buy")            
                          Buy = order;
          
                      if (Buy != null && order.Name == "Buy" && Buy.OrderState == OrderState.Cancelled)            
                          Buy = null;
           }
          protected override void OnExecutionUpdate(Cbi.Execution execution, string executionId, double price, int quantity,
                      Cbi.MarketPosition marketPosition, string orderId, DateTime time)
           {
          
                      if (Buy != null && Buy == execution.Order && (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled || (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0)))            
                      {        
                          if (execution.Order.OrderState == OrderState.Filled)
                          {    
                              Buy  = null;
                          }                
                     } 
           }​​

          Comment


            #20
            Hello diorfo57,

            Setting a variable to null removes the reference from the variable to the actual order object. The order still exists, but the variable is no longer holding it.

            To print the OrderState the variable cannot be null.

            private Order myBuyOrder;

            In OnOrderUpdate():

            if (order.Name == "Buy" && myBuyOrder != order)
            myBuyOrder = order;

            in OnBarUpdate() (or in any other method):
            if (myBuyOrder != null)
            Print("myBuyOrder.OrderState: " + myBuyOrder.OrderState);

            What is your logic for submitting an order method? Are you requiring the variable to be null? If so, then you would need to set the variable to null.

            (After an order variable is assigned an order, it will not become null on it's own. A filled, cancelled, rejected order is still an order object and is not null.)


            Below is a link to examples where variables are set to null to allow new orders.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #21
              Originally posted by NinjaTrader_ChelseaB View Post
              Hello diorfo57,

              Setting a variable to null removes the reference from the variable to the actual order object. The order still exists, but the variable is no longer holding it.

              To print the OrderState the variable cannot be null.

              private Order myBuyOrder;

              In OnOrderUpdate():

              if (order.Name == "Buy" && myBuyOrder != order)
              myBuyOrder = order;

              in OnBarUpdate() (or in any other method):
              if (myBuyOrder != null)
              Print("myBuyOrder.OrderState: " + myBuyOrder.OrderState);

              What is your logic for submitting an order method? Are you requiring the variable to be null? If so, then you would need to set the variable to null.

              (After an order variable is assigned an order, it will not become null on it's own. A filled, cancelled, rejected order is still an order object and is not null.)


              Below is a link to examples where variables are set to null to allow new orders.
              https://ninjatrader.com/support/foru...269#post802269
              Hi Chelsea,

              Sorry for late feedback related my problem.

              As far I understand, I have to set an order variable to "null" like below when the order is filled or canceled to make sure the variable will be empty when I have to use it again in future to store another order data.

              Code:
              protected override void OnOrderUpdate(Cbi.Order order, double limitPrice, double stopPrice,
                          int quantity, int filled, double averageFillPrice,
                          Cbi.OrderState orderState, DateTime time, Cbi.ErrorCode error, string comment)
               {
                          if (Buy == null && order.Name == "Buy")            
                              Buy = order;
              
                          if (Buy != null && order.Name == "Buy" && Buy.OrderState == OrderState.Cancelled)            
                              Buy = null;
               }
              protected override void OnExecutionUpdate(Cbi.Execution execution, string executionId, double price, int quantity,
                          Cbi.MarketPosition marketPosition, string orderId, DateTime time)
               {
              
                          if (Buy != null && Buy == execution.Order && (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled || (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0)))            
                          {        
                              if (execution.Order.OrderState == OrderState.Filled)
                              {    
                                  Buy  = null;
                              }                
                         }
               }​​
              Otherwise I may have some issues in place new orders due variables not be null (what actually I'm still experiencing now).

              The provisory solution I found to my problem is cancel all active orders and set them to null (about 8 variables) when any of each order is filled to make sure the variables will be empty when I need again in next trade.

              This is a hassle because I constantly have to open new orders but it was the only solution I found to my script not stop working and make sure all orders variables will be empty ​to store the next order.

              Comment


                #22
                Hello diorfo57,

                If the conditions to submit an order are checking the variable is null, the variable would need to be set to null when you are ready for a new order.

                The ProfitChaseStopTrailUnmanagedExample_NT8 example has logic like this.
                Chelsea B.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Segwin, 05-07-2018, 02:15 PM
                14 responses
                1,788 views
                0 likes
                Last Post aligator  
                Started by Jimmyk, 01-26-2018, 05:19 AM
                6 responses
                837 views
                0 likes
                Last Post emuns
                by emuns
                 
                Started by jxs_xrj, 01-12-2020, 09:49 AM
                6 responses
                3,292 views
                1 like
                Last Post jgualdronc  
                Started by Touch-Ups, Today, 10:36 AM
                0 responses
                12 views
                0 likes
                Last Post Touch-Ups  
                Started by geddyisodin, 04-25-2024, 05:20 AM
                11 responses
                62 views
                0 likes
                Last Post halgo_boulder  
                Working...
                X