Download MetaTrader 5

iCustom a weird issue

To add comments, please log in or register
Start making profit using the Market. Publish your product!
hhchenfx
886
hhchenfx 2014.10.22 05:19 

Hello,

I fall in a problem where the following code directly uses iCustom works

if(iCustom(NULL,0,"indiname",7,10,199,0,i)==-3 )   sell[i]=1;

 But the below using a middle variable doesn't work.

double medium1=iCustom(NULL,0,"indiname",7,10,199,0,i);

if(medium1==-3 ) double good=1;

sell[i]=good;

 

I thought that the above 2 codes should be  be the same. Definitely I am wrong but I dont know how to fix it.  

Please help. 

Many thanks.

HHC 

Umar Ismail
10491
Umar Ismail 2014.10.22 05:35  
try to replace the "double" with "int"
Enrico Lambino
4323
Enrico Lambino 2014.10.22 09:41  
hhchenfx:

Hello,

I fall in a problem where the following code directly uses iCustom works

 But the below using a middle variable doesn't work.

 

I thought that the above 2 codes should be  be the same. Definitely I am wrong but I dont know how to fix it.  

Please help. 

Many thanks.

HHC 

Maybe this?

double good=0.0;

double medium1=iCustom(NULL,0,"indiname",7,10,199,0,i);

if(medium1==-3 ) good=1;

sell[i]=good;
hhchenfx
886
hhchenfx 2014.10.22 16:37  
Iceron:

Maybe this?

Thanks, Iceron.

but why your works and mine fail? I am really curious.

HHC 

Enrico Lambino
4323
Enrico Lambino 2014.10.23 02:12  
hhchenfx:

Thanks, Iceron.

but why your works and mine fail? I am really curious.

HHC 



double medium1=iCustom(NULL,0,"indiname",7,10,199,0,i);

if(medium1==-3 ) 
{
   double good=1; //variable good is declared and assigned a value
   //scope of good is only between the brackets
}
//good is already out of scope
sell[i]=good; //unknown variable good (undeclared identifier)


Your code is fine, but you are using #property strict on your code. 

New MQL4 with #property strict: Variable scope is from declaration to the end of the block, in which the variable is declared

http://docs.mql4.com/mql4changes#compiler_difference

Either remove the strict property or update the code to the changes.
What's New in MQL4 - MQL4 Documentation
  • docs.mql4.com
What's New in MQL4 - MQL4 Documentation
Umar Ismail
10491
Umar Ismail 2014.10.23 04:28  
hhchenfx:

Hello,

I fall in a problem where the following code directly uses iCustom works

 But the below using a middle variable doesn't work.

 

I thought that the above 2 codes should be  be the same. Definitely I am wrong but I dont know how to fix it.  

Please help. 

Many thanks.

HHC 

double medium1=0;//or int medium1=0;
medium1=iCustom(NULL,0,"indiname",7,10,199,0,i);
double good=0;//or  int good=0;
if(medium1==-3 ) good=1; sell[i]=good;
hhchenfx
886
hhchenfx 2014.10.24 02:58  
ismail77:

Thanks you all for explaining.

HHC 

To add comments, please log in or register