EA not working under Build 610

[Deleted]  

Hello all,

I've recently updated to MT4 Build 610 and have transferred the source MQL4 file across for my expert advisor, tried to compile and it comes up with 14 errors and 12 warnings.

'.' - semicolon expected

')' - semicolon expected

'.' - semicolon expected

')' - semicolon expected

check operator precedence for possible error; use parentheses to clarify precedence

check operator precedence for possible error; use parentheses to clarify precedence

check operator precedence for possible error; use parentheses to clarify precedence

check operator precedence for possible error; use parentheses to clarify precedence

check operator precedence for possible error; use parentheses to clarify precedence

check operator precedence for possible error; use parentheses to clarify precedence

'Max' - undeclared identifier

'Lot' - struct or class type expected

'Lot' - undeclared identifier

'Step' - struct or class type expected

'Step' - struct or class type expected

'Max' - undeclared identifier

'Lot' - struct or class type expected

'Lot' - undeclared identifier

'Step' - struct or class type expected

'Step' - struct or class type expected

variable 'GetLotsLong' not used

variable 'GetLotsShort' not used

declaration of 'Risk' hides global declaration at line 20

not all control paths return a value

declaration of 'Risk' hides global declaration at line 20

not all control paths return a value

14 error(s), 12 warning(s)

These warnings do not appear in the previous build and was a decent fully functioning EA with no errors or warnings.

This is really frustrating since I was in the final stages of tweeking my EA.

I also transferred my custom indicator over, and when compiled it produces 100 errors and warnings.

I don't know where to start to make this EA work. Is it straight forward correcting the code to work with the latest build. I really don't know where to start.

Chris.

Mladen Rakic
232281
crsnape@btinternet.com:
Hello all,

I've recently updated to MT4 Build 610 and have transferred the source MQL4 file across for my expert advisor, tried to compile and it comes up with 14 errors and 12 warnings.

'.' - semicolon expected

')' - semicolon expected

'.' - semicolon expected

')' - semicolon expected

check operator precedence for possible error; use parentheses to clarify precedence

check operator precedence for possible error; use parentheses to clarify precedence

check operator precedence for possible error; use parentheses to clarify precedence

check operator precedence for possible error; use parentheses to clarify precedence

check operator precedence for possible error; use parentheses to clarify precedence

check operator precedence for possible error; use parentheses to clarify precedence

'Max' - undeclared identifier

'Lot' - struct or class type expected

'Lot' - undeclared identifier

'Step' - struct or class type expected

'Step' - struct or class type expected

'Max' - undeclared identifier

'Lot' - struct or class type expected

'Lot' - undeclared identifier

'Step' - struct or class type expected

'Step' - struct or class type expected

variable 'GetLotsLong' not used

variable 'GetLotsShort' not used

declaration of 'Risk' hides global declaration at line 20

not all control paths return a value

declaration of 'Risk' hides global declaration at line 20

not all control paths return a value

14 error(s), 12 warning(s)

These warnings do not appear in the previous build and was a decent fully functioning EA with no errors or warnings.

This is really frustrating since I was in the final stages of tweeking my EA.

I also transferred my custom indicator over, and when compiled it produces 100 errors and warnings.

I don't know where to start to make this EA work. Is it straight forward correcting the code to work with the latest build. I really don't know where to start.

Chris.

You have to remove the "." from the names of the variables for the start

If blocks will be best if you make if from a few smaller steps (or else you will not have the correct result of the logical operations)

The last ones are just warning and are benign

[Deleted]  

Hi mladen,

Thanks for your reply.

I will remove the dot from variable names to clear up this error.

What do you mean by:

If blocks will be best if you make if from a few smaller steps (or else you will not have the correct result of the logical operations). I don't quite understand.

Mladen Rakic
232281
crsnape@btinternet.com:
Hi mladen,

Thanks for your reply.

I will remove the dot from variable names to clear up this error.

What do you mean by:

If blocks will be best if you make if from a few smaller steps (or else you will not have the correct result of the logical operations). I don't quite understand.

for example if you have :

if (value1==value2 || value3==value4 && value5==value6)

you have to do either this :

if ((value1==value2 || value3==value4) && value5==value6)

or (making smaller part first) :

bool cond1 = (value1==value2 || value3==value4);

bool cond2 = (value5==value6);

and then combining :

if (cond1 && cond2)

Otherwise metatrader may evaluate the logical (boolean) conditions in the way you do not wish it to be. This is just a simple example. Some examples are much more complicated and then they really need to be taken care of in order to make sure that all is evaluated properly

[Deleted]  

Ah I see.

What about this error: "'Lot' - struct or class type expected?"

I think I understand the reason for this error: "'Max' - undeclared identifier", because I have Max.Lot as a variable name.

So are these two errors related?

If I change the variable from Max.Lot to MaxLot will that extinguish both errors?

Mladen Rakic
232281
crsnape@btinternet.com:
Ah I see.

What about this error: "'Lot' - struct or class type expected?"

I think I understand the reason for this error: "'Max' - undeclared identifier", because I have Max.Lot as a variable name.

So are these two errors related?

If I change the variable from Max.Lot to MaxLot will that extinguish both errors?

Yes

As soon as you remove the "." that error will disapear

[Deleted]  

Oh good. Hopefully I should be able to correct a lot of these errors and warnings this weekend then.

There's another error: not all control paths return a value

And from researching online I have come to understand it means maybe some "if else" block does not consider all the possibilities as a return. Do you think this is right?

The other error is: declaration of 'Risk' hides global declaration at line 20

I have researched this also and someone has stated not to declare the same variable with global scope and also with local scope, which could give rise to this error.

Is this right? What does it mean?

Mladen Rakic
232281
crsnape@btinternet.com:
Oh good. Hopefully I should be able to correct a lot of these errors and warnings this weekend then.

There's another error: not all control paths return a value

And from researching online I have come to understand it means maybe some "if else" block does not consider all the possibilities as a return. Do you think this is right?

The other error is: declaration of 'Risk' hides global declaration at line 20

I have researched this also and someone has stated not to declare the same variable with global scope and also with local scope, which could give rise to this error.

What does this mean?

Usually it means that you have a function that does not return a value

For example :

int start()

{

doing some code processing

//

//

//

//

//

no return(0); line at the end of the start function and it declared as int start()

}

check if you have cases like that (in 99% of cases it is what happens)

[Deleted]  

I think I understand mladen, so,

int Start ()

{

My code all in here

}

Return (0); <-- this could be what's missing?

I'm pretty sure this is in there but will double check.

Mladen Rakic
232281
crsnape@btinternet.com:
I think I understand mladen, so,

int Start ()

{

My code all in here

}

Return (0); <-- this could be what's missing?

I'm pretty sure this is in there but will double check.

No,

Like this

int Start ()

{

My code all in here

Return (0); <-- this could be what's missing?

}

[Deleted]  

Hi mladen,

I've ironed out all the errors in my code and I am only left with 4 warnings as detailed below:

1. declaration of 'Risk' hides global declaration at line 20

2. not all control paths return a value

3. declaration of 'Risk' hides global declaration at line 20

4. not all control paths return a value

The first error picks up 'Risk' at line 20 which is shown below:

extern double Risk = 5; // Risk allocated per trade, in percents

The warning highlights the row highlighted in red below:

//--- Function for calculating lots for long positions

double GetLotsLong (double SLDistanceLong, double DonchianLowM5, double Risk)

{

RefreshRates();

double MinLots, MaxLots, LotStep;

double LotsLong = 0;

int LotDigit = 2;

SLDistanceLong = (Ask - DonchianLowM5) / 0.0001;

MinLots = NormalizeDouble(MarketInfo(Symbol(), MODE_MINLOT), 2); // Lots need to be normalized to accommodate LotStep.

MaxLots = NormalizeDouble(MarketInfo(Symbol(), MODE_MAXLOT), 2); // Normalization does not round, but cuts any portion of lot that is larger than LotStep.

LotStep = NormalizeDouble(MarketInfo(Symbol(), MODE_LOTSTEP), 2); // That way the risk is a bit smaller.

if (MarketInfo(Symbol(), MODE_DIGITS) == 3 || MarketInfo(Symbol(), MODE_DIGITS) == 5) SLDistanceLong *= 10.0;

if (LotStep == 1.00) LotDigit = 0;

if (LotStep == 0.10) LotDigit = 1;

if (LotStep == 0.01) LotDigit = 2;

if (Risk > 0)

{

Print("Risk percentage ready for use in lots calculation");

if (AccountBalance() > AccountFreeMargin())

LotsLong = NormalizeDouble(AccountFreeMargin() * (Risk / 100) / (SLDistanceLong * MarketInfo (Symbol(), MODE_TICKVALUE)), LotDigit);

else LotsLong = NormalizeDouble(AccountBalance() * (Risk / 100) / (SLDistanceLong * MarketInfo (Symbol(), MODE_TICKVALUE)), LotDigit);

LotsLong = NormalizeDouble(NormalizeDouble(LotsLong / LotStep, 0) * LotStep, LotDigit);

LotsLong = MathMax(LotsLong, MinLots);

Print("Position size calculated successfully using derived risk percentage");

return (LotsLong);

}

else Print("Error calculating position size for long position", GetLastError());

}

Just to clarify this function is used to calculate a position size and is called from within Start {}. This code is positioned outside of Start{}.

The second warning 'not all control paths return a value' is also related to this section of code, and I have highlighted the row in blue (just the small bracket at the end of the code above).

Do you know why this is happening?

Just to confirm, I do have:

Start

{

code in here

}

return(0);

The last two warnings are an exact copy of the first two but relate to my position size calculation for short positions as opposed to long positions which is a seperate section of code.

Any help here would be very much appreciated!!

PS- sorry I do not know how to paste code so it retains its indentation.

Thanks,

Chris.