How to fix the following problem?

 

I submit the local compiled code on MT4, and find the system prompt error. How can I solve it effectively?

Error Message

 
Xianba Xia:

I submit the local compiled code on MT4, and find the system prompt error. How can I solve it effectively?

Error 131 is Invalid Trade Valume.
So, how effective are you talking about? fix the code.

Error Codes - Appendixes - MQL4 Tutorial
Error Codes - Appendixes - MQL4 Tutorial
  • book.mql4.com
GetLastError() - the function that returns codes of error. Code constants of errors are determined in stderror.mqh file. To draw the text messages use the ErrorDescription() function described in the stdlib.mqh file. Error codes returned from a trade server or client...
 

Forum on trading, automated trading systems and testing trading strategies

double variable with wrong decimal cases

Pedro Taveira, 2018.01.12 18:23

Hi,

I'm runnng this code to increase the lotsize in steps:
   double lotsize = 0.01;
   double lotstep = 0.01;

   for(int i=0; i<10; i++)
      {
      lotsize += lotstep;
      Print("i: ", i, ", lotsize: ", lotsize);     
      }

What I get is this result:

2018.01.12 17:15:58.644 test decimal case USDCHFbo,H1: i: 9, lotsize: 0.11
2018.01.12 17:15:58.644 test decimal case USDCHFbo,H1: i: 8, lotsize: 0.09999999999999999
2018.01.12 17:15:58.644 test decimal case USDCHFbo,H1: i: 7, lotsize: 0.09
2018.01.12 17:15:58.644 test decimal case USDCHFbo,H1: i: 6, lotsize: 0.08
2018.01.12 17:15:58.644 test decimal case USDCHFbo,H1: i: 5, lotsize: 0.07000000000000001
2018.01.12 17:15:58.644 test decimal case USDCHFbo,H1: i: 4, lotsize: 0.06
2018.01.12 17:15:58.644 test decimal case USDCHFbo,H1: i: 3, lotsize: 0.05
2018.01.12 17:15:58.644 test decimal case USDCHFbo,H1: i: 2, lotsize: 0.04
2018.01.12 17:15:58.644 test decimal case USDCHFbo,H1: i: 1, lotsize: 0.03
2018.01.12 17:15:58.644 test decimal case USDCHFbo,H1: i: 0, lotsize: 0.02


Why is not the result of the calculation a value with 2 decimal cases?
I'm just adding two numbers with 2 decimal cases each.


Thanks.
Pedro

Forum on trading, automated trading systems and testing trading strategies

Need help in avoiding error 131

FARHANG, 2010.03.20 20:26

Hi, I need help in avoiding orderSend error 131 and orderClose error 131. Here is the value I assign to lot size:

Double lots=NormalizeDouble(MathAbs((AccountEquity()/10000)),2);

and Here is How I send an order:

OrderSend(Symb,OP_SELL,lots,Bid,2,Ask+600*Point,Ask-2000*Point);

I need to program my EA in such a way that it closes ALL opposite trades Whenever there is an opposite signal.
This here is what I came up with for closing all buy trades( there are no pending orders).
 for(i=1; i<=OrdersTotal(); i++)       
   {
   if(OrderSelect(i-1,SELECT_BY_POS)==true)
   Tip=OrderType();                
   if (Tip==0)
   {
   Ticket_Buy=OrderTicket();
   lot=OrderLots();
   Ans=OrderClose(Ticket_Buy,lot,Bid,2);
   }
  }
I defined the variables before I used them in the code above and I had no problem in compiling. But somehow the value of the variable "lot" is always 0 and I keep getting the 131 error.
I seriously don't know what I'm doing wrong. Please have in mind that I'm new to this so I might need you to spoon feed me. Thanks in advance for your help.

 
 for(i=1; i<=OrdersTotal(); i++)       
   {
   if(OrderSelect(i-1,SELECT_BY_POS)==true) Tip=OrderType();                
   if (Tip==0)
   {
   Ticket_Buy=OrderTicket();
   lot=OrderLots();
   Ans=OrderClose(Ticket_Buy,lot,Bid,2);
   }
  }
  1. If the OrderSelect fails you continue processing anyway.

  2. Using OrdersTotal directly and/or no Magic number filtering on your OrderSelect loop means your code is incompatible with every EA (including itself on other charts and manual trading.)
              Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 and MetaTrader 4 - MQL4 programming forum

  3. In the presence of multiple orders (one EA multiple charts, multiple EAs, manual trading,) while you are waiting for the current operation (closing, deleting, modifying) to complete, any number of other operations on other orders could have concurrently happened and changed the position indexing:
    1. For non-FIFO (US brokers,) (or the EA only opens one order per symbol,) you can simply count down in a position loop, and you won't miss orders. Get in the habit of always counting down.
                Loops and Closing or Deleting Orders - MQL4 and MetaTrader 4 - MQL4 programming forum
      For FIFO (US brokers,) and you (potentially) process multiple orders per symbol, you must count up and on a successful operation, reprocess all positions (set index to -1 before continuing.)
    2. and check OrderSelect in case earlier positions were deleted.
                What are Function return values ? How do I use them ? - MQL4 and MetaTrader 4 - MQL4 programming forum
                Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
    3. and if you (potentially) process multiple orders, must call RefreshRates() after server calls if you want to use the Predefined Variables (Bid/Ask) or OrderClosePrice() instead, on the next order/server call.