**Sathish Justin:**I am using the following formula for the volume, and while multiplying it is giving result in digits and am getting invalid volume error while testing How can i rectify this?

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

Forum on trading, automated trading systems and testing trading strategies

Volume Limit Reached - Validation for new Expert Advisor error

Fernando Carreiro, 2022.07.22 18:22

Your EA must be coded to read the broker's contract specifications, such volume limitations, and prevent that from happening.

SYMBOL_VOLUME_MIN | double | |

SYMBOL_VOLUME_MAX | Maximal volume for a deal | double |

SYMBOL_VOLUME_STEP | Minimal volume change step for deal execution | double |

SYMBOL_VOLUME_LIMIT | Maximum allowed aggregate volume of an open position and pending orders in one direction (buy or sell) for the symbol. For example, with the limitation of 5 lots, you can have an open buy position with the volume of 5 lots and place a pending order Sell Limit with the volume of 5 lots. But in this case you cannot place a Buy Limit pending order (since the total volume in one direction will exceed the limitation) or place Sell Limit with the volume more than 5 lots. | double |

Thank you sir.

But there will be 5 sets of Buystop or sellstop order will be placed at one go. The numeric "5" shown in the above code will be changed to some different numbers for each of the sets. Then how do i use this, multiplying with the numeric again gives the invalid volume

**Sathish Justin #:**Thank you sir. But there will be 5 sets of Buystop or sellstop order will be placed at one go. The numeric "5" shown in the above code will be changed to some different numbers for each of the sets. Then how do i use this, multiplying with the numeric again gives the invalid volume

Did you even bother to read and analyse my example code which does exactly that?

Put some effort into it if you want to become a better coder!

Sorry, I am into very basics of coding.

First 3 lines of code i understood. (Maximum & Minimum lot size allowed for trading, step also understood (0.01/0.10/etc., steps)

Rest of the code Sorry I don't understand, but my assumption is that if i replace that 2.8 with 5, then in my case 5 will be replaced with 5 and then for the next successive lots it gives 10,15,20,25... is that right?

If so, how can i achieve the result like 1,3,5,8,11, etc., and if it is not in a series?

**Sathish Justin #:**Sorry, I am into very basics of coding. First 3 lines of code i understood. (Maximum & Minimum lot size allowed for trading, step also understood (0.01/0.10/etc., steps). Rest of the code Sorry I don't understand, but my assumption is that if i replace that 2.8 with 5, then in my case 5 will be replaced with 5 and then for the next successive lots it gives 10,15,20,25... is that right? If so, how can i achieve the result like 1,3,5,8,11, etc., and if it is not in a series?

If you are unable to understand the code, then I don't know how I can help you further. You will have to dedicate some time to learning more about the basics of coding.

- 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,

I am using the following formula for the volume, and while multiplying it is giving result in digits and am getting invalid volume error while testing

How can i rectify this?