Article-15026-MQL5-Trade-Hi.../PositionsControl.mqh

495 lines
44 KiB
MQL5
Raw Permalink Normal View History

2026-03-23 12:53:11 +07:00
<EFBFBD><EFBFBD>//+------------------------------------------------------------------+
//| PositionsControl.mqh |
//| Copyright 2024, MetaQuotes Ltd. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2024, MetaQuotes Ltd."
#property link "https://www.mql5.com"
#property version "1.00"
#include "Position.mqh"
//+------------------------------------------------------------------+
//| ;0AA 8AB>@8G5A:8E ?>78F89 |
//+------------------------------------------------------------------+
class CPositionsControl : public CObject
{
private:
string m_symbol; // =AB@C<5=B, ?> :>B>@><C >B:@KB0 ?>78F8O
long m_current_id; // 45=B8D8:0B>@ B5:CI59 >B>1@06Q==>9 =0 3@0D8:5 ?>78F88
bool m_key_ctrl; // $;03 @07@5H5=85 =0 C?@02;5=85 3@0D8:>< A ?><>ILN :;0280BC@K
//--- >72@0I05B B8? ?>78F88 ?> B8?C A45;:8
ENUM_POSITION_TYPE PositionTypeByDeal(const CDeal *deal);
protected:
CPosition m_temp_pos; // @5<5==K9 >1J5:B ?>78F88 4;O ?>8A:0
CArrayObj m_list_pos; // !?8A>: ?>78F89
long m_chart_id; // 45=B8D8:0B>@ 3@0D8:0
//--- >72@0I05B >1J5:B-?>78F8N 87 A?8A:0 ?> 845=B8D8:0B>@C
CPosition *GetPositionObjByID(const long id);
//--- >72@0I05B D;03 B>3>, GB> ?>78F8O @K=>G=0O
bool IsMarketPosition(const long id);
//--- >72@0I05B C:070B5;L =0 (1) ?5@2CN, (2) ?>A;54=NN 70:@KBCN ?>78F8N 2 A?8A:5
CPosition *GetFirstClosedPosition(void);
CPosition *GetLastClosedPosition(void);
//--- >72@0I05B C:070B5;L =0 (1) ?@54K4CICN, (2) A;54CNICN 70:@KBCN ?>78F8N 2 A?8A:5
CPosition *GetPrevClosedPosition(CPosition *current);
CPosition *GetNextClosedPosition(CPosition *current);
//--- B>1@0605B =0 3@0D8:5 3@0D8G5A:>5 ?@54AB02;5=85 C:070==>9 ?>78F88
void Show(CPosition *pos, const bool chart_redraw=false);
//--- &5=B@8@C5B 3@0D8: =0 B5:CI59 2K1@0==>9 ?>78F88
void CentersChartByCurrentSelected(void);
//--- >72@0I05B 845=B8D8:0B>@ B5:CI59 2K1@0==>9 ?>78F88
long CurrentSelectedID(void) const { return this.m_current_id; }
//--- >72@0I05B 2@5<O (1) >B:@KB8O, (2) 70:@KB8O B5:CI59 2K1@0==>9 ?>78F88
datetime TimeOpenCurrentSelected(void);
datetime TimeCloseCurrentSelected(void);
//--- !:@K205B =0 3@0D8:5 3@0D8G5A:>5 ?@54AB02;5=85 2A5E ?>78F89, :@><5 C:070==>9
void HideAllExceptOne(const long pos_id, const bool chart_redraw=false);
public:
//--- >72@0I05B (1) A8<2>;, (2) 845=B8D8:0B>@ 3@0D8:0
string Symbol(void) const { return this.m_symbol; }
long ChartID(void) const { return this.m_chart_id; }
//--- !>740QB 8 >1=>2;O5B A?8A>: ?>78F89. >65B 1KBL ?5@5>?@545;Q= 2 =0A;54C5<KE :;0AA0E
virtual bool Refresh(void);
//--- >72@0I05B :>;8G5AB2> ?>78F89 2 A?8A:5
int Total(void) const { return this.m_list_pos.Total(); }
//--- (1) !:@K205B, (2) >B>1@0605B =0 3@0D8:5 3@0D8G5A:>5 ?@54AB02;5=85 ?5@2>9 ?>78F88
void HideFirst(const bool chart_redraw=false);
void ShowFirst(const bool chart_redraw=false);
//--- (1) !:@K205B, (2) >B>1@0605B =0 3@0D8:5 3@0D8G5A:>5 ?@54AB02;5=85 ?>A;54=59 ?>78F88
void HideLast(const bool chart_redraw=false);
void ShowLast(const bool chart_redraw=false);
//--- B>1@0605B =0 3@0D8:5 3@0D8G5A:>5 ?@54AB02;5=85 (1) B5:CI59, (2) ?@54K4CI59, (3) A;54CNI59 ?>78F88
void ShowCurrent(const bool chart_redraw=false);
void ShowPrev(const bool chart_redraw=false);
void ShowNext(const bool chart_redraw=false);
//--- >72@0I05B >?8A0=85 B5:CI59 2K1@0==>9 ?>78F88
string CurrentSelectedDescription(void);
//--- 0A?5G0BK205B 2 6C@=0;5 A2>9AB20 2A5E ?>78F89 2 A?8A:5 8 8E A45;>:
void Print(void);
//--- >=AB@C:B>@/45AB@C:B>@
CPositionsControl(const string symbol=NULL);
~CPositionsControl();
};
//+------------------------------------------------------------------+
//| >=AB@C:B>@ |
//+------------------------------------------------------------------+
CPositionsControl::CPositionsControl(const string symbol=NULL)
{
this.m_list_pos.Sort(SORT_MODE_POSITION_TIME_CLOSE_MSC);
this.m_symbol = (symbol==NULL ? ::Symbol() : symbol);
this.m_chart_id = ::ChartID();
this.m_current_id = 0;
this.m_key_ctrl = ::ChartGetInteger(this.m_chart_id, CHART_KEYBOARD_CONTROL);
}
//+------------------------------------------------------------------+
//| 5AB@C:B>@ |
//+------------------------------------------------------------------+
CPositionsControl::~CPositionsControl()
{
this.m_list_pos.Shutdown();
::ChartSetInteger(this.m_chart_id, CHART_KEYBOARD_CONTROL, this.m_key_ctrl);
}
//+------------------------------------------------------------------+
//| >72@0I05B >1J5:B-?>78F8N 87 A?8A:0 ?> 845=B8D8:0B>@C |
//+------------------------------------------------------------------+
CPosition *CPositionsControl::GetPositionObjByID(const long id)
{
//--- #AB0=02;8205< 2@5<5==><C >1J5:BC 845=B8D8:0B>@ ?>78F88, 0 A?8A:C - D;03 A>@B8@>2:8 ?> 845=B8D8:0B>@C ?>78F88
this.m_temp_pos.SetID(id);
this.m_list_pos.Sort(SORT_MODE_POSITION_IDENTIFIER);
//--- >;CG05< 87 A?8A:0 8=45:A >1J5:B0-?>78F88 A B0:8< 845=B8D8:0B>@>< (;81> -1 ?@8 53> >BACBAB288)
//--- > ?>;CG5==><C 8=45:AC ?>;CG05< C:070B5;L =0 >1J5:B ?>78F8N 87 A?8A:0 (;81> NULL ?@8 7=0G5=88 8=45:A0 -1)
int index=this.m_list_pos.Search(&this.m_temp_pos);
CPosition *pos=this.m_list_pos.At(index);
//--- #AB0=02;8205< A?8A:C D;03 A>@B8@>2:8 ?> 2@5<5=8 70:@KB8O ?>78F88 2 <8;;8A5:C=40E 8
//--- 2>72@0I05< C:070B5;L =0 >1J5:B-?>78F8N (;81> NULL ?@8 53> >BACBAB288)
this.m_list_pos.Sort(SORT_MODE_POSITION_TIME_CLOSE_MSC);
return pos;
}
//+------------------------------------------------------------------+
//| >72@0I05B D;03 B>3>, GB> ?>78F8O @K=>G=0O |
//+------------------------------------------------------------------+
bool CPositionsControl::IsMarketPosition(const long id)
{
//---  F8:;5 ?> A?8A:C 459AB2CNI8E ?>78F89 2 B5@<8=0;5
for(int i=::PositionsTotal()-1; i>=0; i--)
{
//--- ?>;CG05< B8:5B ?>78F88 ?> 8=45:AC F8:;0
ulong ticket=::PositionGetTicket(i);
//--- A;8 B8:5B ?>;CG5= 8 ?>78F8N <>6=> 2K1@0BL 8 5Q 845=B8D8:0B>@ @025= ?5@540==><C 2 <5B>4 -
//--- MB> 8A:><0O @K=>G=0O ?>78F8O, 2>72@0I05< true
if(ticket!=0 && ::PositionSelectByTicket(ticket) && ::PositionGetInteger(POSITION_IDENTIFIER)==id)
return true;
}
//--- 5B B0:>9 @K=>G=>9 ?>78F88 - 2>72@0I05< false
return false;
}
//+------------------------------------------------------------------+
//| >72@0I05B C:070B5;L =0 ?5@2CN 70:@KBCN ?>78F8N 2 A?8A:5 |
//+------------------------------------------------------------------+
CPosition *CPositionsControl::GetFirstClosedPosition(void)
{
this.m_list_pos.Sort(SORT_MODE_POSITION_TIME_CLOSE_MSC);
return this.m_list_pos.At(0);
}
//+------------------------------------------------------------------+
//| >72@0I05B C:070B5;L =0 ?>A;54=NN 70:@KBCN ?>78F8N 2 A?8A:5 |
//+------------------------------------------------------------------+
CPosition *CPositionsControl::GetLastClosedPosition(void)
{
this.m_list_pos.Sort(SORT_MODE_POSITION_TIME_CLOSE_MSC);
return this.m_list_pos.At(this.m_list_pos.Total()-1);
}
//+------------------------------------------------------------------+
//| >72@0I05B C:070B5;L =0 ?@54K4CICN 70:@KBCN ?>78F8N 2 A?8A:5 |
//+------------------------------------------------------------------+
CPosition *CPositionsControl::GetPrevClosedPosition(CPosition *current)
{
this.m_list_pos.Sort(SORT_MODE_POSITION_TIME_CLOSE_MSC);
int prev=this.m_list_pos.SearchLess(current);
return this.m_list_pos.At(prev);
}
//+------------------------------------------------------------------+
//| >72@0I05B C:070B5;L =0 A;54CNICN 70:@KBCN ?>78F8N 2 A?8A:5 |
//+------------------------------------------------------------------+
CPosition *CPositionsControl::GetNextClosedPosition(CPosition *current)
{
this.m_list_pos.Sort(SORT_MODE_POSITION_TIME_CLOSE_MSC);
int next=this.m_list_pos.SearchGreat(current);
return this.m_list_pos.At(next);
}
//+------------------------------------------------------------------+
//| K2>48B =0 3@0D8: 3@0D8G5A:>5 ?@54AB02;5=85 C:070==>9 ?>78F88 |
//+------------------------------------------------------------------+
void CPositionsControl::Show(CPosition *pos,const bool chart_redraw=false)
{
if(pos!=NULL)
{
pos.Show(chart_redraw);
this.m_current_id=pos.ID();
}
}
//+------------------------------------------------------------------+
//| !:@K205B A 3@0D8:0 3@0D8G5A:>5 ?@54AB02;5=85 ?5@2>9 ?>78F88 |
//+------------------------------------------------------------------+
void CPositionsControl::HideFirst(const bool chart_redraw=false)
{
CPosition *pos=this.GetFirstClosedPosition();
if(pos!=NULL)
pos.Hide(chart_redraw);
}
//+------------------------------------------------------------------+
//| B>1@0605B =0 3@0D8:5 3@0D8G5A:>5 ?@54AB02;5=85 ?5@2>9 ?>78F88 |
//+------------------------------------------------------------------+
void CPositionsControl::ShowFirst(const bool chart_redraw=false)
{
//--- >;CG05< C:070B5;L =0 ?5@2CN 70:@KBCN ?>78F8N
CPosition *pos=this.GetFirstClosedPosition();
if(pos==NULL)
return;
//--- !:@K205< 7=0G:8 2A5E ?>78F89, :@><5 ?5@2>9 ?> 5Q 845=B8D8:0B>@C
this.HideAllExceptOne(pos.ID());
//--- B>1@0605< 7=0G:8 ?5@2>9 ?>78F88 =0 3@0D8:5 8
//--- F5=B@8@C5< 3@0D8: ?> 7=0G:0< B5:CI59 2K1@0==>9 ?>78F88
this.Show(pos,chart_redraw);
this.CentersChartByCurrentSelected();
}
//+------------------------------------------------------------------+
//| !:@K205B A 3@0D8:0 3@0D8G5A:>5 ?@54AB02;5=85 ?>A;54=59 ?>78F88 |
//+------------------------------------------------------------------+
void CPositionsControl::HideLast(const bool chart_redraw=false)
{
CPosition *pos=this.GetLastClosedPosition();
if(pos!=NULL)
pos.Hide(chart_redraw);
}
//+------------------------------------------------------------------+
//| B>1@0605B =0 3@0D8:5 3@0D8G5A:>5 ?@54AB02;5=85 ?>A;54=59 ?>78F88|
//+------------------------------------------------------------------+
void CPositionsControl::ShowLast(const bool chart_redraw=false)
{
//--- >;CG05< C:070B5;L =0 ?>A;54=NN 70:@KBCN ?>78F8N
CPosition *pos=this.GetLastClosedPosition();
if(pos==NULL)
return;
//--- !:@K205< 7=0G:8 2A5E ?>78F89, :@><5 ?>A;54=59 ?> 5Q 845=B8D8:0B>@C
this.HideAllExceptOne(pos.ID(), false);
//--- B>1@0605< 7=0G:8 ?>A;54=59 ?>78F88 =0 3@0D8:5 8
//--- F5=B@8@C5< 3@0D8: ?> 7=0G:0< B5:CI59 2K1@0==>9 ?>78F88
this.Show(pos,chart_redraw);
this.CentersChartByCurrentSelected();
}
//+------------------------------------------------------------------+
//| B>1@0605B =0 3@0D8:5 3@0D8G5A:>5 ?@54AB02;5=85 B5:CI59 ?>78F88 |
//+------------------------------------------------------------------+
void CPositionsControl::ShowCurrent(const bool chart_redraw=false)
{
//--- >;CG05< C:070B5;L =0 B5:CICN 2K1@0==CN 70:@KBCN ?>78F8N
CPosition *curr=this.GetPositionObjByID(this.CurrentSelectedID());
if(curr==NULL)
return;
//--- B>1@0605< 7=0G:8 B5:CI59 ?>78F88 =0 3@0D8:5 8
//--- F5=B@8@C5< 3@0D8: ?> 7=0G:0< B5:CI59 2K1@0==>9 ?>78F88
this.Show(curr,chart_redraw);
this.CentersChartByCurrentSelected();
}
//+------------------------------------------------------------------+
//|B>1@0605B =0 3@0D8:5 3@0D8G5A:>5 ?@54AB02;5=85 ?@54K4CI59 ?>78F88|
//+------------------------------------------------------------------+
void CPositionsControl::ShowPrev(const bool chart_redraw=false)
{
//--- >;CG05< C:070B5;L =0 B5:CICN 8 ?@54K4CICN ?>78F88
CPosition *curr=this.GetPositionObjByID(this.CurrentSelectedID());
CPosition *prev=this.GetPrevClosedPosition(curr);
if(curr==NULL || prev==NULL)
return;
//--- "5:CICN ?>78F8N A:@K205<, ?@54K4CICN >B>1@0605< 8
//--- F5=B@8@C5< 3@0D8: ?> 7=0G:0< B5:CI59 2K1@0==>9 ?>78F88
curr.Hide();
this.Show(prev,chart_redraw);
this.CentersChartByCurrentSelected();
}
//+------------------------------------------------------------------+
//| B>1@0605B =0 3@0D8:5 3@0D8G5A:>5 ?@54AB02;5=85 A;54CNI59 ?>78F88|
//+------------------------------------------------------------------+
void CPositionsControl::ShowNext(const bool chart_redraw=false)
{
//--- >;CG05< C:070B5;L =0 B5:CICN 8 A;54CNICN ?>78F88
CPosition *curr=this.GetPositionObjByID(this.CurrentSelectedID());
CPosition *next=this.GetNextClosedPosition(curr);
if(curr==NULL || next==NULL)
return;
//--- "5:CICN ?>78F8N A:@K205<, A;54CNICN >B>1@0605< 8
//--- F5=B@8@C5< 3@0D8: ?> 7=0G:0< B5:CI59 2K1@0==>9 ?>78F88
curr.Hide();
this.Show(next,chart_redraw);
this.CentersChartByCurrentSelected();
}
//+------------------------------------------------------------------+
//| !:@K205B A 3@0D8:0 3@0D8G5A:>5 ?@54AB02;5=85 |
//| 2A5E ?>78F89, :@><5 C:070==>9 |
//+------------------------------------------------------------------+
void CPositionsControl::HideAllExceptOne(const long pos_id,const bool chart_redraw=false)
{
//---  F8:;5 ?> A?8A:C ?>78F89
int total=this.m_list_pos.Total();
for(int i=0; i<total; i++)
{
//--- ?>;CG05< C:070B5;L =0 >G5@54=CN ?>78F8N 8
CPosition *pos=this.m_list_pos.At(i);
if(pos==NULL || pos.ID()==pos_id)
continue;
//--- A:@K205< 3@0D8G5A:>5 ?@54AB02;5=85 ?>78F88
pos.Hide();
}
//--- >A;5 F8:;0 ?@8 CAB0=>2;5==>< D;035 >1=>2;O5< 3@0D8:
if(chart_redraw)
::ChartRedraw(this.m_chart_id);
}
//+------------------------------------------------------------------+
//| &5=B@8@C5B 3@0D8: =0 B5:CI59 2K1@0==>9 ?>78F88 |
//+------------------------------------------------------------------+
void CPositionsControl::CentersChartByCurrentSelected(void)
{
//--- >;CG05< 8=45:A ?5@2>3> 2848<>3> 10@0 =0 3@0D8:5 8 :>;8G5AB2> 2848<KE 10@>2
int bar_open=0, bar_close=0;
int first_visible=(int)::ChartGetInteger(this.m_chart_id, CHART_FIRST_VISIBLE_BAR);
int visible_bars =(int)::ChartGetInteger(this.m_chart_id, CHART_VISIBLE_BARS);
//--- >;CG05< 2@5<O >B:@KB8O ?>78F88, 0 ?> =5<C - 10@ >B:@KB8O
datetime time_open=this.TimeOpenCurrentSelected();
if(time_open!=0)
bar_open=::iBarShift(this.m_symbol, PERIOD_CURRENT, time_open);
//--- >;CG05< 2@5<O 70:@KB8O ?>78F88, 0 ?> =5<C - 10@ 70:@KB8O
datetime time_close=this.TimeCloseCurrentSelected();
if(time_close!=0)
bar_close=::iBarShift(this.m_symbol, PERIOD_CURRENT, time_close);
//--- 0AAG8B05< H8@8=C >:=0, 2 :>B>@>< @0A?>;>65=K 7=0G:8 A45;:8
int width=bar_open-bar_close;
//--- 0AAG8B05< A<5I5=85 3@0D8:0 B0:, GB>1K >:=> A> A45;:0<8 =0E>48;>AL ?> F5=B@C 3@0D8:0
int shift=(bar_open + visible_bars/2 - width/2);
//--- A;8 H8@8=0 >:=0 1>;LH5 H8@8=K 3@0D8:0, B> A45;:0 >B:@KB8O 1C45B @0A?>;030BLAO =0 2B>@>< 2848<>< 10@5
if(shift-bar_open<0)
shift=bar_open+1;
//--- A;8 10@ A45;:8 >B:@KB8O ;5255 ?5@2>3> 2848<>3> 10@0 3@0D8:0,
//--- 8;8 10@ A45;:8 >B:@KB8O ?@0255 ?>A;54=53> 2848<>3> 10@0 3@0D8:0 -
//--- ?@>:@CG8205< 3@0D8: =0 @0AAG8B0==>5 A<5I5=85
if(bar_open>first_visible || bar_open<first_visible+visible_bars)
::ChartNavigate(this.m_chart_id, CHART_CURRENT_POS, first_visible-shift);
}
//+------------------------------------------------------------------+
//| >72@0I05B 2@5<O >B:@KB8O B5:CI59 2K1@0==>9 ?>78F88 |
//+------------------------------------------------------------------+
datetime CPositionsControl::TimeOpenCurrentSelected(void)
{
CPosition *pos=this.GetPositionObjByID(this.CurrentSelectedID());
return(pos!=NULL ? pos.Time() : 0);
}
//+------------------------------------------------------------------+
//| >72@0I05B 2@5<O 70:@KB8O B5:CI59 2K1@0==>9 ?>78F88 |
//+------------------------------------------------------------------+
datetime CPositionsControl::TimeCloseCurrentSelected(void)
{
CPosition *pos=this.GetPositionObjByID(this.CurrentSelectedID());
return(pos!=NULL ? pos.TimeClose() : 0);
}
//+------------------------------------------------------------------+
//| >72@0I05B B8? ?>78F88 ?> B8?C A45;:8 |
//+------------------------------------------------------------------+
ENUM_POSITION_TYPE CPositionsControl::PositionTypeByDeal(const CDeal *deal)
{
if(deal==NULL)
return WRONG_VALUE;
switch(deal.TypeDeal())
{
case DEAL_TYPE_BUY : return POSITION_TYPE_BUY;
case DEAL_TYPE_SELL : return POSITION_TYPE_SELL;
default : return WRONG_VALUE;
}
}
//+------------------------------------------------------------------+
//| !>740QB A?8A>: 8AB>@8G5A:8E ?>78F89 |
//+------------------------------------------------------------------+
bool CPositionsControl::Refresh(void)
{
//--- A;8 70?@>A8BL 8AB>@8N A45;>: 8 >@45@>2 =5 C40;>AL - 2>72@0I05< false
if(!::HistorySelect(0,::TimeCurrent()))
return false;
//--- !B028< A?8A:C ?>78F89 D;03 A>@B8@>2:8 ?> 2@5<5=8 2 <8;;8A5:C=40E
this.m_list_pos.Sort(SORT_MODE_POSITION_TIME_MSC);
//--- 1JO2;O5< ?5@5<5==CN @57C;LB0B0 8 C:070B5;L =0 >1J5:B ?>78F88
bool res=true;
CPosition *pos=NULL;
//---  F8:;5 ?> :>;8G5AB2C A45;>: 8AB>@88
int total=::HistoryDealsTotal();
for(int i=total-1; i>=0; i--)
{
//--- ?>;CG05< B8:5B >G5@54=>9 A45;:8 2 A?8A:5
ulong ticket=::HistoryDealGetTicket(i);
//--- A;8 B8:5B A45;:8 =5 ?>;CG5=, 8;8 MB> =5 >?5@0F8O ?>:C?:8/?@>4068, 8;8 5A;8 A45;:0 =5 ?> A8<2>;C, CAB0=>2;5==><C 4;O :;0AA0 - 84Q< 40;LH5
ENUM_DEAL_TYPE deal_type=(ENUM_DEAL_TYPE)::HistoryDealGetInteger(ticket, DEAL_TYPE);
if(ticket==0 || (deal_type!=DEAL_TYPE_BUY && deal_type!=DEAL_TYPE_SELL) || ::HistoryDealGetString(ticket, DEAL_SYMBOL)!=this.m_symbol)
continue;
//--- >;CG05< 87 A45;:8 7=0G5=85 845=B8D8:0B>@0 ?>78F88
long pos_id=::HistoryDealGetInteger(ticket, DEAL_POSITION_ID);
//--- A;8 MB> @K=>G=0O ?>78F8O - 84Q< 40;55
if(this.IsMarketPosition(pos_id))
continue;
//--- >;CG05< C:070B5;L =0 >1J5:B-?>78F8N 87 A?8A:0
pos=this.GetPositionObjByID(pos_id);
//--- A;8 ?>78F88 A B0:8< 845=B8D8:0B>@>< 2 A?8A:5 5IQ =5B
if(pos==NULL)
{
//--- !>740Q< =>2K9 >1J5:B ?>78F88 8, 5A;8 >1J5:B A>740BL =5 C40;>AL, 4>102;O5< : ?5@5<5==>9 res 7=0G5=85 false 8 84Q< 40;55
pos=new CPosition(pos_id, this.m_symbol);
if(pos==NULL)
{
res &=false;
continue;
}
//--- A;8 >1J5:B ?>78F88 =5 C40;>AL 4>1028BL 2 A?8A>: - 4>102;O5< : ?5@5<5==>9 res 7=0G5=85 false, C40;O5< >1J5:B ?>78F88 8 84Q< 40;55
if(!this.m_list_pos.InsertSort(pos))
{
res &=false;
delete pos;
continue;
}
}
//--- A;8 >1J5:B A45;:8 =5 C40;>AL 4>1028BL 2 A?8A>: A45;>: >1J5:B0 ?>78F88 - 4>102;O5< : ?5@5<5==>9 res 7=0G5=85 false 8 84Q< 40;55
CDeal *deal=pos.DealAdd(ticket);
if(deal==NULL)
{
res &=false;
continue;
}
//--- AQ CA?5H=>.
//---  7028A8<>AB8 >B B8?0 A45;:8 CAB0=02;8205< A2>9AB20 ?>78F88
if(deal.Entry()==DEAL_ENTRY_IN)
{
pos.SetTime(deal.Time());
pos.SetTimeMsc(deal.TimeMsc());
ENUM_POSITION_TYPE type=this.PositionTypeByDeal(deal);
pos.SetTypePosition(type);
pos.SetPriceOpen(deal.Price());
pos.SetVolume(deal.Volume());
}
if(deal.Entry()==DEAL_ENTRY_OUT || deal.Entry()==DEAL_ENTRY_OUT_BY)
{
pos.SetPriceCurrent(deal.Price());
}
if(deal.Entry()==DEAL_ENTRY_INOUT)
{
ENUM_POSITION_TYPE type=this.PositionTypeByDeal(deal);
pos.SetTypePosition(type);
pos.SetVolume(deal.Volume()-pos.Volume());
}
}
//--- #AB0=02;8205< A?8A:C ?>78F89 D;03 A>@B8@>2:8 ?> 2@5<5=8 70:@KB8O 2 <8;;8A5:C=40E
this.m_list_pos.Sort(SORT_MODE_POSITION_TIME_CLOSE_MSC);
//--- >72@0I05< @57C;LB0B A>740=8O 8 4>102;5=8O ?>78F88 2 A?8A>:
return res;
}
//+------------------------------------------------------------------+
//| 0A?5G0BK205B 2 6C@=0;5 A2>9AB20 ?>78F89 8 8E A45;>: |
//+------------------------------------------------------------------+
void CPositionsControl::Print(void)
{
int total=this.m_list_pos.Total();
for(int i=0; i<total; i++)
{
CPosition *pos=this.m_list_pos.At(i);
if(pos==NULL)
continue;
pos.Print();
}
}
//+------------------------------------------------------------------+
//| >72@0I05B >?8A0=85 B5:CI59 2K1@0==>9 ?>78F88 |
//+------------------------------------------------------------------+
string CPositionsControl::CurrentSelectedDescription(void)
{
CPosition *pos=this.GetPositionObjByID(this.CurrentSelectedID());
return(pos!=NULL ? pos.Tooltip() : NULL);
}
//+------------------------------------------------------------------+