Ive come across a warning when writing an expert advisor that I don't understand. I have some ideas on why I'm getting it but was hoping someone could clarify. I'm getting the warning possible loss of data due to type conversion warning when compiling the code attached. I know this error is normally caused when trying to use the wrong data type with the normaliseDouble function but im passing a double type variable into it in onTick. I'm also not sure if the warning is something to do with the pass by reference element and possibly my improper use of it?
This is the proper way to adjust the Volume (lots) for an Order (don't use NormalizeDouble) :
void lotSizeChecks( double &lotSize ) { double volumeMinimum = SymbolInfoDouble( _Symbol, SYMBOL_VOLUME_MIN ), volumeMaximum = SymbolInfoDouble( _Symbol, SYMBOL_VOLUME_MAX ), volumeStep = SymbolInfoDouble( _Symbol, SYMBOL_VOLUME_STEP ); lotSize = fmin( volumeMaximum, // Prevent too greater volume fmax( volumeMinimum, // Prevent too smaller volume round( lotSize / volumeStep ) * volumeStep ) ); // Align to Step value }
Also, the reason you were getting a "possible loss of data", was because of the "roundingDigits" argument which should have been of the "int" type and not a "double" (for NormalizeDouble).
For warnings and errors, you should always look at the line number, and column position, to identify the problem.
Why am I getting the same warrning on the 3 lines below when the fast, slow, and stop variables are all declared as int?
if ( Use_Globals == 1 )
{
string prefix = Symbol() + IntegerToString(Period());
if ( GlobalVariableCheck( prefix + "_FastMA_Periods" ) > 0 ) iFastMA_Periods = GlobalVariableGet( prefix + "_FastMA_Periods" ); else iFastMA_Periods = FastMA_Periods;
if ( GlobalVariableCheck( prefix + "_SlowMA_Periods" ) > 0 ) iSlowMA_Periods = GlobalVariableGet( prefix + "_SlowMA_Periods" ); else iSlowMA_Periods = SlowMA_Periods;
if ( GlobalVariableCheck( prefix + "_StopMA_Periods" ) > 0 ) iStopMA_Periods = GlobalVariableGet( prefix + "_StopMA_Periods" ); else iStopMA_Periods = StopMA_Periods;
}
BillRitz #:
Why am I getting the same warrning on the 3 lines below when the fast, slow, and stop variables are all declared as int?
if ( GlobalVariableCheck( prefix + "_FastMA_Periods" ) > 0 ) iFastMA_Periods = GlobalVariableGet( prefix + "_FastMA_Periods" ); else iFastMA_Periods = FastMA_Periods;
Because GlobalVariableGet returns double
https://www.mql5.com/en/docs/globals/globalvariableget
Returns the value of an existing global variable of the client terminal. There are 2 variants of the function.
1. Immediately returns the value of the global variable.
double GlobalVariableGet( string name // Global variable name );

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Ive come across a warning when writing an expert advisor that I don't understand. I have some ideas on why I'm getting it but was hoping someone could clarify. I'm getting the warning possible loss of data due to type conversion warning when compiling the code attached. I know this error is normally caused when trying to use the wrong data type with the normaliseDouble function but im passing a double type variable into it in onTick. I'm also not sure if the warning is something to do with the pass by reference element and possibly my improper use of it?