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

Double position contracts for the next Entry when Stop loss hitted

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

    #16
    Hello tradingnasdaqprueba,

    Thank you for your patience.

    Please provide an updated snippet with the latest prints that were added.

    I look forward to your reply.
    Emily C.NinjaTrader Customer Service

    Comment


      #17
      Hi Emily,

      Here you have:

      I am pretty sure that something is missing in the code... I can't figure what it is...

      Code:
        protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time)
      {​
      
      #region Cobertura Automatica X2    
          
              if ((execution.Order.Name == "StopLong1") || (execution.Order.Name == "StopShort1")
                  && execution.Order.OrderState == OrderState.Filled
                  && (Cobertura_manual == false)
                  && (iscounting == false)
              )
          {
              Print(Time[0] + "Cobertura_Manual Bolean in Coertura Automatica is set to: " + Cobertura_manual);
              Print(Time[0] + "order name: " + execution.Order.Name + " order state: " + execution.Order.OrderState + " iscounting: " + iscounting);
              Print(Time[0] + "initial counter value: " + counter);
              counter++;
              Print(Time[0] + "counter++. new counter value: " + counter);
              Ncontratos_trade1 = (counter * 2);
              Print(Time[0] + "Ncontratos_trade1: " + Ncontratos_trade1);
              Ncontratos_trade2 = (counter * 2);
              Print(Time[0] + "Ncontratos_trade2: " + Ncontratos_trade2);
              iscounting = true;
              Print(Time[0] + "iscounting: " + iscounting);
      
              Print(Time[0] + " Number of STOPS are " + counter);
              Print(Time[0] + " ACTUAL Contracts for TRADE1 are " + Ncontratos_trade1);
              Print(Time[0] + " ACTUAL Contracts for TRADE2 are " + Ncontratos_trade2);
              Print(Time[0] + " ISCOUNTING = " + iscounting);
          }
          
                  #endregion    
          
              #region Cobertura Manual
          
          
      
              if ((execution.Order.Name == "StopLong1") || (execution.Order.Name == "StopShort1")
              && execution.Order.OrderState == OrderState.Filled
              && (Cobertura_manual == true)
              )
          {
              counter++;
              Print(Time[0] + "Cobertura Manual 1 counter++. new counter value: " + counter);
              Print(Time[0] + "Cobertura_Manual 1 Bolean is set to: " + Cobertura_manual);
              if ((counter == 1)
              && (counter < Cobertura_Max)
                  )
                          {
                              Ncontratos_trade1 = Cobertura1;
                              Ncontratos_trade2 = Cobertura1;
                          
                              Print(Time[0] + " Cobertura Manual 1 Number of STOPS are " + counter);
                              Print(Time[0] + " Cobertura Manual 1 ACTUAL Contracts for TRADE1 are " + Ncontratos_trade1);
                              Print(Time[0] + " Cobertura Manual 1 ACTUAL Contracts for TRADE2 are " + Ncontratos_trade2);
                          }        
                              
          }
          
              if ((execution.Order.Name == "StopLong1") || (execution.Order.Name == "StopShort1")
              && execution.Order.OrderState == OrderState.Filled
              && (Cobertura_manual == true)
              )
          {
              counter++;
              Print(Time[0] + "Cobertura Manual 2 counter++. new counter value: " + counter);
              Print(Time[0] + "Cobertura_Manual 2 Bolean is set to: " + Cobertura_manual);
              if ((counter == 2)
              && (counter < Cobertura_Max)
                  )        
                      {
                              Ncontratos_trade1 = Cobertura2;
                              Ncontratos_trade2 = Cobertura2;
                          
                              Print(Time[0] + " Cobertura Manual 2 Number of STOPS are " + counter);
                              Print(Time[0] + " Cobertura Manual 2 ACTUAL Contracts for TRADE1 are " + Ncontratos_trade1);
                              Print(Time[0] + " Cobertura Manual 2 ACTUAL Contracts for TRADE2 are " + Ncontratos_trade2);
                      }        
          }                    
      
              if ((execution.Order.Name == "StopLong1") || (execution.Order.Name == "StopShort1")
              && execution.Order.OrderState == OrderState.Filled
              && (Cobertura_manual == true)
      
              )
          {
              counter++;
              Print(Time[0] + "Cobertura Manual 3 counter++. new counter value: " + counter);
              Print(Time[0] + "Cobertura_Manual 3 Bolean is set to: " + Cobertura_manual);
              if ((counter == 3)
              && (counter < Cobertura_Max)
                  )        
                      {
                              Ncontratos_trade1 = Cobertura3;
                              Ncontratos_trade2 = Cobertura3;
                          
                              Print(Time[0] + " Cobertura Manual 3 Number of STOPS are " + counter);
                              Print(Time[0] + " Cobertura Manual 3 ACTUAL Contracts for TRADE1 are " + Ncontratos_trade1);
                              Print(Time[0] + " Cobertura Manual 3 ACTUAL Contracts for TRADE2 are " + Ncontratos_trade2);
                      }        
          }                        
          
              if ((execution.Order.Name == "StopLong1") || (execution.Order.Name == "StopShort1")
              && execution.Order.OrderState == OrderState.Filled
              && (Cobertura_manual == true)
      
              )
          {
              counter++;
              Print(Time[0] + "Cobertura Manual 4 counter++. new counter value: " + counter);
              Print(Time[0] + "Cobertura_Manual 4 Bolean is set to: " + Cobertura_manual);
              if ((counter == 4)
              && (counter < Cobertura_Max)
                  )    
                          {
                              Ncontratos_trade1 = Cobertura4;
                              Ncontratos_trade2 = Cobertura4;
                          
                              Print(Time[0] + " Cobertura Manual 4 Number of STOPS are " + counter);
                              Print(Time[0] + " Cobertura Manual 4 ACTUAL Contracts for TRADE1 are " + Ncontratos_trade1);
                              Print(Time[0] + " Cobertura Manual 4 ACTUAL Contracts for TRADE2 are " + Ncontratos_trade2);
                          }    
          }
          
              if ((execution.Order.Name == "StopLong1") || (execution.Order.Name == "StopShort1")
              && execution.Order.OrderState == OrderState.Filled
              && (Cobertura_manual == true)
      
              )
          {
              counter++;
              Print(Time[0] + "Cobertura Manual 5 counter++. new counter value: " + counter);
              Print(Time[0] + "Cobertura_Manual 5 Bolean is set to: " + Cobertura_manual);
              if ((counter == 5)
              && (counter < Cobertura_Max)
                  )        
                      {
                              Ncontratos_trade1 = Cobertura5;
                              Ncontratos_trade2 = Cobertura5;
                              
                              Print(Time[0] + " Cobertura Manual 5 Number of STOPS are " + counter);
                              Print(Time[0] + " Cobertura Manual 5 ACTUAL Contracts for TRADE1 are " + Ncontratos_trade1);
                              Print(Time[0] + " Cobertura Manual 5 ACTUAL Contracts for TRADE2 are " + Ncontratos_trade2);
                      }        
          }                    
      
              if ((execution.Order.Name == "StopLong1") || (execution.Order.Name == "StopShort1")
              && execution.Order.OrderState == OrderState.Filled
              && (Cobertura_manual == true)
          
              )
          {
              counter++;
              Print(Time[0] + "Cobertura Manual 6 counter++. new counter value: " + counter);
              Print(Time[0] + "Cobertura_Manual 6 Bolean is set to: " + Cobertura_manual);
              if ((counter == 6)
              && (counter < Cobertura_Max)
                  )        
                          {
                              Ncontratos_trade1 = Cobertura6;
                              Ncontratos_trade2 = Cobertura6;
                              
                              Print(Time[0] + " Cobertura Manual 6 Number of STOPS are " + counter);
                              Print(Time[0] + " Cobertura Manual 6 ACTUAL Contracts for TRADE1 are " + Ncontratos_trade1);
                              Print(Time[0] + " Cobertura Manual 6 ACTUAL Contracts for TRADE2 are " + Ncontratos_trade2);
                          }        
                              
          }        
          
              if ((execution.Order.Name == "StopLong1") || (execution.Order.Name == "StopShort1")
              && execution.Order.OrderState == OrderState.Filled
              && (Cobertura_manual == true)
      
              )
          {
              counter++;
              Print(Time[0] + "Cobertura Manual 7 counter++. new counter value: " + counter);
              Print(Time[0] + "Cobertura_Manual 7 Bolean is set to: " + Cobertura_manual);
              if ((counter == 7)
              && (counter < Cobertura_Max)
                  )
                              
                      {
                              Ncontratos_trade1 = Cobertura7;
                              Ncontratos_trade2 = Cobertura7;
                              
                              Print(Time[0] + " Cobertura Manual 7 Number of STOPS are " + counter);
                              Print(Time[0] + " Cobertura Manual 7 ACTUAL Contracts for TRADE1 are " + Ncontratos_trade1);
                              Print(Time[0] + " Cobertura Manual 7 ACTUAL Contracts for TRADE2 are " + Ncontratos_trade2);
                      }        
          }                    
      
              if ((execution.Order.Name == "StopLong1") || (execution.Order.Name == "StopShort1")
              && execution.Order.OrderState == OrderState.Filled
              && (Cobertura_manual == true)
      
              )
          {
              counter++;
              Print(Time[0] + "Cobertura Manual 8 counter++. new counter value: " + counter);
              Print(Time[0] + "Cobertura_Manual 8 Bolean is set to: " + Cobertura_manual);
              if ((counter == 8)
              && (counter < Cobertura_Max)
                  )
                  
                  {
                              Ncontratos_trade1 = Cobertura8;
                              Ncontratos_trade2 = Cobertura8;
                              
                              Print(Time[0] + " Cobertura Manual 8 Number of STOPS are " + counter);
                              Print(Time[0] + " Cobertura Manual 8 ACTUAL Contracts for TRADE1 are " + Ncontratos_trade1);
                              Print(Time[0] + " Cobertura Manual 8 ACTUAL Contracts for TRADE2 are " + Ncontratos_trade2);
                  }            
          }    
          
              
                  #endregion        
       ​

      Comment


        #18
        Originally posted by tradingnasdaqprueba View Post
        Hi Emily,

        Here you have:

        I am pretty sure that something is missing in the code... I can't figure what it is...

        Code:
        protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time)
        {​
        
        #region Cobertura Automatica X2
        
        if ((execution.Order.Name == "StopLong1") || (execution.Order.Name == "StopShort1")
        && execution.Order.OrderState == OrderState.Filled
        && (Cobertura_manual == false)
        && (iscounting == false)
        )
        {
        Print(Time[0] + "Cobertura_Manual Bolean in Coertura Automatica is set to: " + Cobertura_manual);
        Print(Time[0] + "order name: " + execution.Order.Name + " order state: " + execution.Order.OrderState + " iscounting: " + iscounting);
        Print(Time[0] + "initial counter value: " + counter);
        counter++;
        Print(Time[0] + "counter++. new counter value: " + counter);
        Ncontratos_trade1 = (counter * 2);
        Print(Time[0] + "Ncontratos_trade1: " + Ncontratos_trade1);
        Ncontratos_trade2 = (counter * 2);
        Print(Time[0] + "Ncontratos_trade2: " + Ncontratos_trade2);
        iscounting = true;
        Print(Time[0] + "iscounting: " + iscounting);
        
        Print(Time[0] + " Number of STOPS are " + counter);
        Print(Time[0] + " ACTUAL Contracts for TRADE1 are " + Ncontratos_trade1);
        Print(Time[0] + " ACTUAL Contracts for TRADE2 are " + Ncontratos_trade2);
        Print(Time[0] + " ISCOUNTING = " + iscounting);
        }
        
        #endregion
        
        #region Cobertura Manual
        
        
        
        if ((execution.Order.Name == "StopLong1") || (execution.Order.Name == "StopShort1")
        && execution.Order.OrderState == OrderState.Filled
        && (Cobertura_manual == true)
        )
        {
        counter++;
        Print(Time[0] + "Cobertura Manual 1 counter++. new counter value: " + counter);
        Print(Time[0] + "Cobertura_Manual 1 Bolean is set to: " + Cobertura_manual);
        if ((counter == 1)
        && (counter < Cobertura_Max)
        )
        {
        Ncontratos_trade1 = Cobertura1;
        Ncontratos_trade2 = Cobertura1;
        
        Print(Time[0] + " Cobertura Manual 1 Number of STOPS are " + counter);
        Print(Time[0] + " Cobertura Manual 1 ACTUAL Contracts for TRADE1 are " + Ncontratos_trade1);
        Print(Time[0] + " Cobertura Manual 1 ACTUAL Contracts for TRADE2 are " + Ncontratos_trade2);
        }
        
        }
        
        if ((execution.Order.Name == "StopLong1") || (execution.Order.Name == "StopShort1")
        && execution.Order.OrderState == OrderState.Filled
        && (Cobertura_manual == true)
        )
        {
        counter++;
        Print(Time[0] + "Cobertura Manual 2 counter++. new counter value: " + counter);
        Print(Time[0] + "Cobertura_Manual 2 Bolean is set to: " + Cobertura_manual);
        if ((counter == 2)
        && (counter < Cobertura_Max)
        )
        {
        Ncontratos_trade1 = Cobertura2;
        Ncontratos_trade2 = Cobertura2;
        
        Print(Time[0] + " Cobertura Manual 2 Number of STOPS are " + counter);
        Print(Time[0] + " Cobertura Manual 2 ACTUAL Contracts for TRADE1 are " + Ncontratos_trade1);
        Print(Time[0] + " Cobertura Manual 2 ACTUAL Contracts for TRADE2 are " + Ncontratos_trade2);
        }
        }
        
        if ((execution.Order.Name == "StopLong1") || (execution.Order.Name == "StopShort1")
        && execution.Order.OrderState == OrderState.Filled
        && (Cobertura_manual == true)
        
        )
        {
        counter++;
        Print(Time[0] + "Cobertura Manual 3 counter++. new counter value: " + counter);
        Print(Time[0] + "Cobertura_Manual 3 Bolean is set to: " + Cobertura_manual);
        if ((counter == 3)
        && (counter < Cobertura_Max)
        )
        {
        Ncontratos_trade1 = Cobertura3;
        Ncontratos_trade2 = Cobertura3;
        
        Print(Time[0] + " Cobertura Manual 3 Number of STOPS are " + counter);
        Print(Time[0] + " Cobertura Manual 3 ACTUAL Contracts for TRADE1 are " + Ncontratos_trade1);
        Print(Time[0] + " Cobertura Manual 3 ACTUAL Contracts for TRADE2 are " + Ncontratos_trade2);
        }
        }
        
        if ((execution.Order.Name == "StopLong1") || (execution.Order.Name == "StopShort1")
        && execution.Order.OrderState == OrderState.Filled
        && (Cobertura_manual == true)
        
        )
        {
        counter++;
        Print(Time[0] + "Cobertura Manual 4 counter++. new counter value: " + counter);
        Print(Time[0] + "Cobertura_Manual 4 Bolean is set to: " + Cobertura_manual);
        if ((counter == 4)
        && (counter < Cobertura_Max)
        )
        {
        Ncontratos_trade1 = Cobertura4;
        Ncontratos_trade2 = Cobertura4;
        
        Print(Time[0] + " Cobertura Manual 4 Number of STOPS are " + counter);
        Print(Time[0] + " Cobertura Manual 4 ACTUAL Contracts for TRADE1 are " + Ncontratos_trade1);
        Print(Time[0] + " Cobertura Manual 4 ACTUAL Contracts for TRADE2 are " + Ncontratos_trade2);
        }
        }
        
        if ((execution.Order.Name == "StopLong1") || (execution.Order.Name == "StopShort1")
        && execution.Order.OrderState == OrderState.Filled
        && (Cobertura_manual == true)
        
        )
        {
        counter++;
        Print(Time[0] + "Cobertura Manual 5 counter++. new counter value: " + counter);
        Print(Time[0] + "Cobertura_Manual 5 Bolean is set to: " + Cobertura_manual);
        if ((counter == 5)
        && (counter < Cobertura_Max)
        )
        {
        Ncontratos_trade1 = Cobertura5;
        Ncontratos_trade2 = Cobertura5;
        
        Print(Time[0] + " Cobertura Manual 5 Number of STOPS are " + counter);
        Print(Time[0] + " Cobertura Manual 5 ACTUAL Contracts for TRADE1 are " + Ncontratos_trade1);
        Print(Time[0] + " Cobertura Manual 5 ACTUAL Contracts for TRADE2 are " + Ncontratos_trade2);
        }
        }
        
        if ((execution.Order.Name == "StopLong1") || (execution.Order.Name == "StopShort1")
        && execution.Order.OrderState == OrderState.Filled
        && (Cobertura_manual == true)
        
        )
        {
        counter++;
        Print(Time[0] + "Cobertura Manual 6 counter++. new counter value: " + counter);
        Print(Time[0] + "Cobertura_Manual 6 Bolean is set to: " + Cobertura_manual);
        if ((counter == 6)
        && (counter < Cobertura_Max)
        )
        {
        Ncontratos_trade1 = Cobertura6;
        Ncontratos_trade2 = Cobertura6;
        
        Print(Time[0] + " Cobertura Manual 6 Number of STOPS are " + counter);
        Print(Time[0] + " Cobertura Manual 6 ACTUAL Contracts for TRADE1 are " + Ncontratos_trade1);
        Print(Time[0] + " Cobertura Manual 6 ACTUAL Contracts for TRADE2 are " + Ncontratos_trade2);
        }
        
        }
        
        if ((execution.Order.Name == "StopLong1") || (execution.Order.Name == "StopShort1")
        && execution.Order.OrderState == OrderState.Filled
        && (Cobertura_manual == true)
        
        )
        {
        counter++;
        Print(Time[0] + "Cobertura Manual 7 counter++. new counter value: " + counter);
        Print(Time[0] + "Cobertura_Manual 7 Bolean is set to: " + Cobertura_manual);
        if ((counter == 7)
        && (counter < Cobertura_Max)
        )
        
        {
        Ncontratos_trade1 = Cobertura7;
        Ncontratos_trade2 = Cobertura7;
        
        Print(Time[0] + " Cobertura Manual 7 Number of STOPS are " + counter);
        Print(Time[0] + " Cobertura Manual 7 ACTUAL Contracts for TRADE1 are " + Ncontratos_trade1);
        Print(Time[0] + " Cobertura Manual 7 ACTUAL Contracts for TRADE2 are " + Ncontratos_trade2);
        }
        }
        
        if ((execution.Order.Name == "StopLong1") || (execution.Order.Name == "StopShort1")
        && execution.Order.OrderState == OrderState.Filled
        && (Cobertura_manual == true)
        
        )
        {
        counter++;
        Print(Time[0] + "Cobertura Manual 8 counter++. new counter value: " + counter);
        Print(Time[0] + "Cobertura_Manual 8 Bolean is set to: " + Cobertura_manual);
        if ((counter == 8)
        && (counter < Cobertura_Max)
        )
        
        {
        Ncontratos_trade1 = Cobertura8;
        Ncontratos_trade2 = Cobertura8;
        
        Print(Time[0] + " Cobertura Manual 8 Number of STOPS are " + counter);
        Print(Time[0] + " Cobertura Manual 8 ACTUAL Contracts for TRADE1 are " + Ncontratos_trade1);
        Print(Time[0] + " Cobertura Manual 8 ACTUAL Contracts for TRADE2 are " + Ncontratos_trade2);
        }
        }
        
        
        #endregion
        ​
        Thank you for your reply.

        Aside from adding prints, there are other debugging methods available. While we do not offer hands-on debugging services, I would be glad to offer you more suggestions to narrow down this behavior. First, I suggest commenting out portions of your code and uncomment them a little bit at a time until the unexpected/undesired behavior is reintroduced. That way you will know that the last thing you uncommented is part of the cause of the behavior. More information on debugging may be found at the links below:



        Thank you for your time and patience.
        Emily C.NinjaTrader Customer Service

        Comment


          #19
          Hello Emily,

          I finally got it, It was an error in the code, it was modifying the code and making it simpler. now everything works correctly!

          Thanks a lot for your Help!

          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,293 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