... Unexpected token, probably type is missing? & Function already defined and has different type

 

Hello , in my ZigZag.mqh file when I compile I'm receive the following errors :

'Create' - unexpected token, probably type is missing? ZigZag.mqh 72 10

'Create' - function already defined and has different type ZigZag.mqh 72 10

'Calculate' - unexpected token, probably type is missing? ZigZag.mqh 89 10

'Calculate' - function already defined and has different type ZigZag.mqh 89 10


'AddExtremum' - unexpected token, probably type is missing? ZigZag.mqh 280 10

'AddExtremum' - function already defined and has different type ZigZag.mqh 280 10


there is the object creation :

class CZigZag : public CObject
  {
private:

   void              Calculate();
   void              AddExtremum(double value, datetime time);
//---

public:

   void              Create(string symbol,int depth,int deviation,int backstep,ENUM_TIMEFRAMES timeframe=PERIOD_CURRENT);
  };

there are the functions wich give compiling error :

CZigZag::Create(string symbol,int depth,int deviation,int backstep,ENUM_TIMEFRAMES timeframe=PERIOD_CURRENT) // line 72
  {
   s_Symbol=symbol;
   i_Depth=depth;
   i_Deviation=deviation;
   i_Backstep=(backstep>=depth ? depth-1 : backstep);
   e_TimeFrame=timeframe;
   i_MaxHistory=0;
   dt_LastCalculate=0;
   ArrayFree(ZigZagBuffer);
   d_Point=SymbolInfoDouble(s_Symbol,SYMBOL_POINT);
   i_total=0;
   return;
  }
CZigZag::Calculate()   // line 89
  {
   if (dt_LastCalculate>=iTime(s_Symbol,e_TimeFrame,0))
      return;
   dt_LastCalculate=iTime(s_Symbol,e_TimeFrame,0);
   int    limit=0,whatlookfor=0;
   int    back,lasthighpos=0,lastlowpos=0;
   double extremum;
   double curlow=0.0,curhigh=0.0,lasthigh=0.0,lastlow=0.0;
   int size=i_total-2;
   if (size<=0)
     {
      ArrayFree(ZigZagBuffer);
      i_total=0;
      limit=(i_MaxHistory>0 ? MathMin(iBars(s_Symbol,e_TimeFrame)-i_Depth,i_MaxHistory) : iBars(s_Symbol,e_TimeFrame)-i_Depth);
     }
   else
     {
      i_total--;
      ArrayResize(ZigZagBuffer,i_total);
      limit=iBarShift(s_Symbol,e_TimeFrame,ZigZagBuffer[size].TimeStartBar)+1;
      limit=MathMin(limit,iBars(s_Symbol,e_TimeFrame)-i_Depth);
      if (size>1)
        {
         if (ZigZagBuffer[size-1].Price<ZigZagBuffer[size].Price)
            curhigh=ZigZagBuffer[size-1].Price;
         if (ZigZagBuffer[size-1].Price>ZigZagBuffer[size].Price)
            curlow=ZigZagBuffer[size-1].Price;
        }
      if (curhigh>0)
        {
         limit=iBarShift(s_Symbol,e_TimeFrame,ZigZagBuffer[size].TimeStartBar)+1;
         whatlookfor=-1;
        }
      if (curlow>0)
        {
         limit=iBarShift(s_Symbol,e_TimeFrame,ZigZagBuffer[size].TimeStartBar)+1;
         whatlookfor=1;
        }
      if (curhigh==0 && curlow==0)
        {
         ArrayFree(ZigZagBuffer);
         i_total=0;
         limit=(i_MaxHistory>0 ? MathMin(iBars(s_Symbol,e_TimeFrame)-i_Depth,i_MaxHistory) : iBars(s_Symbol,e_TimeFrame)-i_Depth);
         whatlookfor=0;
        }
     }
//--- main loop
   double ExtHighBuffer[], ExtLowBuffer[];
   ArrayResize(ExtHighBuffer,limit+1+i_Backstep);
   ArrayResize(ExtLowBuffer,limit+1+i_Backstep);
   double low[], high[];
   limit=CopyLow(s_Symbol,e_TimeFrame,0,limit+i_Depth+1,low)-i_Depth-1;
   limit=CopyHigh(s_Symbol,e_TimeFrame,0,limit+i_Depth+1,high)-i_Depth-1;
   ArraySetAsSeries(low,true);
   ArraySetAsSeries(high,true);
   for(int i=limit; i>=0; i--)
     {
      //--- find lowest low in depth of bars
      extremum=low[ArrayMinimum(low,i,i_Depth)];
      //--- this lowest has been found previously
      if(extremum==lastlow)
         extremum=0.0;
      else 
        { 
         //--- new last low
         lastlow=extremum; 
         //--- discard extremum if current low is too high
         if(low[i]-extremum>i_Deviation*d_Point)
            extremum=0.0;
         else
           {
            //--- clear previous extremums in backstep bars
            for(back=1; back<=i_Backstep; back++)
              {
               int pos=i+back;
               if(ExtLowBuffer[pos]!=0 && ExtLowBuffer[pos]>extremum)
                  ExtLowBuffer[pos]=0.0; 
              }
           }
        } 
      //--- found extremum is current low
      if(low[i]==extremum)
         ExtLowBuffer[i]=extremum;
      else
         ExtLowBuffer[i]=0.0;
      //--- find highest high in depth of bars
      extremum=high[ArrayMaximum(high,i,i_Depth)];
      //--- this highest has been found previously
      if(extremum==lasthigh)
         extremum=0.0;
      else 
        {
         //--- new last high
         lasthigh=extremum;
         //--- discard extremum if current high is too low
         if(extremum-high[i]>i_Deviation*d_Point)
            extremum=0.0;
         else
           {
            //--- clear previous extremums in backstep bars
            for(back=1; back<=i_Backstep; back++)
              {
               int pos=i+back;
               if(ExtHighBuffer[pos]!=0 && ExtHighBuffer[pos]<extremum)
                  ExtHighBuffer[pos]=0.0; 
              } 
           }
        }
      //--- found extremum is current high
      if(high[i]==extremum)
         ExtHighBuffer[i]=extremum;
      else
         ExtHighBuffer[i]=0.0;
     }
//--- final cutting 
   if(whatlookfor==0)
     {
      lastlow=0.0;
      lasthigh=0.0;  
     }
   else
     {
      lastlow=curlow;
      lasthigh=curhigh;
     }
   for(int i=limit; i>=0; i--)
     {
      switch(whatlookfor)
        {
         case 0: // look for peak or lawn 
            if(lastlow==0.0 && lasthigh==0.0)
              {
               if(ExtHighBuffer[i]!=0.0)
                 {
                  lasthigh=high[i];
                  lasthighpos=i;
                  whatlookfor=-1;
                  AddExtremum(lasthigh,iTime(s_Symbol,e_TimeFrame,i));
                 }
               if(ExtLowBuffer[i]!=0.0)
                 {
                  lastlow=low[i];
                  lastlowpos=i;
                  whatlookfor=1;
                  AddExtremum(lastlow,iTime(s_Symbol,e_TimeFrame,i));
                 }
              }
             break;  
         case 1: // look for peak
            if(ExtLowBuffer[i]!=0.0 && ExtLowBuffer[i]<lastlow && ExtHighBuffer[i]==0.0)
              {
               i_total--;
               ArrayResize(ZigZagBuffer,i_total);
               lastlowpos=i;
               lastlow=ExtLowBuffer[i];
               AddExtremum(lastlow,iTime(s_Symbol,e_TimeFrame,i));
              }
            if(ExtHighBuffer[i]!=0.0 && ExtLowBuffer[i]==0.0)
              {
               lasthigh=ExtHighBuffer[i];
               lasthighpos=i;
               AddExtremum(lasthigh,iTime(s_Symbol,e_TimeFrame,i));
               whatlookfor=-1;
              }   
            break;               
         case -1: // look for lawn
            if(ExtHighBuffer[i]!=0.0 && ExtHighBuffer[i]>lasthigh && ExtLowBuffer[i]==0.0)
              {
               i_total--;
               ArrayResize(ZigZagBuffer,i_total);
               lasthighpos=i;
               lasthigh=ExtHighBuffer[i];
               AddExtremum(lasthigh,iTime(s_Symbol,e_TimeFrame,i));
              }
            if(ExtLowBuffer[i]!=0.0 && ExtHighBuffer[i]==0.0)
              {
               lastlow=ExtLowBuffer[i];
               lastlowpos=i;
               AddExtremum(lastlow,iTime(s_Symbol,e_TimeFrame,i));
               whatlookfor=1;
              }   
            break;               
        }
     }
//--- done
   return;
  }
CZigZag::AddExtremum(double value, datetime time)  // line 280
  {
   if (i_total==0 || (iTime(s_Symbol,e_TimeFrame,i_MaxHistory)<ZigZagBuffer[0].TimeStartBar || i_MaxHistory<=0))
      ArrayResize(ZigZagBuffer,i_total+1);
   else
     {
      int k=1;
      while (k<i_total && iTime(s_Symbol,e_TimeFrame,i_MaxHistory)<ZigZagBuffer[k].TimeStartBar)
         k++;
      for (int i=0; i<i_total-k; i++)
         {
         ZigZagBuffer[i].Price=ZigZagBuffer[i+k].Price;
         ZigZagBuffer[i].TimeStartBar=ZigZagBuffer[i+k].TimeStartBar;
         }
      i_total-=k;
     }
   ZigZagBuffer[i_total].Price=value;
   ZigZagBuffer[i_total].TimeStartBar=time;
   i_total++;
   if (ArraySize(ZigZagBuffer)>(i_total))
      ArrayResize(ZigZagBuffer,i_total);
   return;
  }

Already searched a lot about the errors but don't understand what is wrong here, hope someone more experienced can tell me what is missing or not right .


Thanks in advance, best regards


Ferox

Documentation on MQL5: Constants, Enumerations and Structures / Named Constants / Predefined Macro Substitutions
Documentation on MQL5: Constants, Enumerations and Structures / Named Constants / Predefined Macro Substitutions
  • www.mql5.com
//| Expert initialization function                                   | //| Expert deinitialization function                                 | //| Expert tick function                                             | //| test1                                                            |...
 

I will not even try to check.

Seriously, you have all the information on the error messages. You can't hope for help posting snippets of code where the line numbers doesn't appear.

If you want help, provide the file itself so it's possible to check directly.

 
It could be that you have a typing error related to ; } { somewhere in your code, resulting in error messages about things further down your code.
 
class CZigZag : public CObject
  {                                  <<< Open (1)
private:
   void              Calculate();
   void              AddExtremum(double value, datetime time);
public:
   void              Create(string symbol,int depth,int deviation,int backstep,ENUM_TIMEFRAMES timeframe=PERIOD_CURRENT);
}                                    <<< What is this?
  };                                 <<< Close (2)
 
Alain Verleyen:

I will not even try to check.

Seriously, you have all the information on the error messages. You can't hope for help posting snippets of code where the line numbers doesn't appear.

If you want help, provide the file itself so it's possible to check directly.

I'm sorry for the mistake Sir, already corrected


Best regards

 
WindmillMQL:
It could be that you have a typing error related to ; } { somewhere in your code, resulting in error messages about things further down your code.

Searched this many times and is not the current problem, but thanks a lot Mr.Windmill.


Best Regards

 
William Roeder:

Thank you Mr. William, was my mistake tipping the relevant code to the forum, I apolagise for that, already corrected it.


Best Regards 

Ferox875

 

Really still don't understand the problem ";" and "{" "}" are good, objects are well created, return type is void and the return is empty .


Any hints how to solve this?


Thanks in advance, best regards

 
         CZigZag::Create(string symbol, …
         CZigZag::AddExtremum(double value, datetime time)  // line 280
No function type?
 
William Roeder:
No function type?

Mr. William, you are so awesome so awesome, thank you very much!!!


Problem solved, thank you again Mr.William, 


Best Regards

Ferox875

 

I also found the same error in codebase, can someone help me correct it, thank you~~

https://www.mql5.com/en/code/159

***

A Really Random Robot
A Really Random Robot
  • www.mql5.com
This robot uses a random number generator to simulate simply tossing a coin to decide on the direction of each trade. It provides an example of a minimal expert advisor programmed in an object-oriented style. It also provides a basis for quantifying the value added by alternative methods of entry.
Reason: