You have to adjust your volume size based on the the Lot Step and check for both Maximum and Minimum amounts. Here is an example from another thread (pay special attention to beginning and end of the code below):
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
You have to adjust your volume size based on the the Lot Step and check for both Maximum and Minimum amounts. Here is an example from another thread (pay special attention to beginning and end of the code below):
Usually i would have used the following code that is similar to the one you gave.
But i still get the problem of no trades being placed?
//+------------------------------------------------------------------+ //| Check the correctness of the order volume | //+------------------------------------------------------------------+ bool CheckVolumeValue(double volume) { //--- minimal allowed volume for trade operations double min_volume=MarketInfo(Symbol(),MODE_MINLOT); if(volume<min_volume) { Print("Volume is less than the minimal allowed. Minimum allowed is ",min_volume); return(false); // If womeone types lower than minimum lotvolume it returns print } //--- maximal allowed volume of trade operations double max_volume=MarketInfo(Symbol(),MODE_MAXLOT); if(volume>max_volume) { Print("Volume is greater than the maximal allowed. Maximum allowed is ",max_volume); return(false); } //--- get minimal step of volume changing double volume_step=MarketInfo(Symbol(),MODE_LOTSTEP); int ratio=(int)MathRound(volume/volume_step); if(MathAbs(ratio*volume_step-volume)>0.0000001) { PrintFormat("Volume is not a multiple of the minimal step SYMBOL_VOLUME_STEP=%.2f, the closest correct volume is %.2f", volume_step,ratio*volume_step); return(false); } Print("Correct volume value"); return(true); }Am i right in realising the validation test can only as with 1.0 lot size? As ive tried both 0.1 and 10.0 lots and validation fails but its okay only with 1.0?
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi, why in the following code cant I get it passed validation without having to have lotsize = 1.0
Any smaller lot size and i get error 131?