iCustom a weird issue

 

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 

 
try to replace the "double" with "int"
 
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;
 
Iceron:

Maybe this?

Thanks, Iceron.

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

HHC 

 
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
 
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;
 
ismail77:

Thanks you all for explaining.

HHC 

Reason: