Rejoignez notre page de fans
- Vues:
- 8197
- Note:
- Publié:
- 2017.08.10 12:56
-
Besoin d'un robot ou d'un indicateur basé sur ce code ? Commandez-le sur Freelance Aller sur Freelance
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
Header
Class methods by groups
Initialization | |
---|---|
Init | Initialization using a position ID |
Access to the calculation result | |
GetProfitInPoints is an obsolete method. It is recommended to use GetProfit | Getting the profit of a position in points |
GetProfit | Getting the profit of a position in points, commission, swap and profit in money |
Setting parameters | |
LogErrors | Enable/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)); } } //+------------------------------------------------------------------+
Traduit du russe par MetaQuotes Ltd.
Code original : https://www.mql5.com/ru/code/18721
![Get_Rich_or_Die_Trying_GBP](https://c.mql5.com/i/code/expert.png)
Trades on PERIOD_M1 (M1). Calculates bullish and bearish candlesticks.
![Trailing_Profit](https://c.mql5.com/i/code/expert.png)
Closing all open positions with the specified profit percent.
![VWAP Custom Position](https://c.mql5.com/i/code/indicator.png)
Standard VWAP (Volume Weighted Average Price) calculation, but with configurable start position.
![SaveTicks](https://c.mql5.com/i/code/expert.png)
This utility program records tick quotes in the CSV and BIN format. A flexible set of symbols is available for writing.