Ticaret robotlarını ücretsiz olarak nasıl indirebileceğinizi izleyin
Bizi Twitter üzerinde bulun!
Fan sayfamıza katılın
Komut dosyasını ilginç mi buldunuz?
Öyleyse bir link gönderin -
başkalarının da faydalanmasını sağlayın
Komut dosyasını beğendiniz mi? MetaTrader 5 terminalinde deneyin
Kütüphaneler

HistoryPositionInfo version 2 - MetaTrader 5 için kütüphane

Görüntülemeler:
7989
Derecelendirme:
(31)
Yayınlandı:
2017.08.10 12:56
\MQL5\Include\HistorySelect_\
Bu koda dayalı bir robota veya göstergeye mi ihtiyacınız var? Freelance üzerinden sipariş edin Freelance'e git

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 tarafından Rusçadan çevrilmiştir.
Orijinal kod: 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.