UTE/Strategy/TradeEnvironment.mqh

93 lines
9 KiB
MQL5
Raw Permalink Normal View History

2025-05-30 16:34:43 +02:00
<EFBFBD><EFBFBD>//+------------------------------------------------------------------+
//| TradeEnvironment.mqh |
//| Copyright 2016, Vasiliy Sokolov, St-Petersburg, Russia |
//| https://www.mql5.com/ru/users/c-4 |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, Vasiliy Sokolov."
#property link "https://www.mql5.com/ru/users/c-4"
#include "Dictionary.mqh"
//+------------------------------------------------------------------+
//| B;>65==K9 >@45@. |
//+------------------------------------------------------------------+
/*class CPendingOrder : public CObject
{
public:
CPendingOrder(void) : Price(0.0){;}
double Price; // &5=0 A@010BK20=8O
};*/
//+------------------------------------------------------------------+
//| >4C;L B>@3>2>3> >:@C65=8O. 5B5:B8@C5B 53> 87<5=5=85 |
//| (:>;8G5AB2> 8AB>@8G5A:8/0:B82=KE >@45@>2 8 A45;>:). <5==> ?> |
//| 87<5=5=8N B>@3>2>3> >:@C65=8O CStrategy >?@545;O5B AB0BCA A2>8E |
//| B>@3>2KE >?5@0F89. 0==K9 :;0AA ?>72>;O5B 871560BL 2K7>20 |
//| A><=8B5;L=KE OnTrade 8 OnTradeTransaction. |
//+------------------------------------------------------------------+
class CTradeEnvironment
{
private:
CDictionary m_pending_orders;
int m_last_deals_count; // >A;54=55 70?><=5==>5 :>;8G5AB2> A45;>:
int m_last_pending_orders; // >A;54=55 70?><=5==>5 :>;8G5AB2> >B;>65==KE >@45@>2
int m_last_historders_count; // >A;54=55 70?><=5==>5 :>;8G5AB2> 8AB>@8G5A:8E >@45@>2
bool m_changed; // $;03 C:07K20NI89, GB> ?@>87>H;> 87<5=5=85 2 B>@3>2>< >:@C65=88
ulong m_last_change_time; // @5<O ?>A;54=53> 87<5=5=8O B>@3>2>3> >:@C65=8O
uint m_last_access; // @5<O ?>A;54=53> 4>ABC?0 : 8AB>@88 A45;>:.
ulong m_last_microseconds; // @5<O ?>A;54=53> 87<5=5=8O 8AB>@88 2 <8:@>A5:C=40E A <><5=B0 70?CA:0 ?@>3@0<<K.
bool DetectPendingChanges();
datetime StartTimeTerminal(void);
public:
CTradeEnvironment(void);
bool ChangeEnvironment(void);
void RememberEnvironment(void);
ulong LastMicrosecondsState(void);
};
//+------------------------------------------------------------------+
//| >=AB@C:B>@ ?>-C<>;G0=8N. |
//+------------------------------------------------------------------+
CTradeEnvironment::CTradeEnvironment(void) : m_changed(true)
{
}
//+------------------------------------------------------------------+
//| >72@0I05B 8AB8=C, 5A;8 B>@3>2>5 >:@C65=85 87<5=8;>AL |
//+------------------------------------------------------------------+
bool CTradeEnvironment::ChangeEnvironment(void)
{
if(m_changed)return true;
datetime dt=D'2115.01.01';
HistorySelect(0,dt);
if(HistoryDealsTotal()!=m_last_deals_count)
{
m_changed=true;
}
return m_changed;
}
//+------------------------------------------------------------------+
//| !>E@0=O5B B5:CI55 B>@3>2>5 A>AB>O=85 |
//+------------------------------------------------------------------+
void CTradeEnvironment::RememberEnvironment(void)
{
HistorySelect(0,D'2115.01.01');
m_last_deals_count=HistoryDealsTotal();
m_changed=false;
m_last_microseconds=GetMicrosecondCount();
}
//+------------------------------------------------------------------+
//| >72@0I05B 2@5<O AB0@B0 B5@<8=0;0. |
//+------------------------------------------------------------------+
datetime CTradeEnvironment::StartTimeTerminal(void)
{
uint start_seconds=(uint)MathRound(GetMicrosecondCount()/1000000.0)+1;
datetime time_begin=TimeCurrent()-start_seconds;
return time_begin;
}
//+------------------------------------------------------------------+
//| >72@0I05B 2@5<O ?>A;54=53> 87<5=5=8O B>@3>2>3> A>AB>O=8O |
//| 2 <8:@>A5:C=40E A =0G0;0 @01>BK ?@>3@0<<K. |
//+------------------------------------------------------------------+
ulong CTradeEnvironment::LastMicrosecondsState(void)
{
return m_last_microseconds;
}
//+------------------------------------------------------------------+