당사 팬 페이지에 가입하십시오
- 조회수:
- 7958
- 평가:
- 게시됨:
- 2020.01.21 03:26
- 업데이트됨:
- 2021.10.24 23:13
-
이 코드를 기반으로 한 로봇이나 지표가 필요하신가요? 프리랜스로 주문하세요 프리랜스로 이동
CHistoryPositionInfo class provides an easy access to the closed position properties.
The class has a similar interface to CPositionInfo class of the standard library.
class CHistoryPositionInfo : public CObject { public: CHistoryPositionInfo(void); ~CHistoryPositionInfo(void); //--- methods of access to protected data ulong Ticket(void) const { return(m_curr_ticket); } //--- fast access methods to the integer position properties datetime TimeOpen(void); ulong TimeOpenMsc(void); datetime TimeClose(void); ulong TimeCloseMsc(void); ENUM_POSITION_TYPE PositionType(void); string TypeDescription(void); long Magic(void); long Identifier(void); ENUM_DEAL_REASON OpenReason(void); ENUM_DEAL_REASON CloseReason(void); //--- fast access methods to the double position properties double Volume(void); double PriceOpen(void); double StopLoss(void) const; double TakeProfit(void) const; double PriceClose(void); double Commission(void); double Swap(void); double Profit(void); //--- fast access methods to the string position properties string Symbol(void); string OpenComment(void); string CloseComment(void); string OpenReasonDescription(void); string CloseReasonDescription(void); string DealTickets(const string separator = " "); //--- info methods string FormatType(string &str,const uint type) const; string FormatReason(string &str,const uint reason) const; //--- methods for select position bool HistorySelect(datetime from_date,datetime to_date); int PositionsTotal(void) const; bool SelectByTicket(const ulong ticket); bool SelectByIndex(const int index); };
Here is a sample code showing how to use the class in your code
#include <CHistoryPositionInfo.mqh> //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void OnStart() { //--- variable to hold the history position info CHistoryPositionInfo hist_position; //--- Retrieve the history of closed positions for the specified period if(!hist_position.HistorySelect(0,TimeCurrent())) { Alert("CHistoryPositionInfo::HistorySelect() failed!"); return; } //--- now process the list of closed positions int total = hist_position.PositionsTotal(); for(int i = 0; i < total; i++) { //--- Select a closed position by its index in the list if(hist_position.SelectByIndex(i)) { ulong ticket = hist_position.Ticket(); datetime time_open = hist_position.TimeOpen(); ulong time_open_msc = hist_position.TimeOpenMsc(); datetime time_close = hist_position.TimeClose(); ulong time_close_msc = hist_position.TimeCloseMsc(); long type = hist_position.PositionType(); string type_desc = hist_position.TypeDescription(); long magic = hist_position.Magic(); long pos_id = hist_position.Identifier(); double volume = hist_position.Volume(); double price_open = hist_position.PriceOpen(); double price_sl = hist_position.StopLoss(); double price_tp = hist_position.TakeProfit(); double price_close = hist_position.PriceClose(); double commission = hist_position.Commission(); double swap = hist_position.Swap(); double profit = hist_position.Profit(); string symbol = hist_position.Symbol(); string open_comment = hist_position.OpenComment(); string close_comment = hist_position.CloseComment(); string open_reason_desc = hist_position.OpenReasonDescription(); string close_reason_desc = hist_position.CloseReasonDescription(); string deal_tickets = hist_position.DealTickets(","); //--- int deals_count = HistoryDealsTotal(); // of the selected position int orders_count = HistoryOrdersTotal(); // of the selected position } } //--- Print("Total closed positions = ",hist_position.PositionsTotal()); } //+------------------------------------------------------------------+
Note: when using the methods HistorySelect() and SelectByIndex(), the list of positions is ordered by time of closing (not by the opening times).
This means the history of closed positions (data rows) is ordered by Close Time to help calculate the running Balance, correctly.
![3D Spiral Quotes](https://c.mql5.com/i/code/indicator.png)
Demonstration of Canvas's capabilities using 3D spiral quotes as an example.
![Pseudo-Indicator with Asynchronous Multi-Threaded Calculations Demo](https://c.mql5.com/i/code/indicator.png)
This is an indicator w/o buffers which demonstrates parallel multi-threaded calculations in chart objects hosting worker expert adviser.
![3D Moving Average](https://c.mql5.com/i/code/indicator.png)
The first really 3D indicator "Moving Average".
![CSetFileReader](https://c.mql5.com/i/code/library.png)
Class to provide simple reading mechanism from MetaTrader set files.