ÿþ//+------------------------------------------------------------------+
//| Reconstruction of positions.mq5 |
//| Copyright © 2016, Vladimir Karputov |
//| http://wmua.ru/slesar/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2016, Vladimir Karputov"
#property link "http://wmua.ru/slesar/"
#property version "1.000"
#include <Arrays\ArrayObj.mqh>
#property description " 5:>=AB@C:F8O & 87 8AB>@88 A45;>:"
#property script_show_inputs
//---
input datetime start=D'2016.12.22 16:17:00';
//+------------------------------------------------------------------+
//| ;0AA - ?>78F8O - A>2>:C?=>ABL 2A5E A45;>: |
//| A >48=0:>2K< POSITION_ID |
//+------------------------------------------------------------------+
class CMyPosition : public CArrayObj
{
private:
long m_pos_id; // 845=B8D8:0B>@ ?>78F88, 2 >B:@KB88, 87<5=5=88 8;8 70:@KB88 :>B>@>9 CG0AB2>20;0 MB0 A45;:0
public:
// CMyPosition(void);
//~CMyPosition(void);
//--- <5B>4K 4>ABC?0 : 70I8IQ==K< 40==K<
void ID(const long value) { m_pos_id=value; }
long ID(void) const { return(m_pos_id); }
};
//+------------------------------------------------------------------+
//| ;0AA - A45;:0 |
//+------------------------------------------------------------------+
class CMyDeal : public CObject
{
private:
long m_deal_entry; // =0?@02;5=85 A45;:8 2E>4 2 @K=>:, 2KE>4 87 @K=:0 8;8 @072>@>B
long m_deal_type; // B8? A45;:8
double m_deal_price; // F5=0 A45;:8
double m_deal_volume; // >1JQ< A45;:8
long m_deal_id; // 845=B8D8:0B>@ ?>78F88, 2 >B:@KB88, 87<5=5=88 8;8 70:@KB88 :>B>@>9 CG0AB2>20;0 MB0 A45;:0
double m_deal_profit; // D8=0=A>2K9 @57C;LB0B A45;:8
public:
CMyDeal(void);
~CMyDeal(void);
//--- <5B>4K 4>ABC?0 : 70I8IQ==K< 40==K<
void Entry_deal(const long value) { m_deal_entry=value; }
long Entry_deal(void) const { return(m_deal_entry); }
void Type_deal(const long value) { m_deal_type=value; }
long Type_deal(void) const { return(m_deal_type); }
void Price_deal(const double value) { m_deal_price=value; }
double Price_deal(void) const { return(m_deal_price); }
void Volume_deal(const double value) { m_deal_volume=value; }
double Volume_deal(void) const { return(m_deal_volume); }
void ID_deal(const long value) { m_deal_id=value; }
long ID_deal(void) const { return(m_deal_id); }
void Profit_deal(const double value) { m_deal_profit=value; }
double Profit_deal(void) const { return(m_deal_profit); }
};
//+------------------------------------------------------------------+
//| Constructor |
//+------------------------------------------------------------------+
CMyDeal::CMyDeal(void) : m_deal_entry(0),
m_deal_type(0),
m_deal_price(0.0),
m_deal_volume(0.0),
m_deal_id(0),
m_deal_profit(0.0)
{
}
//+------------------------------------------------------------------+
//| Destructor |
//+------------------------------------------------------------------+
CMyDeal::~CMyDeal(void)
{
}
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
//---
if(AccountInfoInteger(ACCOUNT_MARGIN_MODE)!=ACCOUNT_MARGIN_MODE_RETAIL_HEDGING)
{
Print("This script can be started only on a hedge; -B>B A:@8?B <>6=> 70?CA:0BL B>;L:> =0 E546");
return;
}
Print_IDs();
}
//+------------------------------------------------------------------+
//| List all positions and deals |
//+------------------------------------------------------------------+
void Print_IDs(void)
{
CArrayObj arr_positions; // >1J:B 48=0<8G5A:>3> <0AA820 C:070B5;59
//--- 70?@0H8205< 8AB>@8N A45;>: 8 >@45@>2 70 C:070==K9 ?5@8>4 A5@25@=>3> 2@5<5=8
HistorySelect(start,TimeCurrent()+86400);
uint total =HistoryDealsTotal(); // :>;8G5AB2> A45;>: 2 8AB>@88
ulong ticket =0; // B8:5B A45;:8 2 8AB>@88
long magic =0;
long type =0; // B8? A45;:8
long deal_id =0; // 845=B8D8:0B>@ ?>78F88, 2 >B:@KB88, 87<5=5=88 8;8 70:@KB88 :>B>@>9 CG0AB2>20;0 MB0 A45;:0
double volume =0.0; // >1JQ< A45;:8
double profit =0.0; // D8=0=A>2K9 @57C;LB0B A45;:8
double price =0.0; // F5=0 A45;:8
string symbol =NULL; // 8<O A8<2>;0, ?> :>B>@><C ?@>872545=0 A45;:0
long entry =0; // =0?@02;5=85 A45;:8 2E>4 2 @K=>:, 2KE>4 87 @K=:0 8;8 @072>@>B
//--- for all deals
for(uint i=0;i<total;i++)
{
//--- try to get deals ticket
if((ticket=HistoryDealGetTicket(i))>0)
{
//--- get deals properties
magic =HistoryDealGetInteger(ticket,DEAL_MAGIC);
type =HistoryDealGetInteger(ticket,DEAL_TYPE);
deal_id =HistoryDealGetInteger(ticket,DEAL_POSITION_ID);
volume =HistoryDealGetDouble(ticket,DEAL_VOLUME);
profit =HistoryDealGetDouble(ticket,DEAL_PROFIT);
price =HistoryDealGetDouble(ticket,DEAL_PRICE);
symbol =HistoryDealGetString(ticket,DEAL_SYMBOL);
entry =HistoryDealGetInteger(ticket,DEAL_ENTRY);
if(symbol==Symbol() /*&& magic==m_magic*/)
{
bool find=false;
for(int j=0;j<arr_positions.Total();j++)
{
//--- >1JO28< C:070B5;L =0 >1J5:B :;0AA0 CMyPosition 8 ?@8A2>8< 5<C M;5<5=B 87 C:070==>9 ?>78F88 <0AA820
CMyPosition *my_position=arr_positions.At(j);
if(my_position==NULL)
{
//--- >H81:0 GB5=8O 87 <0AA820
Print("Get element error (\"arr_positions\")");
return;
}
if(my_position.ID()==deal_id)
{
find=true;
//--- >1JO28< C:070B5;L =0 >1J5:B :;0AA0 CMyDeal 8 ?@8A2>8< 5<C 2=>2L A>740==K9 >1J5:B :;0AA0 CMyDeal
CMyDeal *my_deal=new CMyDeal;
if(my_deal==NULL)
{
//--- >H81:0 A>740=8O
Print("Object create error (\"my_deal\")");
return;
}
my_deal.Entry_deal(entry);
my_deal.Type_deal(type);
my_deal.Price_deal(price);
my_deal.Volume_deal(volume);
my_deal.ID_deal(deal_id);
my_deal.Profit_deal(profit);
my_position.Add(my_deal);
}
}
if(!find)
{
//--- >1JO28< C:070B5;L =0 >1J5:B :;0AA0 CMyPosition 8 ?@8A2>8< 5<C 2=>2L A>740==K9 >1J5:B :;0AA0 CMyPosition
CMyPosition *my_position=new CMyPosition;
if(my_position==NULL)
{
//--- >H81:0 A>740=8O
Print("Object create error (\"arr_positions\")");
return;
}
my_position.ID(deal_id);
//--- >1JO28< C:070B5;L =0 >1J5:B :;0AA0 CMyDeal 8 ?@8A2>8< 5<C 2=>2L A>740==K9 >1J5:B :;0AA0 CMyDeal
CMyDeal *my_deal=new CMyDeal;
if(my_deal==NULL)
{
//--- >H81:0 A>740=8O
Print("Object create error (\"my_deal\")");
return;
}
my_deal.Entry_deal(entry);
my_deal.Type_deal(type);
my_deal.Price_deal(price);
my_deal.Volume_deal(volume);
my_deal.ID_deal(deal_id);
my_deal.Profit_deal(profit);
my_position.Add(my_deal);
arr_positions.Add(my_position);
}
}
}
}
for(int k=0;k<arr_positions.Total();k++)
{
//--- >1JO28< C:070B5;L =0 >1J5:B :;0AA0 CMyPosition 8 ?@8A2>8< 5<C M;5<5=B 87 C:070==>9 ?>78F88 <0AA820
CMyPosition *my_position=arr_positions.At(k);
if(my_position==NULL)
{
//--- >H81:0 GB5=8O 87 <0AA820
Print("Get element error (\"arr_positions\")");
return;
}
Print("position #",k);
for(int m=0;m<my_position.Total();m++)
{
//--- >1JO28< C:070B5;L =0 >1J5:B :;0AA0 CMyDeal 8 ?@8A2>8< 5<C M;5<5=B 87 C:070==>9 ?>78F88 <0AA820
CMyDeal *my_deal=my_position.At(m);
if(my_deal==NULL)
{
//--- >H81:0 GB5=8O 87 <0AA820
Print("Get element error (\"my_deal\")");
return;
}
Print(EnumToString((ENUM_DEAL_ENTRY)my_deal.Entry_deal()),
", type ",EnumToString((ENUM_DEAL_TYPE)my_deal.Type_deal()),
", price ",DoubleToString(my_deal.Price_deal(),Digits()),
", Deal ",Symbol(),
", volume ",DoubleToString(my_deal.Volume_deal(),2),
", DEAL_POSITION_ID #",my_deal.ID_deal(),
", profit ",DoubleToString(my_deal.Profit_deal(),2));
}
}
Print("");
}
//+------------------------------------------------------------------+
Comments