MaxH Some operator expected

 

Hi,

I'm teaching myself how to program in mql4 and while working on an indicator I came across this problem on line 83.

MaxH = Prices[ArrayMaximum(Prices,period,i)];

the compile error is:

'MaxH' - some operator expected

I wondered if anyone could give me some advice as to what I've done wrong?

I've attached the file, thanks. 

Improperly formatted code edited by moderator. Please use the CODE button (Alt-S) when inserting code.

Code button in editor

Files:
forum.mq4  4 kb
 
mql4acc:
'MaxH' - some operator expected

Always consider that the error may be in the lines above the reported error line.

In this case, you are missing a semicolon on the previous line to terminate it, and you were using an open parenthesis instead of a brace .

for(i=limit; i>=0; i--)                                                                            
   {  // <-- should be an opening brace " { ", not parenthesis " ( "
      Prices[i]=iMA(NULL,0,1,0,MODE_SMA,PriceType,i);    // <-- Was missing a semicolon at the end
      MaxH = Prices[ArrayMaximum(Prices,period,i)];  

There are possibly other errors. I did not check, nor did I compile to verify.

 
Fernando Carreiro #:

Always consider that the error may be in the lines above the reported error line.

In this case, you are missing a semicolon on the previous line to terminate it, and you were using an open parenthesis instead of a brace .

There are possibly other errors. I did not check, nor did I compile to verify.

Thank you so much! I made the changes you suggested, and recompiled and found some other unbalanced braces, once I fixed them it compiled without error.

I really appreciate your response, as I have been trying to fix this every night without success.

I've noted to use the code button in future, when inserting code, thanks

 
Hi, upon attaching the indicator to the chart there is a problem as my indicator window doesn't draw any lines. I think it is to do with #property strict.
If I comment out #property strict all seems good, but I understand this is not best practice.
I think my issues maybe on lines 72 as I'm using some old language IndicatorCounted() and don't know how better to express this.
Having checked the logs it says "array out of range in 'forum.mq4' (81,8)" So I think there is an issue with the for loop iMA?

Possibly it isn't checking the entire array? Please could someone give advice, thanks. I am very new to programming and the forum.


Line72

int  i,limit;                                                                                                   
int  counted_bars=IndicatorCounted(); 
//int counted_bars=Bars(Symbol(),0);    

81,8? I'm assuming that numbers referred to in the log are lines in the code?, if so this is line 81

for(i=limit; i>=0; i--)                                                                            
        { 
        Prices[i]=iMA(NULL,0,1,0,MODE_SMA,PriceType,i);   



Appended/Merged by moderator. Please don't post the same topic multiple times. Continue on the existing one.

I added this as a follow up question in a previous post, but didn't receive a reply. Is that normal or am I doing it wrong?

If I comment out #property strict all seems good, but I understand this is not best practice.

I think my issues maybe with some of old language I'm using like, IndicatorCounted() but I don't know how better to express this yet as I'm a beginner.
I also think there is an issue with the for loop iMA?

Possibly it isn't checking the entire array?

Please could someone give advice, thanks. I am very new to programming and the forum.

Files:
forum.mq4  4 kb
 
  1. mql4acc:

    I added this as a follow up question in a previous post, but didn't receive a reply. Is that normal or am I doing it wrong?

    You should have stayed there.

  2. mql4acc: If I comment out #property strict all seems good, but I understand this is not best practice.
    Always use strict. Fixing the warnings will save you hours of debugging, but you must understand the differences.
  3. mql4acc: I think my issues maybe with some of old language I'm using like, IndicatorCounted() but I don't know how better to express this yet as I'm a beginner.

    You should stop using the old event handlers (init, start, deinit) and IndicatorCounted() and start using new event handlers (OnInit, OnTick/OnCalculate, OnDeinit).
              Event Handling Functions - MQL4 Reference
              How to do your lookbacks correctly - MQL4 programming forum #9-14 & #19 (2016)

  4. mql4acc: I also think there is an issue with the for loop iMA?
             Values[i] = 0.33*2*((Prices[i]-MinL)/(MaxH-MinL)-0.5)+0.67*Values[i+1]; 
    

    Your lookback is one. When your process the first bar, Values[i+1] exceeds the array and indicator crashes with strict.
              How to do your lookbacks correctly #9#14 & #19 (2016)

 

Many thanks to Mr Carreiro and Mr Roeder,


I'm now making slow but steady progress.

I've managed to make things slightly better as  indicators lines now appear in the separate window, however things are still amiss:

1. Crossovers aren't crossing over at relevant crossover points.

2. Indicator buffers mapping isn't auto setting the levels value (I, at least think I've programmed it to do this on lines 39-42)

3 it seems there are a lot of numbers appearing next to the IndicatorShortName, and I've no idea how they have appeared.


Could someone please assist further and maybe supply some code or more advice on how to correct these issues.


Many thanks.

Files:
forum.mq4  5 kb
 

I persevered, and resolved the issue. Unsurprisingly the help I required was linked within Mr Roeders' post number 4

Here is the incorrect code, followed below by the correct alternative. I would love to know why one works and the other doesn't so I will study the differences.  Can anyone explain why one worked and not the other?

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//--- Start of code for OnCalculate

int total=0;

if(prev_calculated==0)
  {
   total=rates_total-1;
  }
else
  {
   total=rates_total-prev_calculated;
  }
  
 
for(int i=0; i<total; i++) //currently using this line as it seems to work correctly with property strict                                                                          
        { 
        Prices[i]=iMA(NULL,0,1,0,MODE_SMA,PriceType,i);     
        
        double MaxH = Prices[ArrayMaximum(Prices,period,i)];      
   double MinL = Prices[ArrayMinimum(Prices,period,i)];         
        if (MaxH!=MinL)                                      
                        Values[i] = 0.33*2*((Prices[i]-MinL)/(MaxH-MinL)-0.5)+0.67*Values[i+1]; 
        else  Values[i] = 0.00;
                        Values[i] = MathMin(MathMax(Values[i],-0.999),0.999); 
        
        buffer1[i] = 0.5*MathLog((1+Values[i])/(1-Values[i]))+0.5*buffer1[i+1]; 
        if (showSignalLine)
        buffer2[i] = buffer1[i+1];                                                                      
            
   }
   
//--- End of code for OnCalculate  
   return(rates_total);
}

This is the code that resolved my issue:

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//--- Start of code for OnCalculate
int lookback=1;
int total=0;

if(prev_calculated==0)
  {
   total=rates_total;
  }
else
  {
   total=rates_total-prev_calculated;
  }
  
 
//for(int i=0; i<total; i++) //currently using this line as it seems to work correctly with property strict                                                                        
for(int i = Bars-1-MathMax(lookback, prev_calculated); i >= 0; --i)     
        { 
        Prices[i]=iMA(NULL,0,1,0,MODE_SMA,PriceType,i);     
        
        double MaxH = Prices[ArrayMaximum(Prices,period,i)];      
   double MinL = Prices[ArrayMinimum(Prices,period,i)];         
        if (MaxH!=MinL)                                      
                        Values[i] = 0.33*2*((Prices[i]-MinL)/(MaxH-MinL)-0.5)+0.67*Values[i+1]; 
        else  Values[i] = 0.00;
                        Values[i] = MathMin(MathMax(Values[i],-0.999),0.999); 
        
        buffer1[i] = 0.5*MathLog((1+Values[i])/(1-Values[i]))+0.5*buffer1[i+1]; 
        if (showSignalLine)
        buffer2[i] = buffer1[i+1];                                                                      
            
   }
   
//--- End of code for OnCalculate  
   return(rates_total-1);
  }

It's this post on how to do your lookbacks correctly, that helped me. I had been using a suggestion from Jim Dandys' video which seemed to make sense (to me a beginner) but it was wrong and this forum was correct.

Can anyone explain why one worked and not the other?

Thanks.

MaxH Some operator expected
MaxH Some operator expected
  • 2024.10.17
  • mql4acc
  • www.mql5.com
Hi, I'm teaching myself how to program in mql4 and while working on an indicator I came across this problem on line 83...
 
mql4acc #: Can anyone explain why one worked and not the other?
  1.    total=rates_total-1;
    

    This doesn't account for any lookback.

  2. for(int i=0; i<total; i++) //currently using this line as it seems to work correctly with property strict
    

    This is computing from the newest to oldest bar. No lookback possible.