I have tested this code in MT4 build 788 in both ECN and normal accounts, its ok in both cases. What problem exactly do you get?
It showing as "ordersend error 131 - wrong volume"
You have to normalize your volume, nothing to do with ECN or not.
You have to call function NormalizeDouble with first parameter - your volume, and second parameter - digits in lot, usually 2 or 1. This will make sure that your volume has only two decimal digits. Its similar to round, and must be mandatory used for all volumes and prices before OrderSend.
Vol = NormalizeDouble(Vol, 2);
Also, make sure to do the same with your order price, stoploss, takeprofit:
double orderPrice = Ask; double orderStoploss = Ask-0.001; orderPrice = NormalizeDouble(orderPrice, _Digits); orderStoploss = NormalizeDouble(orderStoploss, _Digits);
Usually I use following code to make sure that volume is setup according to broker settings:
//+------------------------------------------------------------------+ //| volume_norm.mq4 | //| Copyright 2015, Dr.Trader | //| https://www.mql5.com/en/users/dr.trader | //+------------------------------------------------------------------+ #property copyright "Copyright 2015, Dr.Trader" #property link "https://www.mql5.com/en/users/dr.trader" #property version "1.00" #property strict int _LotDigits; double _MinLot; double _MaxLot; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- _LotDigits = 0; double lotStep = MarketInfo(_Symbol, MODE_LOTSTEP); while(MathRound(lotStep) != lotStep){ _LotDigits++; lotStep *= 10.0; } _MinLot = NormalizeDouble(MarketInfo(_Symbol, MODE_MINLOT), _LotDigits); _MaxLot = NormalizeDouble(MarketInfo(_Symbol, MODE_MAXLOT), _LotDigits); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- double orderVolume = 0; //insert your money management code here //... //... if (orderVolume < _MinLot){ orderVolume = _MinLot; } if (orderVolume > _MaxLot){ orderVolume = _MaxLot; } orderVolume = NormalizeDouble(orderVolume, _LotDigits); } //+------------------------------------------------------------------+
You have to call function NormalizeDouble with first parameter - your volume, and second parameter - digits in lot, usually 2 or 1. This will make sure that your volume has only two decimal digits. Its similar to round, and must be mandatory used for all volumes and prices before OrderSend.
Also, make sure to do the same with your order price, stoploss, takeprofit:
Usually I use following code to make sure that volume is setup according to broker settings:
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I use following moneymanagement code for my Ea. it working in micro accounts. but in ECN accounts not working. please some one help me for edit it
thanks