Announcement

Collapse
No announcement yet.

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.

    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.

        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 NullPointStrategies, Yesterday, 05:17 AM
          0 responses
          54 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          130 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          72 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          44 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          49 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X