if you buy 10 lot EURUSD at 1.27443 with leverage 1:100 then your account isn't enough:
margin required = 10 x 100.000 x 1.27443 /100 = 12744.3 > 10000
Dear All,
ACCOUNT BALANCE:10000. 00 USD
Tried to place an oder through EA.
CTrade::OrderSend: instant buy 10.00 EURUSD at 1.27443 tp: 1.28443 [not enough money]
Got an error:not enough money
why? please advise.
hi.
Chech your trade volum.
use this code:
double CheckLots (int risk_percent,double Stoplost_point, double Static_Lot) {
double Margin_Required=MarketInfo(Symbol(), MODE_MARGINREQUIRED);
double lotmin=MarketInfo(Symbol(), MODE_MINLOT);
double lotmax=MarketInfo(Symbol(), MODE_MAXLOT);
if (risk_percent<=0) return (Static_Lot);
double lots=0;
lots=NormalizeDouble( (AccountBalance()*Risk_Percentage/100) / (Tick_Value*sl_size), 2 );
if (lots*Margin_Required>AccountFreeMargin()) {
error("Not enough money to take " + DoubleToStr(lots,2) +" lots.");
lots=AccountFreeMargin()/Margin_Required;
}
lots=MathFloor(lots/Lot_Step + 0.5)* Lot_Step;
if ( lots < lotmin ) lots=lotmin;
if ( lots > lotmax ) lots=lotmax;
if ( lots > MaxLot) lots = MaxLot;
return(lots);
}
This is the MQL5 forum, so your MQQL4 code won't help, unfortunately.
For MQL5 some helpful methods can be found in AccountInfo.mqh: Look for MaxLotCheck(..)
// calculate for lot size based on the account balance and risk per trade double CalculateLotSize(ENUM_ORDER_TYPE type, double ask) { // e.g. £10 = £1000 * 1% double maxRiskAmount = AccountInfoDouble(ACCOUNT_BALANCE) * inputRiskPerTrade / 100; // e.g. 20 pence = £10 / 50 double riskPerPip = maxRiskAmount / (inputStopLoss / 10); double pipValue = 10 * SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_VALUE); double lotSize = riskPerPip / pipValue; double minLotSize = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_MIN); double maxLotSize = (AccountInfoDouble(ACCOUNT_BALANCE) * AccountInfoInteger(ACCOUNT_LEVERAGE)) / SymbolInfoDouble(_Symbol, SYMBOL_TRADE_CONTRACT_SIZE); if ( lotSize < minLotSize ) lotSize = minLotSize; if ( lotSize > maxLotSize ) lotSize = maxLotSize; double freeMargin = AccountInfoDouble(ACCOUNT_MARGIN_FREE); double margin = 0.0; if(!OrderCalcMargin(type, _Symbol, lotSize, ask, margin)) { Print("Margin Calculation Error"); return NormalizeDouble(minLotSize, 2); } if(freeMargin - margin <= 0.0) { double mLot = (margin * AccountInfoInteger(ACCOUNT_LEVERAGE)) / SymbolInfoDouble(_Symbol, SYMBOL_TRADE_CONTRACT_SIZE); lotSize = lotSize - (mLot - lotSize); } return NormalizeDouble(lotSize, 2); }

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Dear All,
ACCOUNT BALANCE:10000. 00 USD
Tried to place an oder through EA.
CTrade::OrderSend: instant buy 10.00 EURUSD at 1.27443 tp: 1.28443 [not enough money]
Got an error:not enough money
why? please advise.