You implement method chaining to a newly created object
CPosition* CPosition::operator[](const int indexPar) { if(CheckPointer(this.mObject) == POINTER_INVALID)this.mObject = new CPosition(this.GroupSymbol,this.GroupMagicNumber,this.Group); long ticketTemp = this.SelectByIndex(indexPar); return this.mObject; }
The above allows code like this
//-- Modify the position using quick access feature position[0].Modify(50,50,SLTP_PIPS);
But I suggest that you better re-use the existing object and return a pointer to self.
CPosition* CPosition::operator[](const int indexPar) { long ticketTemp = this.SelectByIndex(indexPar); return GetPointer(this); }
You implement method chaining to a newly created object
The above allows code like this
But I suggest that you better re-use the existing object and return a pointer to self.
You have right. I'll make an update.
If you have any other robust solutions and implementations please feel free to share.
Also, if you want to be a contributor on GitHub just let me know.
The MQL_Easy belongs to everyone who find it useful.
Thank you.
Result (MQL_Easy_Example):
2019.04.05 23:40:47.976 script MQL_Easy_Example (EURUSD,M1) loaded successfully 2019.04.05 23:40:48.036 '35286172': market buy 0.10 EURUSD sl: 1.11967 tp: 1.12367 2019.04.05 23:40:48.076 '35286172': accepted market buy 0.10 EURUSD sl: 1.11967 tp: 1.12367 2019.04.05 23:40:48.086 '35286172': market buy 0.10 EURUSD sl: 1.11967 tp: 1.12367 placed for execution 2019.04.05 23:40:48.184 '35286172': order #2215014790 buy 0.10 / 0.10 EURUSD at market done in 147.219 ms 2019.04.05 23:40:48.184 '35286172': deal #2212236172 buy 0.10 EURUSD at 1.12167 done (based on order #2215014790) 2019.04.05 23:40:50.218 '35286172': modify #2215014790 buy 0.10 EURUSD sl: 1.11967, tp: 1.12367 -> sl: 1.11667, tp: 1.12667 2019.04.05 23:40:50.255 '35286172': accepted modify #2215014790 buy 0.10 EURUSD sl: 1.11967, tp: 1.12367 -> sl: 1.11667, tp: 1.12667 2019.04.05 23:40:50.265 '35286172': modify #2215014790 buy 0.10 EURUSD -> sl: 1.11667, tp: 1.12667 done in 47.225 ms 2019.04.05 23:40:52.305 '35286172': modify #2215014790 buy 0.10 EURUSD sl: 1.11667, tp: 1.12667 -> sl: 1.11867, tp: 1.12467 2019.04.05 23:40:52.335 '35286172': accepted modify #2215014790 buy 0.10 EURUSD sl: 1.11667, tp: 1.12667 -> sl: 1.11867, tp: 1.12467 2019.04.05 23:40:52.345 '35286172': modify #2215014790 buy 0.10 EURUSD -> sl: 1.11867, tp: 1.12467 done in 41.673 ms 2019.04.05 23:40:54.376 '35286172': market sell 0.10 EURUSD, close #2215014790 buy 0.10 EURUSD 1.12167 2019.04.05 23:40:54.406 '35286172': accepted market sell 0.10 EURUSD, close #2215014790 buy 0.10 EURUSD 1.12167 2019.04.05 23:40:54.406 '35286172': market sell 0.10 EURUSD, close #2215014790 buy 0.10 EURUSD 1.12167 placed for execution 2019.04.05 23:40:54.516 '35286172': order #2215014791 sell 0.10 / 0.10 EURUSD at market done in 146.877 ms 2019.04.05 23:40:54.516 script MQL_Easy_Example (EURUSD,M1) removed 2019.04.05 23:40:54.516 '35286172': deal #2212236173 sell 0.10 EURUSD at 1.12162 done (based on order #2215014791)
2019.04.05 23:40:48.184 MQL_Easy_Example (EURUSD,M1) --------------- ERROR --------------- 2019.04.05 23:40:48.184 MQL_Easy_Example (EURUSD,M1) Message : The index of selection can NOT be greater or equal than the total positions. 2019.04.05 23:40:48.184 MQL_Easy_Example (EURUSD,M1) indexPar = 0 -- Total Positions = 0 2019.04.05 23:40:48.184 MQL_Easy_Example (EURUSD,M1) Function : CPosition::SelectByIndex 2019.04.05 23:40:48.184 MQL_Easy_Example (EURUSD,M1) --------------- ERROR --------------- 2019.04.05 23:40:48.184 MQL_Easy_Example (EURUSD,M1) #Ticket: -1, OpenPrice: -1.0
I would like to know what type of account you use (hedging or netting).
I will check it deeply when the markets is open.
Hedge-demo-account from ForexTimeFXTM-Demo01.
Hedge-demo-account from ForexTimeFXTM-Demo01.
Hi,
I couldn't replicate the issue with metatrader MT5 terminal except from the FXTM terminal.
The issue occurs because of the lack of execution trade of FXTM demo server. If you copy paste the delay function between the code which execute the trade and the selection of position, it resolves the issue.
//-- Create a trade Position BUY ENUM_TYPE_POSITION type = TYPE_POSITION_BUY; double volume = 0.10; double stopLoss = 20; double takeProfit = 20; execute.Position(type,volume,stopLoss,takeProfit,SLTP_PIPS); //-- delay for visual purposes and slow brokers Sleep(2000); //-- Collect Information about the trade if(position.SelectByIndex(0)){ long ticket = position.GetTicket(); double openPrice = position.GetPriceOpen(); Print("#Ticket: "+(string)ticket+", OpenPrice: "+(string)openPrice); }
I will update the script example and i will insert another small delay in order to deal with the slow execution of brokers.
Thank you!
Hi,
I couldn't replicate the issue with metatrader MT5 terminal except from the FXTM terminal.
The issue occurs because of the lack of execution trade of FXTM demo server. If you copy paste the delay function between the code which execute the trade and the selection of position, it resolves the issue.
I will update the script example and i will insert another small delay in order to deal with the slow execution of brokers.
Thank you!
Unfortunately, then your library is of little use, since it is impossible to write a trading code equally on both platforms.
Try using your library to write this trade MT4-logic for MT5.
Форум по трейдингу, автоматическим торговым системам и тестированию торговых стратегий
Особенности языка mql5, тонкости и приёмы работы
fxsaber, 2018.02.15 11:48
void OnStart() { OrderCloseBy(OrderSend(_Symbol, OP_BUY, 1, Ask, 0, 0, 0), OrderSend(_Symbol, OP_SELL, 1, Bid, 0, 0, 0)); }
Unfortunately, then your library is of little use, since it is impossible to write a trading code equally on both platforms.
Try using your library to write this trade MT4-logic for MT5.
Hi,
As i show you, there is a delay on FXTM demo broker which produce the issue above. It is not the library fault. That issue can occur with pure MQL language.
The script example works on both platforms. So it is possible.
The MQL_Easy's goal is not only for cross platform compatibility but to encapsulate the complexity and make it easy to create MQL applications.
Of course the MT5 has more features than MT4 and in the future it will have even more. This is why it is designed in such a way that
you can scale the MT5 part without the MT4.
If you have a specific code or example that you think it will suits better, just let me know.
Thank you.
As i show you, there is a delay on FXTM demo broker which produce the issue above. It is not the library fault. That issue can occur with pure MQL language.
Here I immediately found two topics on this issue.
If you have a specific code or example that you think it will suits better, just let me know.
Форум по трейдингу, автоматическим торговым системам и тестированию торговых стратегий
Меньше кода, больше прока.. пишем советник
fxsaber, 2019.03.12 20:50
#include <MT4Orders.mqh> #define Bid SymbolInfoDouble(_Symbol, SYMBOL_BID) #define Ask SymbolInfoDouble(_Symbol, SYMBOL_ASK) void OnStart() { OrderCloseBy(OrderSend(_Symbol, OP_BUY, 1, Ask, 0, 0, 0), OrderSend(_Symbol, OP_SELL, 1, Bid, 0, 0, 0)); }

- 2018.08.08
- www.mql5.com
Hi,
I will create a solution for slow brokers based on the links you show.
Thank you.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
MQL_Easy:
A cross platform library/framework
Author: Dionisis Nikolopoulos