double tickSize = MarketInfo(_Symbol,MODE_TICKVALUE); // 1.0 lotSize = (margin / StopLoss) / tickSize; // 200 / 50 = 4 4 / 1.0 = 4
Do not use tick value by itselfelse if(MarketInfo(_Symbol,MODE_LOTSTEP) == 0.1) lotSize = NormalizeDouble(lotSize,1); else NormalizeDouble(lotSize,2);
Assumes step is a multiple of 10- You place the stop where it needs to be - where the reason for the trade is no longer valid. E.g. trading a support bounce the stop goes below the support.
- Account Balance * percent/100 = RISK = OrderLots * (|OrderOpenPrice - OrderStopLoss| * DeltaPerLot + CommissionPerLot) (Note OOP-OSL includes the SPREAD, and DeltaPerLot is usually around $10/pip but it takes account of the exchange rates of the pair vs. your account currency.)
- Do NOT use TickValue by itself - DeltaPerLot
- You must normalize lots
properly and check against min and max.
- You must also check FreeMargin to avoid stop out
gBuyTicket = OrderSend(_Symbol,OP_BUYSTOP,lotSize,pendingBuyPrice,Slippage,stopLoss,takeProfit,"BuyOrder",MagicNumber,0,clrBlue); gSellTicket = OrderSend(_Symbol,OP_SELLSTOP,lotSize,pendingSellPrice,Slippage,stopLoss,takeProfit,"SellOrder",MagicNumber,0,clrRed);
Check your return codes. What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
- Do not use tick value by itself
- Assumes step is a multiple of 10
- You place the stop where it needs to be - where the reason for the trade is no longer valid. E.g. trading a support bounce the stop goes below the support.
- Account Balance * percent/100 = RISK = OrderLots * (|OrderOpenPrice - OrderStopLoss| * DeltaPerLot + CommissionPerLot) (Note OOP-OSL includes the SPREAD, and DeltaPerLot is usually around $10/pip but it takes account of the exchange rates of the pair vs. your account currency.)
- Do NOT use TickValue by itself - DeltaPerLot
- You must normalize lots
properly and check against min and max.
- You must also check FreeMargin to avoid stop out
- Check your return codes. What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
Yes, but my problem is in seeing the return values. Because its the automatic validation that returns error. When I test on my broker it works okay.
So is there any way of finding out the return values of whatever broker or software the automatic validation uses?
Stephen Reynolds: When I test on my broker it works okay. |
|
<< moved >>
Forum on trading, automated trading systems and testing trading strategies
OrderSend error 131
Stephen Reynolds, 2017.03.29 21:38
Why am I getting an order send 131 error on the following code :
#property strict // Input variables input int MagicNumber = 101; input int Slippage = 10; input double LotSize = 1.0; input int StopLoss = 500; input int TakeProfit = 500; // Global variables int gBuyTicket; // OnTick() event handler void OnTick() { // Our bar count for our condition int hour = Hour(); int timehour = 9; // Our order condition if(hour == timehour && gBuyTicket == 0) { // Open buy order gBuyTicket = OrderSend(_Symbol,OP_BUY,LotSize,Ask,Slippage,0,0,"Buy order",MagicNumber,0,clrGreen); // Add stop loss & take profit to Buy order if(gBuyTicket > 0 && (StopLoss > 0 || TakeProfit > 0)) { bool select = OrderSelect(gBuyTicket,SELECT_BY_TICKET); // Calculate stop loss & take profit double stopLoss = 0, takeProfit = 0; if(StopLoss > 0) stopLoss = OrderOpenPrice() - (StopLoss * _Point); if(TakeProfit > 0) takeProfit = OrderOpenPrice() + (TakeProfit * _Point); // Verify stop loss & take profit double stopLevel = MarketInfo(_Symbol,MODE_STOPLEVEL) * _Point; RefreshRates(); double upperStopLevel = Ask + stopLevel; double lowerStopLevel = Bid - stopLevel; if(takeProfit <= upperStopLevel && takeProfit != 0) takeProfit = upperStopLevel + _Point; if(stopLoss >= lowerStopLevel && stopLoss != 0) stopLoss = lowerStopLevel - _Point; // Modify order bool modify = OrderModify(gBuyTicket,0,stopLoss,takeProfit,0); } } // Reset tickets if(OrdersTotal() == 0 && hour == 23) { gBuyTicket = 0; } }
double GetLots(int orderType) { double lot = 0, firstLot = 0,multiplier = Multiplier_, MinLot = MarketInfo(Symbol(),MODE_MINLOT), MaxLot = MarketInfo(Symbol(),MODE_MAXLOT), lotStep = MarketInfo(Symbol(),MODE_LOTSTEP); int lotDigit = 1; if(lotStep == 0.01) lotDigit = 2; if(lotStep == 0.001) lotDigit = 3; if(TotalOrder(orderType)+1 >= 1) multiplier = LotExponent; for(int i = 0; i < OrdersTotal(); i++) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) { if(OrderSymbol() == Symbol() && OrderMagicNumber() == MagicID) { if(OrderType() == orderType) lot = MathMax(lot,OrderLots()); } } } if(lot == 0) { if(risk==0 || !AutoMM)lot = LOTS; else lot = AccountFreeMargin()*risk/10000; } else { if( AutoMM && multiplier > 0){lot *= multiplier;lot += (0.004);} else { if(risk==0 || !AutoMM)lot = LOTS; else lot = AccountFreeMargin()*risk/10000; } } lot = NormalizeDouble(lot,lotDigit); if(lot < MinLot) lot = MinLot; if(lot > MaxLot) lot = MaxLot; if(lot > 0.05) lot = 0.05; return(lot); }
When backtesting ea works without errors, when uploading to mql5 market it resturns error ordersend error 131 Here is the lot code
When backtesting ea works without errors, when uploading to mql5 market it resturns error ordersend error 131 Here is the lot code
Hi,
I have the same problem. The EA validation process shows "Ordersend Error 131" but when I test it in the strategytester of MT4 there occurs no error. Its very difficult to spot the problem. Especially because I checked already the lot size (min, max, and step).
- 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, ive tested the my EA on my current broker Vipromarkets and it test okay with no errors. But, when I send it in for automatic validation I get ordersend error 131 and a zero divide error. After looking into the problem this type of error is associated with lot volume.
The part of code from my EA is as follows :
I cant see the problem?