how to count how many times a symbol satisfies if conditions

 

Hi I am trying to change the following code so it does

outputs  (like in picture) symbols that satisfy the adx cross and/or ma cross

If a symbol just satisfies one condtion it will put 1 after them like in the picture

If the symbol satisfies both it will put 2 after the symbol . x number for x number of condition . I tried to use the for loop and mycount++ as in the bold part inside the function but it does not do what is wanted it does put numbers after the symbols but not how many times the condition are met . How do i go about doing it. Thank you.

At the moment it leaves a space before the symbol if it meets both condition . How to get rid of that empty space and have the correct X after the symbol.


          ......
// for ma cross

            double mv90 = iMA(Symbname[i],timeframes[j],MA100,0,method100,price100,shift);
            double sv90 = iMA(Symbname[i],timeframes[j],MA200,0,method200,price200,shift);
            double mv91 = iMA(Symbname[i],timeframes[j],MA100,0,method100,price100,shift+1);
            double sv91 = iMA(Symbname[i],timeframes[j],MA200,0,method200,price200,shift+1);        
           
// for adx cross

            double mv0ad =  iADX(Symbname[i],timeframes[j],ADXperiod,PRICE_CLOSE,1,shift);
            double sv0ad =  iADX(Symbname[i],timeframes[j],ADXperiod,PRICE_CLOSE,2,shift);
            double mv1ad =  iADX(Symbname[i],timeframes[j],ADXperiod,PRICE_CLOSE,1,shift+1);
            double sv1ad =  iADX(Symbname[i],timeframes[j],ADXperiod,PRICE_CLOSE,2,shift+1);
          
           
// ma cross condition

            if(sv91 >= mv91 && sv90 < mv90)
              {
               setstochlabel(i,j,shift,ii); // function below
               find = true;
               
               ii++;
              }
            if(sv91 <= mv91 && sv90 > mv90)
              {
               shift = -shift;
               setstochlabel(i,j,shift,ii);
               find = true;
               
               ii++;
              }
                         
              
    // adx cross condition
   
             
            if(sv1ad >= mv1ad && sv0ad < mv0ad)
              {
               setstochlabel(i,j,shift,ii); // function below
               find = true;
               ii++;
              }
            if(sv1ad <= mv1ad && sv0ad > mv0ad)
              {
               shift = -shift;
               setstochlabel(i,j,shift,ii);
               find = true;
               ii++;
              }


          }
        }
     }

   return rates_total;
  }
//+------------------------------------------------------------------+
//|                function                                                  |
//+------------------------------------------------------------------+
void setstochlabel(int i, int j, int shift,int ii)
  {
   int h = 2*FontSize;
   int x = 10*FontSize + j*15*FontSize;
   int y = 73 + ii*h;
   
   string objn = "lbl_Period_"+IntegerToString(i)+"_"+IntegerToString(j);
   ObjectDelete(objn);
   ObjectCreate(ChartID(),objn,OBJ_LABEL,0,0,0);
   
   string txt;

// for loop not working 
   
   int MyCount = 0;
  for( int t = 1; t <= ii; t++ )
  {
   if( Symbname[i] == Symbname[i]  )
   {
      MyCount++;     
      
     }
   }
   
   txt =  StringConcatenate(Symbname[i]," ",MyCount );

   color c = RestColor;
   if(shift == 1)
      c = Bullish1;
   if(shift== -1)
      c=Bearish1;

   ObjectSetInteger(ChartID(),objn,OBJPROP_FONTSIZE,FontSize);
   ObjectSetInteger(ChartID(),objn,OBJPROP_COLOR,c);
   ObjectSetString(ChartID(),objn,OBJPROP_TEXT,txt);
   ObjectSetInteger(ChartID(),objn,OBJPROP_XDISTANCE,x);
   ObjectSetInteger(ChartID(),objn,OBJPROP_YDISTANCE,y);
   ObjectSetInteger(ChartID(),objn,OBJPROP_XSIZE,10*FontSize);
   ObjectSetInteger(ChartID(),objn,OBJPROP_SELECTABLE,0);
  }

 

Use meaningful variable names, it makes the code easier to read.

Instead of

            double mv90 = iMA(Symbname[i],timeframes[j],MA100,0,method100,price100,shift);
            double mv91 = iMA(Symbname[i],timeframes[j],MA100,0,method100,price100,shift+1);

use something like

            double ma_1 = iMA(Symbname[i],timeframes[j],MA100,0,method100,price100,shift);
            double ma_1_previous = iMA(Symbname[i],timeframes[j],MA100,0,method100,price100,shift+1);

With the variable names that you are using, I am not even going to try to work out what your code is meant to do.

iADX(Symbname[i],timeframes[j],ADXperiod,PRICE_CLOSE,1,shift);

Use the enum not the buffer number for indicators like ADX, again it makes it easier to read and understand 

iADX

(MODE_MAIN,  MODE_PLUSDI, MODE_MINUSDI).

 

I receive a PM requesting me to have a look at this thread. Here are my comments:

A moderator and experienced coder has given you some suggestions on how to improve your code readability. Why did you not follow up on it?

The suggestions may not solve the issue, but it will make it easier for us to read your code.

Also, the code you have presented does not seem to be sufficient for us to spot the problem at first glance.

So, I suggest you do as was suggested to improve your code and then make a new post attaching the entire file for review.

 
Fernando Carreiro #:

I receive a PM requesting me to have a look at this thread. Here are my comments:

A moderator and experienced coder has given you some suggestions on how to improve your code readability. Why did you not follow up on it?

The suggestions may not solve the issue, but it will make it easier for us to read your code.

Also, the code you have presented does not seem to be sufficient for us to spot the problem at first glance.

So, I suggest you do as was suggested to improve your code and then make a new post attaching the entire file for review.

Will do so thank you .

Reason: