How do I write this function without "possible loss of data due to type conversion" warning ?
int StepIndex(int PosIndex)
if(OrderSelect(PosIndex,SELECT_BY_POS,MODE_TRADES) == true)
S10 = NormalizeDouble(((Bid-OrderOpenPrice())/10*Point),0);
S10 is an integer variable and you assign a double value to it and compiler warns you that double value will be truncated.
To eliminate that warning (if you really want to truncate result), you must cast the result of a function to an integer. This will show to the compiler that you really want that to happen.
S10 = (int) NormalizeDouble(((Bid-OrderOpenPrice())/10.0*Point),0);
thank you very much indeed, I searched a lot.
so the parenthesis means that "hey MQL! I know it convert double to int". haha...
void StepIndex(int PosIndex)
if( OrderSelect( PosIndex, SELECT_BY_POS, MODE_TRADES ) )
S10 = (int) round( ( OrderClosePrice() - OrderOpenPrice() ) / ( _Point * 10.0 ) );
1. yes you are right.
2. why OrderClosePrice, it is in TRADES not HISTORY ? besides I need to subtract last current price from OrderOpenPrice, whatever its OrderType is.
3. I want cut off everything after dot, even it would be 9.
5. I set this as an extern to change it on start, and it is 5 digits, what if it would be 4 digits ?
6. I chnged it to 10.0. is it ok?
8. I just declare S10. and need the value in my EA, what did I wrong ?
9. I started learning since 2 weeks age and I know the basics and trying to make simple EAs, but the points that you mention was not in my tutorial. :))
thank you that you take time for me
Then use "round()", or "floor()" or "ceil()" depending on what you need.
Overall you are missing the main point. It is not a question of fixing "bugs", but that in general you don't really understand the main concepts and constructs that you are using.
So, until you do. First practice by coding small pieces of "C" code that is independent of it working in Meta-trader and as a EA. Use online resources that go though all the steps from beginner to a higher level of coding in "C".
You missed the joke here.
The hilarious thing is when you, for example, calculate stop loss price for the EUR/USD and your function instead of 1.14001 returns integer 1 and your account burns because of that.
After you suffer a huge loss, you'll learn why this warning should be carefully investigated and why is it a good thing that compiler asks you to explicitly confirm that you want to truncate double to integer.