Just read the doc about HistoryOrdersTotal(): " Prior to calling HistoryOrdersTotal(), first it is necessary to receive the history of deals and orders using the HistorySelect() or HistorySelectByPosition() function."
If you follow the link of HistorySeletc() you'll find an example which you can amend according to your priorities..
Hi people!
Since build 1525, Metatrader 5 allows listing positions history.
What are the functions related to retrieving them, as there is HistoryOrdersTotal(), HistoryDealsTotal(), but there is no HistoryPositionsTotal(), HistoryPositionGetTicket(), and HistorySelect() generates a list of orders and trades. I just want a history of positions.
Is there a function for it?
Many thanks!
Just read the doc about HistoryOrdersTotal(): " Prior to calling HistoryOrdersTotal(), first it is necessary to receive the history of deals and orders using the HistorySelect() or HistorySelectByPosition() function."
If you follow the link of HistorySeletc() you'll find an example which you can amend according to your priorities..
HistorySelectByPosition does not retrieve Positions, only retrieves Orders or Deals.
How can I retrieve a list of all Closed POSITIONS?
HistorySelectByPosition does not retrieve Positions, only retrieves Orders or Deals.
How can I retrieve a list of all Closed POSITIONS?
A history positionInfo library, with methods similar to those in OrderInfo in std library.
I assume you understand some basic OOP of MQL at least.
Hi people!
Since build 1525, Metatrader 5 allows listing positions history.
What are the functions related to retrieving them, as there is HistoryOrdersTotal(), HistoryDealsTotal(), but there is no HistoryPositionsTotal(), HistoryPositionGetTicket(), and HistorySelect() generates a list of orders and trades. I just want a history of positions.
Is there a function for it?
Many thanks!
Please refer to
https://www.mql5.com/en/code/27683
see also
- www.mql5.com
Please refer to
https://www.mql5.com/en/code/27683
see also
https://www.mql5.com/en/code/21434
your answer is professional and explicative bliss, great!
Please @amrali, though a rudimentary question, i would like to ask if you could help me with a scirpt that helps me get the ticket of a trade i just took
e.g what i have tried
Ctrade trade; //////////other parts of the code // Function to get the ticket of the last trade ulong GetLastTradeTicket(string symbol) { int totalDeals = HistoryDealsTotal(); for (int i = totalDeals - 1; i >= 0; i--) { ulong dealTicket = HistoryDealGetTicket(i); string dealSymbol = HistoryDealGetString(i, DEAL_SYMBOL); if (dealTicket > 0 && StringCompare(dealSymbol, symbol) == 0) { // Found the last trade for the specified symbol return dealTicket; } } // No trade found for the specified symbol return 0; } trade.Sell(1, Symbol(), 0, NULL , NULL, 'sell trade'); // Get the ticket of the last trade ulong lastTradeTicket = GetLastTradeTicket(_Symbol); if (lastTradeTicket > 0) { Print("Ticket of the last trade: ", lastTradeTicket); } else { Print("No trades in history."); }
this always outputs 0, let me know whatever additional information you need
Please @amrali, though a rudimentary question, i would like to ask if you could help me with a scirpt that helps me get the ticket of a trade i just took
e.g what i have tried
this always outputs 0, let me know whatever additional information you need
I want to go with your word "... ticket of a trade i just took ". This means that the trade is still running.
if the trade is still running below code might help
double GetLastDetails(ENUM_POSITION_TYPE positionType, int type = 0){ double price = 0; for(int i = PositionsTotal()-1; i >= 0; i--) { ulong ticket = PositionGetTicket(i); PositionSelectByTicket(ticket); if(PositionGetInteger(POSITION_MAGIC) != MagicNumber || PositionGetInteger(POSITION_TYPE) != positionType || PositionGetString(POSITION_SYMBOL) != Symbol()) continue; if(PositionGetInteger(POSITION_TYPE) == positionType && PositionGetInteger(POSITION_MAGIC) == MagicNumber) { switch(type) { case 0: price = PositionGetDouble(POSITION_VOLUME); break; case 1: price = PositionGetDouble(POSITION_PRICE_OPEN); break; case 2: price = PositionGetDouble(POSITION_TP); break; case 3: price = PositionGetDouble(POSITION_SL); break; case 4: price = (double)PositionGetInteger(POSITION_TICKET); break; default: break; } break; } } return price; }
This code can be used to get last volume(i.e. lotsize), last open price, last takeprofit, last stoploss, and then last ticket.
Try it and let me know if it work
I want to go with your word "... ticket of a trade i just took ". This means that the trade is still running.
if the trade is still running below code might help
This code can be used to get last volume(i.e. lotsize), last open price, last takeprofit, last stoploss, and then last ticket.
Try it and let me know if it work
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi people!
Since build 1525, Metatrader 5 allows listing positions history.
What are the functions related to retrieving them, as there is HistoryOrdersTotal(), HistoryDealsTotal(), but there is no HistoryPositionsTotal(), HistoryPositionGetTicket(), and HistorySelect() generates a list of orders and trades. I just want a history of positions.
Is there a function for it?
Many thanks!