EA-Setka-2/Libs/CtrlPanel/GraphFunction.mqh

233 lines
21 KiB
MQL5
Raw Permalink Normal View History

2025-05-30 14:50:44 +02:00
<EFBFBD><EFBFBD>//+------------------------------------------------------------------+
//| GraphFunction.mqh |
//| Copyright 2021, MetaQuotes Ltd. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Ltd."
#property link "https://www.mql5.com"
//+------------------------------------------------------------------+
//| !>7405B 3>@87>=B0;L=CN ;8=8N |
//+------------------------------------------------------------------+
bool HLineCreate(const long chart_ID=0, // ID 3@0D8:0
const string name="HLine", // 8<O ;8=88
const int sub_window=0, // =><5@ ?>4>:=0
double price=0, // F5=0 ;8=88
const color clr=clrRed, // F25B ;8=88
const ENUM_LINE_STYLE style=STYLE_SOLID, // AB8;L ;8=88
const int width=1, // B>;I8=0 ;8=88
const string tooltip="", // 2A?;K20NI0O ?>4A:07:0
const bool back=false, // =0 704=5< ?;0=5
const bool selection=true, // 2K45;8BL 4;O ?5@5<5I5=89
const bool hidden=true, // A:@KB 2 A?8A:5 >1J5:B>2
const long z_order=0) // ?@8>@8B5B =0 =060B85 <KHLN
{
//--- 5A;8 F5=0 =5 7040=0, B> CAB0=>28< 55 =0 C@>2=5 B5:CI59 F5=K Bid
if(!price)
price=SymbolInfoDouble(Symbol(),SYMBOL_BID);
//--- A1@>A8< 7=0G5=85 >H81:8
ResetLastError();
//--- A>74048< 3>@87>=B0;L=CN ;8=8N
if(!ObjectCreate(chart_ID,name,OBJ_HLINE,sub_window,0,price))
{
Print(__FUNCTION__,
": =5 C40;>AL A>740BL 3>@87>=B0;L=CN ;8=8N! >4 >H81:8 = ",GetLastError());
return(false);
}
//--- CAB0=>28< F25B ;8=88
ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);
//--- CAB0=>28< AB8;L >B>1@065=8O ;8=88
ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style);
//--- CAB0=>28< B>;I8=C ;8=88
ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,width);
//--- >B>1@078< =0 ?5@54=5< (false) 8;8 704=5< (true) ?;0=5
ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);
//--- 2:;NG8< (true) 8;8 >B:;NG8< (false) @568< ?5@5<5I5=8O ;8=88 <KHLN
//--- ?@8 A>740=88 3@0D8G5A:>3> >1J5:B0 DC=:F859 ObjectCreate, ?> C<>;G0=8N >1J5:B
//--- =5;L7O 2K45;8BL 8 ?5@5<5I0BL. =CB@8 65 MB>3> <5B>40 ?0@0<5B@ selection
//--- ?> C<>;G0=8N @025= true, GB> ?>72>;O5B 2K45;OBL 8 ?5@5<5I0BL MB>B >1J5:B
ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);
ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);
//--- A:@>5< (true) 8;8 >B>1@078< (false) 8<O 3@0D8G5A:>3> >1J5:B0 2 A?8A:5 >1J5:B>2
ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);
//--- CAB0=>28< ?@8>@8B5B =0 ?>;CG5=85 A>1KB8O =060B8O <KH8 =0 3@0D8:5
ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);
//--- CA?5H=>5 2K?>;=5=85
if (StringLen(tooltip))
{
ObjectSetString(chart_ID,name,OBJPROP_TOOLTIP,tooltip);
}
return(true);
}
//+------------------------------------------------------------------+
//| 5@5<5I5=85 3>@87>=B0;L=>9 ;8=88 |
//+------------------------------------------------------------------+
bool HLineMove(const long chart_ID=0, // ID 3@0D8:0
const string name="HLine", // 8<O ;8=88
double price=0) // F5=0 ;8=88
{
//--- 5A;8 F5=0 ;8=88 =5 7040=0, B> ?5@5<5I05< 55 =0 C@>25=L B5:CI59 F5=K Bid
if(!price)
price=SymbolInfoDouble(Symbol(),SYMBOL_BID);
//--- A1@>A8< 7=0G5=85 >H81:8
ResetLastError();
//--- ?5@5<5AB8< 3>@87>=B0;L=CN ;8=8N
if(!ObjectMove(chart_ID,name,0,0,price))
{
Print(__FUNCTION__,
": =5 C40;>AL ?5@5<5AB8BL 3>@87>=B0;L=CN ;8=8N! >4 >H81:8 = ",GetLastError());
return(false);
}
//--- CA?5H=>5 2K?>;=5=85
return(true);
}
//+------------------------------------------------------------------+
//| #40;O5B 3>@87>=B0;L=CN ;8=8N |
//+------------------------------------------------------------------+
bool HLineDelete(const long chart_ID=0, // ID 3@0D8:0
const string name="HLine") // 8<O ;8=88
{
//--- A1@>A8< 7=0G5=85 >H81:8
ResetLastError();
//--- C40;8< 3>@87>=B0;L=CN ;8=8N
if(!ObjectDelete(chart_ID,name)&&(GetLastError()!=4202))
{
Print(__FUNCTION__,
": =5 C40;>AL C40;8BL 3>@87>=B0;L=CN ;8=8N! >4 >H81:8 = ",GetLastError());
return(false);
}
//--- CA?5H=>5 2K?>;=5=85
return(true);
}
//+------------------------------------------------------------------+
//| !>7405B >1J5:B ""5:AB" |
//+------------------------------------------------------------------+
bool TextCreate(const long chart_ID=0, // ID 3@0D8:0
const string name="Text", // 8<O >1J5:B0
const int sub_window=0, // =><5@ ?>4>:=0
datetime time=0, // 2@5<O B>G:8 ?@82O7:8
double price=0, // F5=0 B>G:8 ?@82O7:8
const string text="Text", // A0< B5:AB
const string font="Arial", // H@8DB
const int font_size=10, // @07<5@ H@8DB0
const color clr=clrRed, // F25B
const double angle=0.0, // =0:;>= B5:AB0
const ENUM_ANCHOR_POINT anchor=ANCHOR_LEFT_UPPER, // A?>A>1 ?@82O7:8
const bool back=false, // =0 704=5< ?;0=5
const bool selection=false, // 2K45;8BL 4;O ?5@5<5I5=89
const bool hidden=true, // A:@KB 2 A?8A:5 >1J5:B>2
const long z_order=0) // ?@8>@8B5B =0 =060B85 <KHLN
{
//--- CAB0=>28< :>>@48=0BK B>G:8 ?@82O7:8, 5A;8 >=8 =5 7040=K
ChangeTextEmptyPoint(time,price);
//--- A1@>A8< 7=0G5=85 >H81:8
ResetLastError();
//--- A>74048< >1J5:B ""5:AB"
if(!ObjectCreate(chart_ID,name,OBJ_TEXT,sub_window,time,price))
{
Print(__FUNCTION__,
": =5 C40;>AL A>740BL >1J5:B \""5:AB\"! >4 >H81:8 = ",GetLastError());
return(false);
}
//--- CAB0=>28< B5:AB
ObjectSetString(chart_ID,name,OBJPROP_TEXT,text);
//--- CAB0=>28< H@8DB B5:AB0
ObjectSetString(chart_ID,name,OBJPROP_FONT,font);
//--- CAB0=>28< @07<5@ H@8DB0
ObjectSetInteger(chart_ID,name,OBJPROP_FONTSIZE,font_size);
//--- CAB0=>28< C3>; =0:;>=0 B5:AB0
ObjectSetDouble(chart_ID,name,OBJPROP_ANGLE,angle);
//--- CAB0=>28< A?>A>1 ?@82O7:8
ObjectSetInteger(chart_ID,name,OBJPROP_ANCHOR,anchor);
//--- CAB0=>28< F25B
ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);
//--- >B>1@078< =0 ?5@54=5< (false) 8;8 704=5< (true) ?;0=5
ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);
//--- 2:;NG8< (true) 8;8 >B:;NG8< (false) @568< ?5@5<5I5=8O >1J5:B0 <KHLN
ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);
ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);
//--- A:@>5< (true) 8;8 >B>1@078< (false) 8<O 3@0D8G5A:>3> >1J5:B0 2 A?8A:5 >1J5:B>2
ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);
//--- CAB0=>28< ?@8>@8B5B =0 ?>;CG5=85 A>1KB8O =060B8O <KH8 =0 3@0D8:5
ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);
//--- CA?5H=>5 2K?>;=5=85
return(true);
}
//+------------------------------------------------------------------+
//| 5@5<5I05B B>G:C ?@82O7:8 |
//+------------------------------------------------------------------+
bool TextMove(const long chart_ID=0, // ID 3@0D8:0
const string name="Text", // 8<O >1J5:B0
datetime time=0, // :>>@48=0B0 2@5<5=8 B>G:8 ?@82O7:8
double price=0) // :>>@48=0B0 F5=K B>G:8 ?@82O7:8
{
//--- 5A;8 :>>@48=0BK B>G:8 =5 7040=K, B> ?5@5<5I05< 55 =0 B5:CI89 10@ A F5=>9 Bid
if(!time)
time=TimeCurrent();
if(!price)
price=SymbolInfoDouble(Symbol(),SYMBOL_BID);
//--- A1@>A8< 7=0G5=85 >H81:8
ResetLastError();
//--- ?5@5<5AB8< B>G:C ?@82O7:8
if(!ObjectMove(chart_ID,name,0,time,price))
{
Print(__FUNCTION__,
": =5 C40;>AL ?5@5<5AB8BL B>G:C ?@82O7:8! >4 >H81:8 = ",GetLastError());
return(false);
}
//--- CA?5H=>5 2K?>;=5=85
return(true);
}
//+------------------------------------------------------------------+
//| 7<5=O5B B5:AB >1J5:B0 |
//+------------------------------------------------------------------+
bool TextChange(const long chart_ID=0, // ID 3@0D8:0
const string name="Text", // 8<O >1J5:B0
const string text="Text") // B5:AB
{
//--- A1@>A8< 7=0G5=85 >H81:8
ResetLastError();
//--- 87<5=8< B5:AB >1J5:B0
if(!ObjectSetString(chart_ID,name,OBJPROP_TEXT,text))
{
Print(__FUNCTION__,
": =5 C40;>AL 87<5=8BL B5:AB! >4 >H81:8 = ",GetLastError());
return(false);
}
//--- CA?5H=>5 2K?>;=5=85
return(true);
}
//+------------------------------------------------------------------+
//| #40;O5B >1J5:B ""5:AB" |
//+------------------------------------------------------------------+
bool TextDelete(const long chart_ID=0, // ID 3@0D8:0
const string name="Text") // 8<O >1J5:B0
{
//--- A1@>A8< 7=0G5=85 >H81:8
ResetLastError();
//--- C40;8< >1J5:B
if(!ObjectDelete(chart_ID,name))
{
Print(__FUNCTION__,
": =5 C40;>AL C40;8BL >1J5:B \""5:AB\"! >4 >H81:8 = ",GetLastError());
return(false);
}
//--- CA?5H=>5 2K?>;=5=85
return(true);
}
//+------------------------------------------------------------------+
//| @>25@O5B 7=0G5=8O B>G:8 ?@82O7:8 8 4;O ?CABKE 7=0G5=89 |
//| CAB0=02;8205B 7=0G5=8O ?> C<>;G0=8N |
//+------------------------------------------------------------------+
void ChangeTextEmptyPoint(datetime &time,double &price)
{
//--- 5A;8 2@5<O B>G:8 =5 7040=>, B> >=0 1C45B =0 B5:CI5< 10@5
if(!time)
time=TimeCurrent();
//--- 5A;8 F5=0 B>G:8 =5 7040=0, B> >=0 1C45B 8<5BL 7=0G5=85 Bid
if(!price)
price=SymbolInfoDouble(Symbol(),SYMBOL_BID);
}