거래 로봇을 무료로 다운로드 하는 법을 시청해보세요
당사를 Facebook에서 찾아주십시오!
당사 팬 페이지에 가입하십시오
스크립트가 흥미로우신가요?
그렇다면 링크 to it -
하셔서 다른 이들이 평가할 수 있도록 해보세요
스크립트가 마음에 드시나요? MetaTrader 5 터미널에서 시도해보십시오
라이브러리

HistoryPositionInfo version 2 - MetaTrader 5용 라이브러리

조회수:
7924
평가:
(31)
게시됨:
2017.08.10 12:56
\MQL5\Include\HistorySelect_\
이 코드를 기반으로 한 로봇이나 지표가 필요하신가요? 프리랜스로 주문하세요 프리랜스로 이동

Version 1.0: HistoryPositionInfo.

New in version 2:

The GetProfitInPoints function is still available, but it is recommended to use the new GetProfit function:

   bool              GetProfit(double &profit_in_points,
                               double &commission,
                               double &swap,
                               double &profit_in_money);

The GetProfit function returns the following information about a position, in addition to the profit in points: commission, swap and profit in money.

The CHistoryPositionInfo class is designed for getting the profit of a position in points, commission, swap and profit in money based on the trading history.

Class Description 

The CHistoryPositionInfo class allows getting the profit of a position in points, commission, swap and profit in money based on the trading history. 

Declaration

class CHistoryPositionInfo : public CArrayObj

Header

#include <HistorySelect_\HistoryPositionInfo.mqh>

Class methods by groups

Initialization
InitInitialization using a position ID
Access to the calculation result  
GetProfitInPoints is an obsolete method. It is recommended to use GetProfitGetting the profit of a position in points
GetProfitGetting the profit of a position in points, commission, swap and profit in money
Setting parameters 
LogErrorsEnable/disable logging of errors
PrintDeals(const bool value) Enable/disable deal print mode
Printing deals 
PrintDeals(void)Printing the deals that formed the position

An example of using the CHistoryPositionInfo class: requesting a five-day trading history, forming an array of all found position identifiers, then printing the following information in a loop: the profit of a position in points, commission, swap and profit in money based on the trading history.

//+------------------------------------------------------------------+
//|                                      TestHistoryPositionInfo.mq5 |
//|                              Copyright © 2017, Vladimir Karputov |
//|                                           http://wmua.ru/slesar/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2017, Vladimir Karputov"
#property link      "http://wmua.ru/slesar/"
#property version   "2.000"
#property script_show_inputs
//---
input datetime from_date   = __DATE__-60*60*24*5;  // from date (current time - 5 days)
input datetime to_date     =__DATE__+60*60*24;     // to date (current time + 1 days)
input bool     log_errors  = true;                 // logging errors
input bool     print_deals = true;                 // print deals
#include <HistorySelect_\HistoryPositionInfo.mqh>
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   long arr_tickets[];
//--- request trade history 
   HistorySelect(from_date,to_date);
//---
   uint     total=HistoryDealsTotal();
   ulong    ticket=0;
   long     position_id=0;
//--- for all deals 
   for(uint i=0;i<total;i++)
     {
      //--- try to get deals ticket 
      if((ticket=HistoryDealGetTicket(i))>0)
        {
         //--- get deals properties 
         position_id=HistoryDealGetInteger(ticket,DEAL_POSITION_ID);

         int arr_size=ArraySize(arr_tickets);
         bool search=false;
         for(int ii=0;ii<arr_size;ii++)
           {
            if(arr_tickets[ii]==position_id)
              {
               search=true;
               continue;
              }
           }
         if(!search)
           {
            ArrayResize(arr_tickets,arr_size+1,100);
            arr_tickets[arr_size]=position_id;
           }
        }
     }
//---
   int arr_size=ArraySize(arr_tickets);
   for(int i=0;i<arr_size;i++)
     {
      Print("");
      Print("Search deals with POSITION_IDENTIFIER ",IntegerToString(arr_tickets[i]));

      CHistoryPositionInfo HistoryPositionInfo;
      //--- init position identifier
      HistoryPositionInfo.Init(arr_tickets[i]);
      //--- los errors
      HistoryPositionInfo.LogErrors(log_errors);
      //--- print deals
      HistoryPositionInfo.PrintDeals(print_deals);
      //---
      double profit_in_points=0.0;
      double commission=0.0;
      double swap=0.0;
      double profit=0.0;

      if(HistoryPositionInfo.GetProfit(profit_in_points,commission,swap,profit))
         Print("Profit in points ",DoubleToString(profit_in_points,1),
               ", commission ",DoubleToString(commission,2),
               ", swap ",DoubleToString(swap,2),
               ", profit ",DoubleToString(profit,2));
     }
  }
//+------------------------------------------------------------------+



MetaQuotes Ltd에서 러시아어로 번역함.
원본 코드: https://www.mql5.com/ru/code/18721

Get_Rich_or_Die_Trying_GBP Get_Rich_or_Die_Trying_GBP

Trades on PERIOD_M1 (M1). Calculates bullish and bearish candlesticks.

Trailing_Profit Trailing_Profit

Closing all open positions with the specified profit percent.

VWAP Custom Position VWAP Custom Position

Standard VWAP (Volume Weighted Average Price) calculation, but with configurable start position.

SaveTicks SaveTicks

This utility program records tick quotes in the CSV and BIN format. A flexible set of symbols is available for writing.