ifractals

 

 Hello to everyone, I am trying  to do a function to "intercept" the candle where it "appears" the "fractals" of "the function “ifractals" this is the code:

for(int j=0; j<Bars; j++)
    {
    if(iClose(NULL,0,j)>=iFractals(NULL,0,MODE_UPPER,j) && iFractals(NULL,0,MODE_UPPER,j)!=0)
         {
         r=r+1;
         }

    if(iClose(NULL,0,j)<iFractals(NULL,0,MODE_LOWER,j) && iFractals(NULL,0,MODE_LOWER,j)!=0)
         {
         s=s+1;
         }
         
         Comment("S: "+ s + "R:" + r );
    }
   return(0);
  }

 If something wrong in those who help me

 
if(iClose(NULL,0,j)>=iFractals(NULL,0,MODE_UPPER,j) && iFractals(NULL,0,MODE_UPPER,j)!=0)

The close will never be higher than the fractal.

Remember that there will not be a fractal value for Bar[0] and Bar[1]

 
I tried to turn the code so .....................

for(int j=0; j<Bars; j++)
    {
    if(iClose(Symbol(),0,j)>=iFractals(Symbol(),0,MODE_LOWER,j) && iFractals(Symbol(),0,MODE_LOWER,j)!=0)
         {
         Alert("Resistenza su "+Symbol()+" a TF "+IntegerToString(Period(),0,0)) ;
         r++;
         }

    if(iClose(Symbol(),0,j)<iFractals(Symbol(),0,MODE_UPPER,j) && iFractals(Symbol(),0,MODE_UPPER,j)!=0)
         {
          Alert("\nSupport su "+Symbol()+" a TF "+IntegerToString(Period(),0,0)+"al tempo " + Time[j]);
         s++;
         }
        
         Comment("S: "+ s + "\nR:" + r );
    }
   return(0);

 But I do not understand the reason why run the alert almost continuously at each "tick" and metatrader crashes instead should work so that each time it appears a support / resistance a allert appears to me,

I thank you in advance
 
texoro: I do not understand the reason why run the alert almost continuously at each "tick" and metatrader crashes
  1. Print out your variables, and find out why.
  2. Create a test script that shows the crash. We can't do anything about that, show Metaquotes
 
texoro:
I tried to turn the code so .....................

for(int j=0; j<Bars; j++)
    {
    if(iClose(Symbol(),0,j)>=iFractals(Symbol(),0,MODE_LOWER,j) && iFractals(Symbol(),0,MODE_LOWER,j)!=0)
         {
         Alert("Resistenza su "+Symbol()+" a TF "+IntegerToString(Period(),0,0)) ;
         r++;
         }

    if(iClose(Symbol(),0,j)<iFractals(Symbol(),0,MODE_UPPER,j) && iFractals(Symbol(),0,MODE_UPPER,j)!=0)
         {
          Alert("\nSupport su "+Symbol()+" a TF "+IntegerToString(Period(),0,0)+"al tempo " + Time[j]);
         s++;
         }
        
         Comment("S: "+ s + "\nR:" + r );
    }
   return(0);

 But I do not understand the reason why run the alert almost continuously at each "tick" and metatrader crashes instead should work so that each time it appears a support / resistance a allert appears to me,

I thank you in advance

You need to decide what you actually want to do.

It is no good comparing price to a fractal value, because fractal values are always higher or lower than the bar's high/low. This is so that the fractal does not obscure the bar.



  for(int j=0; j<Bars; j++)
    {
    if(iFractals(Symbol(),0,MODE_LOWER,j)!=0)
         {
         Alert("Lower fractal found at bar ",j) ;
         break;
         }

    if(iFractals(Symbol(),0,MODE_UPPER,j)!=0)
         {
         Alert("Upper fractal found at bar ",j) ;
         break;
         }
    }
   return(0);  


The above code will find the most recent fractal. Build on that to do what you require. Code it so it is only checked when a new bar opens.

You may want to store the time, high or low of the fractal bar etc. You can store thes values in globally declared or static variables. Or even in an array, it all depends on what you will be doing with the results.

 
Keith Watford:

You need to decide what you actually want to do.

It is no good comparing price to a fractal value, because fractal values are always higher or lower than the bar's high/low. This is so that the fractal does not obscure the bar.



  for(int j=0; j<Bars; j++)
    {
    if(iFractals(Symbol(),0,MODE_LOWER,j)!=0)
         {
         Alert("Lower fractal found at bar ",j) ;
         break;
         }

    if(iFractals(Symbol(),0,MODE_UPPER,j)!=0)
         {
         Alert("Upper fractal found at bar ",j) ;
         break;
         }
    }
   return(0);  


The above code will find the most recent fractal. Build on that to do what you require. Code it so it is only checked when a new bar opens.

You may want to store the time, high or low of the fractal bar etc. You can store thes values in globally declared or static variables. Or even in an array, it all depends on what you will be doing with the results.

The function that's okay just that I would like the allert only the candle comnpare support or resistance not every "tick" how it works now!
 
texoro:
The function that's okay just that I would like the allert only the candle comnpare support or resistance not every "tick" how it works now!
I am afraid that this is gibberish. I have no idea what you are asking
 
texoro: I would like the allert only the candle comnpare support or resistance not every "tick" how it works now!
So where is your new bar code and why haven't you put the call in there?
 
Keith Watford:
I am afraid that this is gibberish. I have no idea what you are asking
The allert must play only the candle that appears on fractal and not every market movement (attach picture)
 

I solved this way:

 

   if (TempoSalvato!=Time[0])
    {
     TempoSalvato=Time[0];
     for(int j=0; j<Bars; j++)
         {
         if(iFractals(Symbol(),0,MODE_LOWER,j)!=0)
             {
             Alert("Lower fractal found at bar ",j) ;
             break;
             }
      
         if(iFractals(Symbol(),0,MODE_UPPER,j)!=0)
             {
             Alert("\nUpper fractal found at bar ",j) ;
             break;
              }
         }
      }

 Now I would like to make visible alerts only sound when you see a "support or resistance" and not every candle 

Reason: