 Ema Cross!
 To set EA's lotsize as 0.01 is not validated. Why?
 Once i click button EA Runs in to access violation error.
Without a code sample, we don’t have the foggiest idea of what you are doing (correctly or incorrectly), nor can we guess what you should be doing.
All I can ask is, are you properly adjusting to the symbol’s volume step and verifying for the minimum and maximum volume allowed?
Forum on trading, automated trading systems and testing trading strategies
How to calculate lots using multiplier according to number of opened orders?
Fernando Carreiro, 2017.09.01 21:57
Don't use NormalizeDouble(). Here is some guidance (code is untested, just serves as example):
// Variables for Symbol Volume Conditions double dblLotsMinimum = SymbolInfoDouble( _Symbol, SYMBOL_VOLUME_MIN ), dblLotsMaximum = SymbolInfoDouble( _Symbol, SYMBOL_VOLUME_MAX ), dblLotsStep = SymbolInfoDouble( _Symbol, SYMBOL_VOLUME_STEP ); // Variables for Geometric Progression double dblGeoRatio = 2.8, dblGeoInit = dblLotsMinimum; // Calculate Next Geometric Element double dblGeoNext = dblGeoInit * pow( dblGeoRatio, intOrderCount + 1 ); // Adjust Volume for allowable conditions double dblLotsNext = fmin( dblLotsMaximum, // Prevent too greater volume fmax( dblLotsMinimum, // Prevent too smaller volume round( dblGeoNext / dblLotsStep ) * dblLotsStep ) ); // Align to Step value
 Revo Trades: But why do i often get some weird numbers?
Floatingpoint has an infinite number of decimals, it's you, not understanding floatingpoint and that some numbers can't be represented exactly. (like 1/10.)
Doubleprecision floatingpoint format  WikipediaSee also The == operand.  MQL4 programming forum 2013.06.07
If you want to see the correct number of digits, convert it to a string with the correct/wanted accuracy.
question about decima of marketinfo()  MQL4 programming forum 2016.05.18  Fernando Carreiro:
round( dblGeoNext / dblLotsStep ) * dblLotsStep ) ); // Align to Step value
I prefer to make an explicit function call.
MT4:NormalizeDouble  General  MQL5 programming forum #3.3 2017.01.04
How to Normalize  Expert Advisors and Automated Trading  MQL5 programming forum #2 2017.05.19

Floatingpoint has an infinite number of decimals, it's you, not understanding floatingpoint and that some numbers can't be represented exactly. (like 1/10.)
Doubleprecision floatingpoint format  WikipediaSee also The == operand.  MQL4 programming forum 2013.06.07
If you want to see the correct number of digits, convert it to a string with the correct/wanted accuracy.
question about decima of marketinfo()  MQL4 programming forum 2016.05.18 
I prefer to make an explicit function call.
MT4:NormalizeDouble  General  MQL5 programming forum #3.3 2017.01.04
How to Normalize  Expert Advisors and Automated Trading  MQL5 programming forum #2 2017.05.19
ok. i will read up. thanks for responding.
so would i be correct in thinking that when i use Digits in Normalize(price,Digits), that Digits does not always report the correct value? and by using the DoubleToString function, how does that improve the end result since that that same function uses the same Digits value?
edit == i think i answered my own question, but please answer the q anyways, so i can confirm my own reasoning. thanks.
Since i believe it is all down to using NormalizeDouble where I shouldnt be, i will try inserting this in my mg/lotsize calculations. If you suspect any issues resulting, please point them out in a reply.
#property strict //global double fibo[]={1,1,2,3,5,8,13,21,55}; input double iStartLot = 0.25; //mg lotsize func double round (double z) // z == place in the fibo buffer { int D= MathPow(10,Digits); double value = fibo[z] * iStartLot; double x = ( MathRound (value * D)) / D * z; return(x); } //example OrderSend == round(6) == lotsize = (expected value) = fibo[6] * 0.25 == 13 * 0.25, or 3.25 OrderSend(_Symbol,OP_BUY,round(6),Ask,1,0,0,iComment,iMagic,0,clrBlue);
Note: completely untested. Any suggestions or criticism accepted.
Since i believe it is all down to using NormalizeDouble where I shouldnt be, i will try inserting this in my mg/lotsize calculations. If you suspect any issues resulting, please point them out in a reply.
Note: completely untested. Any suggestions or criticism accepted.
No NormaliseDouble needed! Is this what you are after (untested/uncompiled)?
#property strict //global fibo[]={1,1,2,3,5,8,13,21,55}; input iStartLot = 0.25; //mg lotsize func double FiboLotSize( int index ) { // Variables for Symbol Volume Conditions double dblLotsMinimum = SymbolInfoDouble( _Symbol, SYMBOL_VOLUME_MIN ), dblLotsMaximum = SymbolInfoDouble( _Symbol, SYMBOL_VOLUME_MAX ), dblLotsStep = SymbolInfoDouble( _Symbol, SYMBOL_VOLUME_STEP ); // Calculate Lot Size based on Fibonacci Sequence double dblLots = iStartLot * fibo[ index ]; // Adjust Volume for allowable conditions dblLots = fmin( dblLotsMaximum, // Prevent too greater volume fmax( dblLotsMinimum, // Prevent too smaller volume round( dblLots / dblLotsStep ) * dblLotsStep ) ); // Align to Step value // Return Calculated Value of Lot Size return dblLots; }; void OnTick(void) { //example OrderSend == round(7) == lotsize = (expected value) = fibo[6] * 0.01 == 13 * 0.01, or 0.13 OrderSend( _Symbol, OP_BUY, FiboLotSize(7), Ask, 1, 0, 0, iComment, iMagic, 0, clrBlue ); };
double dblLots = NormalizeDouble(fmin( dblLotsMaximum, // Prevent too greater volume fmax( dblLotsMinimum, // Prevent too smaller volume round( dblLots / dblLotsStep ) * dblLotsStep ) ),2); // Align to Step value
But i was/am getting weird numbers sometimes, like instead of 3.25 lots, getting 2.75. If I am understanding the readings correctly, NormalizeDouble does not round the same way as the func round does, so this may be the root of my issue. If you concur please respond with a yay or nay. either way I will test the code during london tomoz and report back in 24 hours if nothing has changed. If I dont get any weird lots in 48, then I will jump for joy, and report after that.
But i was/am getting weird numbers sometimes, like instead of 3.25 lots, getting 2.75. If I am understanding the readings correctly, NormalizeDouble does not round the same way as the func round does, so this may be the root of my issue. If you concur please respond with a yay or nay. either way I will test the code during london tomoz and report back in 24 hours if nothing has changed. If I dont get any weird lots in 48, then I will jump for joy, and report after that.
I make it a point in my code to NEVER use NormaliseDouble(), EVER. If you search the forum you will find that this has been debated many, many times in a very heated way. Some in favour of using it and a few like myself, against using it.
I will leave it up to you to decide for yourself what you prefer doing.
Suffice to say, that by using the calculations I have shared above, I've have never had any problems or any errors about invalid volume when placing an order.
 Free trading apps
 Over 8,000 signals for copying
 Economic news for exploring financial markets
You agree to website policy and terms of use