Download MetaTrader 5

small problem ciclo for and increase ++

To add comments, please log in or register
fly7680
636
fly7680  

Hello everyone, I created a small loop for, to try closures equal by using a counter. Unfortunately this Vieve count performed every tick, and I can not get an accurate count.

      if(iCustom(NULL, PERIOD_CURRENT, "CCI", CCI_Periodo, 0, PRICE_CLOSE, i) > 60    
      && iCustom(NULL, PERIOD_CURRENT, "CCI", CCI_Periodo, 0, PRICE_CLOSE, i) < 80      
      
      { Sell=false; CloseSell=Close[1+i]; CountSell=0; }
  
      
      if(Sell == false){
      
        for(int I=0; I<1500; I++){      
          
           if(CloseSell==Close[2+I]){
          
              CountSell++;              
              Print("CountSell: "+IntegerToString(CountSell));
              Print("Price :"+ DoubleToString(CloseSell)); }
                            
            if(CountSell==20) { I=1500; Sell=true; }        
         }
        }
      

Carl Schreiber
7292
Carl Schreiber  

Please debug your code and check the values!

If CloseSell is an integer ‌(because of CloseEll++) then what is the meaning of Close[] == CloseSell??

Check the logic of you code!‌

fly7680
636
fly7680  

Carl Schreiber hello, thank you for your answer...in global scope I have this:

int CountSell; double CloseSell; bool Sell;

after my first condition, I try in the 1500 candles counted from the for loop, the close[1+i] is repeated at least 20 times in the history.

      if(iCustom(NULL, PERIOD_CURRENT, "CCI", CCI_Periodo, 0, PRICE_CLOSE, i) > 60    
      && iCustom(NULL, PERIOD_CURRENT, "CCI", CCI_Periodo, 0, PRICE_CLOSE, i) < 80
      
      
      { Sell=false; CloseSell=Close[1+i]; CountSell=0; }
  
      
      if(Sell == false){
      
        for(int I=0; I<1500; I++){      
          
           if(CloseSell==Close[2+I]){
          
              CountSell++;              
              Print("CountSell: "+IntegerToString(CountSell));
              Print("Price :"+ DoubleToString(CloseSell)); }
                            
            if(CountSell==20) { I=1500; Sell=true; }        
         }
        }

‌‌

Mladen Rakic
61879
Mladen Rakic  
fly7680:

Carl Schreiber hello, thank you for your answer...in global scope I have this:

int CountSell; double CloseSell; bool Sell;

after my first condition, I try in the 1500 candles counted from the for loop, the close[1+i] is repeated at least 20 times in the history.

      if(iCustom(NULL, PERIOD_CURRENT, "CCI", CCI_Periodo, 0, PRICE_CLOSE, i) > 60    
      && iCustom(NULL, PERIOD_CURRENT, "CCI", CCI_Periodo, 0, PRICE_CLOSE, i) < 80
      
      
      { Sell=false; CloseSell=Close[1+i]; CountSell=0; }
  
      
      if(Sell == false){
      
        for(int I=0; I<1500; I++){      
          
           if(CloseSell==Close[2+I]){
          
              CountSell++;              
              Print("CountSell: "+IntegerToString(CountSell));
              Print("Price :"+ DoubleToString(CloseSell)); }
                            
            if(CountSell==20) { I=1500; Sell=true; }        
         }
        }

‌‌Try like this :

if (!Sell) for(int i=0; i<1500 && (i+2)<Bars && CountSell<20; i++) if (CloseSell==Close[i+2]) CountSell++;
     Sell = (CountSell==20);
fly7680
636
fly7680  
THANK Mladen Rakic, unfortunately works as my code, so no good .... I think the problem is in the 20 count.
fly7680
636
fly7680  

The number 20, is also achieved if this is false:

if(CloseSell==Close[2+I])
and no correct!

fly7680
636
fly7680  
A Little help please? 
To add comments, please log in or register