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
//+------------------------------------------------------------------+ //| 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 } //+------------------------------------------------------------------+
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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:
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.