- Usually people who cannot code do not receive free help on this forum.
- If you show your attempts and describe your problem clearly, you will most probably receive an answer from the community. Use the CODE button (Alt-S) when inserting code.
- To learn MQL programming, you can research the many available Articles on the subject, or examples in the Codebase, as well as reference the online Documentation.
- If you do not want to learn to code, that is not a problem. You can either look at the Codebase if something free already exists, or in the Market for paid products (also sometimes free). However, recommendations or suggestions for Market products are not allowed on the forum, so you will have to do your own research.
- Finally, you also have the option to hire a programmer in the Freelance section.
I know how to code but in MQL4:
//+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int stoplossAchat= 0; int takeprofitAchat= 14000; int stoplossVente= 14000; int takeprofitVente= 0; double quantite= 1; int slippage= 3; int ticketAchat; int ticketVente; double cours; double position; double rsi; double rsiPasse; void OnTick() { if(1==1) { rsi=iRSI(NULL,0,14,PRICE_CLOSE,0); rsiPasse=iRSI(NULL,0,14,PRICE_CLOSE,1); if(rsi>30 && rsiPasse<30 && position==0) { ticketAchat= OrderSend(NULL,OP_BUY,quantite,Ask,slippage,stoplossAchat,takeprofitAchat,"commentaire",16384,0,Green); position=1; } if(rsi>50 && position==1) { OrderClose(ticketAchat, quantite, Bid, slippage, Green); position=0; } if(rsi<70 && rsiPasse>70 && position==0) { ticketVente= OrderSend(NULL,OP_SELL,quantite,Bid,slippage,stoplossVente,takeprofitVente,"commentaire",16384,0,Red); position=-1; } if(rsi<50 && position==-1) { OrderClose(ticketVente, quantite, Ask, slippage, Red); position=0; } } //return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ //+------------------------------------------------------------------+Can someone help me to translate the opening and closing positions in MQL5?
Here is some research material ...
Documentation:
- Documentation on MQL5: Trade Functions / OrderSend
- Documentation on MQL5: Standard Library / Trade Classes / CTrade / OrderOpen
- Documentation on MQL5: Standard Library / Trade Classes / CTrade / PositionOpen
- Documentation on MQL5: Standard Library / Trade Classes / CTrade / PositionClose
Articles:
- Migrating from MQL4 to MQL5
- Transferring Indicators from MQL4 to MQL5
- Cross-Platform Expert Advisor: Order Manager
- Orders, Positions and Deals in MetaTrader 5
CodeBase:
Blogs:
If however, you do not wish to do your research and learn on your own, then please refer to the Freelance section.
Trading applications for MetaTrader 5 to order
- 2023.09.13
- www.mql5.com
The largest freelance service with MQL5 application developers
yoannh: Can someone put here a very easy code in MQL5 to open and close a position. I tried this: PositionOpen, but it doesn't work.
You must use the CTrade Class if you want to use the PositionOpen function.
for example:
#include <Trade\Trade.mqh>
CTrade myTrade;
Thank you two both. I will try that.
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Can someone put here a very easy code in MQL5 to open and close a position.
I tried this: PositionOpen, but it doesn't work.