declaration of 'result' hides global variable

 


Hi, I have this kind of "error", someone can tell me why they are telling me

does the "result" declaration hide the global variable?


double getTrailingStop( int per, datetime openTime, bool isLong, string sym = "" ) {

if ( sym == "" ) { sym = Symbol(); }
// this function will return the trailing stop of the symbol
// dir = TRUE for longs; FALSE for shorts
double result;
int startBar = getOpenBar( openTime, per );
if ( isLong ) { 
result = iHigh( sym, per, startBar ) - getStopDist( per, startBar, sym );
} else {
result = iLow( sym, per, startBar ) + getStopDist( per, startBar, sym );
}
for ( int i = startBar; i > 0; i -= 1 ) {
if ( isLong ) {
// for LONG orders
// loop through the bars since opentime
result = MathMax( iHigh( sym, per, i ) - getStopDist( per, i, sym ), result );
} else {
// for SHORT orders
result = MathMin( iLow( sym, per, i ) + getStopDist( per, i, sym ), result );
}
}
return(result);
}




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
Predefined Macro Substitutions - Named Constants - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
Files:
 
Please edit your post and use the code button (Alt+S) when pasting code.
EDIT your original post, please do not just post the code properly in a new post.
 
SAM TEST: does the "result" declaration hide the global variable?

That is what the warning says. Use global variables sparingly.

 
William Roeder:

That is what the warning says. Use global variables sparingly.

thanks, solved