expression has no effect error ? for loop and array

 

Hey,


I have been trying to get my head around for loops in order to store data in an array. 

 a = (Current>High[i+1] && Current>High[i-1]);
     
      for(a;!a;a++)
       {
       High_Array[h]=Current;
       }

// So Current is = High[i]
// int a;
//double High_Array[];
^^^^^^^These have all be clarified at top of code.

it says for(a; !a; a++) expression has no effect ?

I read this as if a occurs start loop if a does not occur (!a) stop loop and add that a has occurred again a++.

Then store the High[i] value in the array i created High_Array[h]=Current.


Any thoughts would be greatly appreciated 

thank you :)

 
Your code
Equivalent
for(a;!a;a++){
   //for body
}
a;  ← What do you think this statement does?
while(!a){
   // for body
   a++;
}
 

hey thanks whroeder1.


I thought a; was initiating the loop as in when a happens.

Ill change it to the equivalent and try that. 

Thank you :)

 
 a = (Current>High[i+1] && Current>High[i-1]);
     
       
       while(!a)
       {
       {
       High_Array[h]=Current;
       }
       if(High_Array[0]<High_Array[1])
       {
       testBUFFER[i]=Current;
       }
       a++;
       }


The warnings have now gone so a value must be present but still no change on the chart. 

a = essentially a fractal with one candle either side.

Current = High[i] so the high point of the fractal.

Shouldn't this store the high value when a fractal occurs in the High_Array.

Then i am asking if the current fractal High_Array[0] is less than < the last one High_Array[1] plot the test buffer which is a little yellow thumbs up sign.

Nothing is being plotted on the chart ?

Where am i going wrong here :/

 
 a = (Current>High[i+1] && Current>High[i-1]);
:
       a++;

A is a boolean. What does it mean to increment true/false? If it was false, zero becomes one or true. if it was true, one becomes two which is true.

If it enters the loop, it can never exit and your indicator is forcibly terminated after 2.5 seconds. See the log.

 
whroeder1:

A is a boolean. What does it mean to increment true/false? If it was false, zero becomes one or true. if it was true, one becomes two which is true.

If it enters the loop, it can never exit and your indicator is forcibly terminated after 2.5 seconds. See the log.

Yea the log returns 

Order send failed, error #0


Its a While loop though, shouldn't it automatically switch itself off when the (a) is false and then re-enter the loop when (a) is true ?

 while(a)                                     // while a is true and returns a boolean value of 1
       {
       {
       High_Array[h]=Current;                 //Stores High[i] into the array
       }
       if(High_Array[0]<High_Array[1])        //if the recent high is < the high before 
       {
       testBUFFER[i]=Current;                 //plot the thumbs up
       }
       a++;                                   //create an extra slot in the array as a occurs. Thus the newest addition is always position 0
       

^^Thats my understanding of it 

I'm obviously wrong somewhere as it isn't plotting anything and I'm getting the error in the log but it compiles fine ?

i appreciate your help whroeder1

 
  1. torexvir: shouldn't it automatically switch itself off when the (a) is false
           High_Array[h]=Current;                 //Stores High[i] into the array
    
           if(High_Array[0]<High_Array[1])        //if the recent high is < the high before 
           {
              testBUFFER[i]=Current;                 //plot the thumbs up
           }
           a++;
    You never set it to false. You cast it to an int, increment it, and cast it back to an bool. Thus setting it always to true.

  2. When you post code please use the CODE button (Alt-S)! (For large amounts of code, attach it.) Please edit your (original) post.
              General rules and best pratices of the Forum. - General - MQL5 programming forum
              Messages Editor
  3. torexvir: Order send failed, error #0
    Don't look at last error unless you have an error. Check your return codes for errors, report them. Don't just silence the compiler, it is trying to help you.
              What are Function return values ? How do I use them ? - MQL4 and MetaTrader 4 - MQL4 programming forum
              Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
    Only those functions that return a value (e.g. iClose, MarketInfo, etc.) must you call ResetLastError before in order to check after.

 
whroeder1:
  1. You never set it to false. You cast it to an int, increment it, and cast it back to an bool. Thus setting it always to true.

  2. When you post code please use the CODE button (Alt-S)! (For large amounts of code, attach it.) Please edit your (original) post.
              General rules and best pratices of the Forum. - General - MQL5 programming forum
              Messages Editor
  3. Don't look at last error unless you have an error. Check your return codes for errors, report them. Don't just silence the compiler, it is trying to help you.
              What are Function return values ? How do I use them ? - MQL4 and MetaTrader 4 - MQL4 programming forum
              Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
    Only those functions that return a value (e.g. iClose, MarketInfo, etc.) must you call ResetLastError before in order to check after.

Hey whroeder1 my original post is posted using the code box as well ?

I understand what you are saying as i am incrementing it, the bool always has a a positive value. If it isn't 0 (false) it will never be switched off.


However, the while loop operator documentation gives this as an example 

while(k<n && !IsStopped())        //k<n.....is a boolean value 
  {
   y=y*x;
   k++;                           //Incrementing it
  }

Isn't this exactly what i am doing ?

sorry if i am being annoying just trying to get my head around this so i can fix it ha

Thanks 

 
torexvir:

Hey whroeder1 my original post is posted using the code box as well ?

Isn't this exactly what i am doing ?
  1. It is now, after you edited it.
  2. k is an int. k<n is a bool. you can't increment k<n only k. Your previous post was incrementing a bool.
 
whroeder1:
  1. It is now, after you edited it.
  2. k is an int. k<n is a bool. you can't increment k<n only k. Your previous post was incrementing a bool.

oh ok that makes sense. 

So even though a is a boolean and is assigned a value of 0 or 1 it still can't be recognised as an integer. 

So i have to find a way to convert 


a = (dCurrent>High[i+1] && dCurrent>High[i-1]);

into an integer value first so i can increment it with a++ instead of writing it out as a boolean ?

i tried to increment dCurrent++ as thats the value i want to store in the array but still no thumbs up printing.

//+------------------------------------------------------------------+
//|                                                     Torex.mq4    |
//+------------------------------------------------------------------+


#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Red
#property indicator_color2 Blue
#property indicator_color3 Yellow
//---- input parameters

//---- buffers
double ExtUpFractalsBuffer[];
double ExtDownFractalsBuffer[];
double testBUFFER[];

//double x;
//int BarsSince;
double High_Array[];
double Low_Array[];
int h;
bool a;


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicator buffers mapping  
    SetIndexBuffer(0,ExtUpFractalsBuffer);
    SetIndexBuffer(1,ExtDownFractalsBuffer); 
    SetIndexBuffer(2,testBUFFER);
 
//---- drawing settings
    SetIndexStyle(0,DRAW_ARROW);
    SetIndexArrow(0,119);
    SetIndexStyle(1,DRAW_ARROW);
    SetIndexArrow(1,119);
    SetIndexStyle(2,DRAW_ARROW);
    SetIndexArrow(2,67);

//----
    SetIndexEmptyValue(0,0.0);
    SetIndexEmptyValue(1,0.0);
    SetIndexEmptyValue(2,0.0);

//---- name for DataWindow
    SetIndexLabel(0,"Fractal Up");
    SetIndexLabel(1,"Fractal Down");
    SetIndexLabel(2, "TEST");
    
    
  
    

//---- initialization done   
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- TODO: add your code here
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    i,nCountedBars;
   bool   bFound;
   double dCurrent;
   nCountedBars=IndicatorCounted();
//---- last counted bar will be recounted    
   if(nCountedBars<=2)
      i=Bars-nCountedBars-3;
   if(nCountedBars>2)
     {
      nCountedBars--;
      i=Bars-nCountedBars-1;
     }      
     
     
     
        
//----Up and Down Fractals
   while(i>=2)
     {
      //----Fractals up
      bFound=false;
      dCurrent=High[i];
      
        if(dCurrent>High[i+1] /*&& dCurrent>High[i+2]*/ && dCurrent>High[i-1] /*&& dCurrent>High[i-2]*/)
        {
         bFound=true;
         ExtUpFractalsBuffer[i]=dCurrent;
         Print(iTime(0,0,0));
        }
                                    
      //----Fractals down
      bFound=false;
      dCurrent=Low[i];
      if(dCurrent<Low[i+1] /*&& dCurrent<Low[i+2]*/ && dCurrent<Low[i-1] /*&& dCurrent<Low[i-2]*/)
        {
         bFound=true;
        ExtDownFractalsBuffer[i]=dCurrent;
        }
        
      i--;
     }
     
     a = (dCurrent>High[i+1] && dCurrent>High[i-1]);
       
       while(a)
       {
       {
       High_Array[h]=dCurrent;
       }
       if(High_Array[0]<High_Array[1])
       {
       testBUFFER[i]=dCurrent;
       }
       dCurrent++;
       }
//----
   return(0);
  }
//+------------------------------------------------------------------+

Here is the full code. It's essentially a fractals indictor with this array addition 

Thank you for your help whroeder1

 
  1. torexvir: So i have to find a way to convert  into an integer value first so i can increment it with a++ instead of writing it out as a boolean ?

    You are missing the point. A boolean is true or false. incrementing it makes no sense. If it is cloudy today, what does cloudy today plus one mean?

  2.      a = (dCurrent>High[i+1] && dCurrent>High[i-1]);
           
           while(a)
           {
           {
           High_Array[h]=dCurrent;
           }
           if(High_Array[0]<High_Array[1])
           {
           testBUFFER[i]=dCurrent;
           }
           dCurrent++;
           }
    Infinite loop, "a" never changes inside the loop.
  3. What does a price plus one mean?
  4. Why are you looking at the same two elements inside the loop. That condition is constant.
  5. "h" never changes inside the loop. Why are you assigning the same element multiple times
Reason: