Trading Panel with auto lot size

 
I'm using a freely available source code that calucate risk percent and set auto lot sizing with a trading panel from [edited].com

However the project is not able to open any trades. I have made a test by inserting the open trade codes to it, it gives the error 4014.

I can able to use the same code in another project on the same trade without any issues.

Any ideas what is the issue?

   MqlTradeRequest request={};
   MqlTradeResult  result={};
//--- parameters of request
   request.action   =TRADE_ACTION_DEAL;                     // type of trade operation
   request.symbol   =Symbol();                              // symbol
   request.volume   =0.1;                                   // volume of 0.1 lot
   request.type     =ORDER_TYPE_BUY;                        // order type
   request.price    =SymbolInfoDouble(Symbol(),SYMBOL_ASK); // price for opening
   request.deviation=5;                                     // allowed deviation from the price
   //request.magic    =EXPERT_MAGIC;                          // MagicNumber of the order
//--- send the request
   if(!OrderSend(request,result))
      PrintFormat("OrderSend error %d",GetLastError());     // if unable to send the request, output the error code
//--- information about the operation
   PrintFormat("retcode=%u  deal=%I64u  order=%I64u",result.retcode,result.deal,result.order);
Projects assist in creating profitable trading robots! Or at least, so it seems
Projects assist in creating profitable trading robots! Or at least, so it seems
  • www.mql5.com
A big program starts with a small file, which then grows in size as you keep adding more functions and objects. Most robot developers utilize include files to handle this problem. However, there is a better solution: start developing any trading application in a project. There are so many reasons to do so.
 

Detailed info about errors https://www.mql5.com/ en/docs/constants/ errorswarnings/errorcodes

NOTE: Traders and coders are working for free:

  • if it is interesting for them personally, or
  • if it is interesting for many members on this forum.

Freelance section of the forum should be used in most of the cases.

Documentation on MQL5: Constants, Enumerations and Structures / Codes of Errors and Warnings / Runtime Errors
Documentation on MQL5: Constants, Enumerations and Structures / Codes of Errors and Warnings / Runtime Errors
  • www.mql5.com
GetLastError() is the function that returns the last error code that is stored in the predefined variable _LastError . This value can be reset to...
 
Zixu Li:
I'm using a freely available source code that calucate risk percent and set auto lot sizing with a trading panel from [edited].com

However the project is not able to open any trades. I have made a test by inserting the open trade codes to it, it gives the error 4014.

I can able to use the same code in another project on the same trade without any issues.

Any ideas what is the issue?

The code likely omits several MqlTradeRequest required fields ( Trade Request Structure - Data Structures - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5).

Documentation on MQL5: Constants, Enumerations and Structures / Data Structures / Trade Request Structure
Documentation on MQL5: Constants, Enumerations and Structures / Data Structures / Trade Request Structure
  • www.mql5.com
Interaction between the client terminal and a trade server for executing the order placing operation is performed by using trade requests. The...
 

The exact MqlTradeRequest code is working fine in other project, so the fields are not a problem

 
Zixu Li #:

The exact MqlTradeRequest code is working fine in other project, so the fields are not a problem

Error 4014 appears to be a web request error. Have a look at:

WebRequest MQL5: error 4014 even though I have maintained the Url in "tools / options" - Indices - General - MQL5 programming forum
WebRequest MQL5: error 4014 even though I have maintained the Url in "tools / options"
WebRequest MQL5: error 4014 even though I have maintained the Url in "tools / options"
  • 2022.03.18
  • KjLNi
  • www.mql5.com
Hello there, I am following the instructions for WebRequest in the documentation of MQL5...
 
Zixu Li: However the project is not able to open any trades. I have made a test by inserting the open trade codes to it, it gives the error 4014.

Are you perhaps trying to run your code in an Indicator or perhaps on an account that follows a signal?

ERR_FUNCTION_NOT_ALLOWED

4014

Function is not allowed for call

Documentation on MQL5: Constants, Enumerations and Structures / Codes of Errors and Warnings / Runtime Errors
Documentation on MQL5: Constants, Enumerations and Structures / Codes of Errors and Warnings / Runtime Errors
  • www.mql5.com
GetLastError() is the function that returns the last error code that is stored in the predefined variable _LastError . This value can be reset to...
 
@Ryan L Johnson #: Error 4014 appears to be a web request error.
Not quite. Error 4014 is "Function is not allowed for call".
 
Fernando Carreiro #:

Are you perhaps trying to run your code in an Indicator or perhaps on an account that follows a signal?

ERR_FUNCTION_NOT_ALLOWED

4014

Function is not allowed for call

I'm running the code on EA, I want to add open trades functions to the project (files attached in my first post). So I put in the open trade codes to test but it gives error, but the code is proven to work if I create a new EA project. The project is working perfectly fine with auto lot sizing and adjusting SL lines. I am not following any signals

 
webrequest is allowed in my terminal, the code works in my test EA. The webrequest checkbox is always on.
 
Zixu Li #: I'm running the code on EA, I want to add open trades functions to the project (files attached in my first post). So I put in the open trade codes to test but it gives error, but the code is proven to work if I create a new EA project. The project is working perfectly fine with auto lot sizing and adjusting SL lines. I am not following any signals
Please identify which lines give the error and show the log output.
 
Fernando Carreiro #:
Please identify which lines give the error and show the log output.


void OpenTrade() {
//--- declare and initialize the trade request and result of trade request
   MqlTradeRequest request={};
   MqlTradeResult  result={};
//--- parameters of request
   request.action   =TRADE_ACTION_DEAL;                     // type of trade operation
   request.symbol   =Symbol();                              // symbol
   request.volume   =0.1;                                   // volume of 0.1 lot
   request.type     =ORDER_TYPE_BUY;                        // order type
   request.price    =SymbolInfoDouble(Symbol(),SYMBOL_ASK); // price for opening
   request.deviation=5;                                     // allowed deviation from the price
   //request.magic    =EXPERT_MAGIC;                          // MagicNumber of the order
//--- send the request
   if(!OrderSend(request,result))
      PrintFormat("OrderSend error %d",GetLastError());     // if unable to send the request, output the error code
//--- information about the operation
   //PrintFormat("retcode=%u  deal=%I64u  order=%I64u",result.retcode,result.deal,result.order);
}

I got the error from this code.
   if(!OrderSend(request,result))
      PrintFormat("OrderSend error %d",GetLastError());     // if unable to send the request, output the error code

I call this function OnInit() . The system does not generate it's own error, no trade are opened.