open/close orders, from MT4 to MT5

 

I have written an expert advisor in MT4 and I want to convert it to MT5. Everything seems to work except I can't open or close any orders. I used the function from the MT5 reference library:

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
input double Lots=...;




//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+

void OnTick()
  {
   MqlTradeRequest request;
   MqlTradeResult  result;
      request.action=TRADE_ACTION_DEAL; 
      request.symbol   =Symbol();                             
      request.volume   =Lots; 
      request.deviation=100;   
...
        request.order=order_id; 
      request.price    =SymbolInfoDouble(Symbol(),SYMBOL_BID);
      request.type     =ORDER_TYPE_SELL;  
OrderSend(request,result);
...
}


Thanks, I updated the message with the full code. The only thing missing is a few if statements and other variables declarations, but they should be fine. I just wanted to check if my open order code is not completely wrong or something. MT5 is a lot harder than MT4. I wasn't sure where to put the lines but I put them into the top of the Tick function for general things, then for whether it's a sell or buy, I put it before each sell and buy to change it, then send the order. Please let me know which part is wrong.

The Fundamentals of Testing in MetaTrader 5
The Fundamentals of Testing in MetaTrader 5
  • www.mql5.com
What are the differences between the three modes of testing in MetaTrader 5, and what should be particularly looked for? How does the testing of an EA, trading simultaneously on multiple instruments, take place? When and how are the indicator values calculated during testing, and how are the events handled? How to synchronize the bars from different instruments during testing in an "open prices only" mode? This article aims to provide answers to these and many other questions.
 
M N:

I have written an expert advisor in MT4 and I want to convert it to MT5. Everything seems to work except I can't open or close any orders. I used the function from the MT5 reference library:


        "MqlTradeRequest request;

        MqlTradeResult  result;

request.action=TRADE_ACTION_DEAL; 

      request.symbol   =Symbol();                              

      request.volume   =Lots; 

      request.price    =SymbolInfoDouble(Symbol(),SYMBOL_BID);

      request.deviation=100;

request.type =ORDER_TYPE_SELL;

OrderSend(request,result);"


"Lots" is the only parameter I use which is the volume. The code does nothing in the strategy tester though. I doubt that Lots is the error, but I am not sure how to check for errors either.

Do you know a super simple way to write the open order code please? I don't want to write 100 lines of code when in MT4 it was 1 line. I am looking for the simplest way. I don't have many parameters.


Thanks

Please post your code properly, so I can read it. Use the code button to insert code. Edit your original post, don't repost.
 
//+------------------------------------------------------------------+
//|                                                       testtt.mq5 |
//|                                                  Copyright 2022, |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2022,"
#property link      "https://www.mql5.com"
#property version   "1.00"


#include <Trade\Trade.mqh>               
CTrade   m_trade;
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
  
   m_trade.Buy()           //Enter the arguments
   m_trade.Sell()          //Enter the arguments
   m_trade.PositionClose() //Enter the arguments
  
  
  }
//+------------------------------------------------------------------+