MARGINHEDGED

Author: Yuriy Tokman (YTG)
0 Views
0 Downloads
0 Favorites
MARGINHEDGED
ÿþ//+------------------------------------------------------------------+

//|                                                 MARGINHEDGED.mq4 |

//|                                               Yuriy Tokman (YTG) |

//|                       https://www.mql5.com/ru/users/satop/seller |

//+------------------------------------------------------------------+

#property copyright "Yuriy Tokman (YTG)"

#property link      "https://www.mql5.com/ru/users/satop/seller"

#property version   "1.00"

#property strict



input double Lot = 0.01;



int qwe = 0;

//+------------------------------------------------------------------+

//| Expert initialization function                                   |

//+------------------------------------------------------------------+

int OnInit()

  {

//---

   EventSetMillisecondTimer(100);

   LabelCreate(0,"ytg_q",0,20,30,CORNER_LEFT_UPPER,"v","Wingdings",10,clrRed,0.0);

//---

   return(INIT_SUCCEEDED);

  }

//+------------------------------------------------------------------+

//| Expert deinitialization function                                 |

//+------------------------------------------------------------------+

void OnDeinit(const int reason)

  {

//---

   GetDellName();

   EventKillTimer();

  }

//+------------------------------------------------------------------+

//| Timer function                                                   |

//+------------------------------------------------------------------+

void OnTimer()

  {

//---

  double MARGINHEDGED = ((MarketInfo(Symbol(),MODE_MARGINHEDGED)/AccountInfoInteger(ACCOUNT_LEVERAGE))*Lot)*Ask;

  double MARGININIT = ((MarketInfo(Symbol(),MODE_MARGININIT)/AccountInfoInteger(ACCOUNT_LEVERAGE))*Lot)*Ask;  

 if(qwe<0)qwe=0;

 if(qwe>100)qwe=100; 

 int x = 0;

 int y = 0;



   if(ObjectFind(0,"ytg_q")!=-1)

    {

     x = (int)ObjectGetInteger(0,"ytg_q",OBJPROP_XDISTANCE); 

     y = (int)ObjectGetInteger(0,"ytg_q",OBJPROP_YDISTANCE);         

    } 

 if(x>0 && y>0)

  {

   LabelCreate(0,"ytg_w",0,x,y+15,CORNER_LEFT_UPPER,"y","Wingdings",10,clrRed,0.0,ANCHOR_LEFT_UPPER,true,false);

   LabelCreate(0,"ytg_e",0,x,y+25,CORNER_LEFT_UPPER,"y","Wingdings",10,clrRed,180,ANCHOR_RIGHT_LOWER,true,false);

   

   ButtonCreate(0,"ytg_r",0,x+13,y,220+qwe*10,40+qwe,CORNER_LEFT_UPPER

   ,"MARGINHEDGED "+DoubleToString(MARGINHEDGED,2)+AccountCurrency()+" ("+DoubleToStr(MARGINHEDGED/(MARGININIT/100),1)+"%)",

   "Arial",10+qwe/3,clrBlack,clrLightBlue,clrNONE,false,true);       

  }   

 //----

  }

//+------------------------------------------------------------------+

//| ChartEvent function                                              |

//+------------------------------------------------------------------+

void OnChartEvent(const int id,

                  const long &lparam,

                  const double &dparam,

                  const string &sparam)

  {

//---

//--- =060B85 <KH:>9 =0 3@0D8G5A:>< >1J5:B5 

   if(id==CHARTEVENT_OBJECT_CLICK) 

     { 

      if(sparam=="ytg_w")qwe+=5;

      if(sparam=="ytg_e")qwe-=5;       

     } 

//---   

  }

//+------------------------------------------------------------------+

//+------------------------------------------------------------------+ 

//| !>7405B B5:AB>2CN <5B:C                                          | 

//+------------------------------------------------------------------+ 

bool LabelCreate(const long              chart_ID=0,               // ID 3@0D8:0 

                 const string            name="Label",             // 8<O <5B:8 

                 const int               sub_window=0,             // =><5@ ?>4>:=0 

                 const int               x=0,                      // :>>@48=0B0 ?> >A8 X 

                 const int               y=0,                      // :>>@48=0B0 ?> >A8 Y 

                 const ENUM_BASE_CORNER  corner=CORNER_LEFT_UPPER, // C3>; 3@0D8:0 4;O ?@82O7:8 

                 const string            text="Label",             // 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=true,               // =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 

  { 

//--- A1@>A8< 7=0G5=85 >H81:8 

   ResetLastError();

      if(ObjectFind(chart_ID,name)>=0)

     ObjectDelete(chart_ID,name); 

//--- A>74048< B5:AB>2CN <5B:C 

   if(!ObjectCreate(chart_ID,name,OBJ_LABEL,sub_window,0,0)) 

     { 

      Print(__FUNCTION__, 

            ": =5 C40;>AL A>740BL B5:AB>2CN <5B:C! >4 >H81:8 = ",GetLastError()); 

      return(false); 

     } 

//--- CAB0=>28< :>>@48=0BK <5B:8 

   ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,x); 

   ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,y); 

//--- CAB0=>28< C3>; 3@0D8:0, >B=>A8B5;L=> :>B>@>3> 1C4CB >?@545;OBLAO :>>@48=0BK B>G:8 

   ObjectSetInteger(chart_ID,name,OBJPROP_CORNER,corner); 

//--- 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 <5B:8 <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); 

  } 

//----

//----

void GetDellName(string name_n="ytg_")

  {

   string vName;

   for(int i=ObjectsTotal()-1; i>=0; i--)

     {

      vName=ObjectName(i);

      if(StringFind(vName,name_n)!=-1)

         ObjectDelete(vName);

     }

  }

//----+

//+------------------------------------------------------------------+ 

//| !>7405B :=>?:C                                                   | 

//+------------------------------------------------------------------+ 

bool ButtonCreate(const long              chart_ID=0,               // ID 3@0D8:0 

                  const string            name="Button",            // 8<O :=>?:8 

                  const int               sub_window=0,             // =><5@ ?>4>:=0 

                  const int               x=0,                      // :>>@48=0B0 ?> >A8 X 

                  const int               y=0,                      // :>>@48=0B0 ?> >A8 Y 

                  const int               width=50,                 // H8@8=0 :=>?:8 

                  const int               height=18,                // 2KA>B0 :=>?:8 

                  const ENUM_BASE_CORNER  corner=CORNER_LEFT_UPPER, // C3>; 3@0D8:0 4;O ?@82O7:8 

                  const string            text="Button",            // B5:AB 

                  const string            font="Arial",             // H@8DB 

                  const int               font_size=10,             // @07<5@ H@8DB0 

                  const color             clr=clrBlack,             // F25B B5:AB0 

                  const color             back_clr=C'236,233,216',  // F25B D>=0 

                  const color             border_clr=clrNONE,       // F25B 3@0=8FK 

                  const bool              state=false,              // =060B0/>B60B0 

                  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 

  { 

//--- A1@>A8< 7=0G5=85 >H81:8 

   ResetLastError();

       if(ObjectFind(chart_ID,name)>=0)

      ObjectDelete(chart_ID,name);  

//--- A>74048< :=>?:C 

   if(!ObjectCreate(chart_ID,name,OBJ_BUTTON,sub_window,0,0)) 

     { 

      Print(__FUNCTION__, 

            ": =5 C40;>AL A>740BL :=>?:C! >4 >H81:8 = ",GetLastError()); 

      return(false); 

     } 

//--- CAB0=>28< :>>@48=0BK :=>?:8 

   ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,x); 

   ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,y); 

//--- CAB0=>28< @07<5@ :=>?:8 

   ObjectSetInteger(chart_ID,name,OBJPROP_XSIZE,width); 

   ObjectSetInteger(chart_ID,name,OBJPROP_YSIZE,height); 

//--- CAB0=>28< C3>; 3@0D8:0, >B=>A8B5;L=> :>B>@>3> 1C4CB >?@545;OBLAO :>>@48=0BK B>G:8 

   ObjectSetInteger(chart_ID,name,OBJPROP_CORNER,corner); 

//--- 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< F25B B5:AB0 

   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr); 

//--- CAB0=>28< F25B D>=0 

   ObjectSetInteger(chart_ID,name,OBJPROP_BGCOLOR,back_clr); 

//--- CAB0=>28< F25B 3@0=8FK 

   ObjectSetInteger(chart_ID,name,OBJPROP_BORDER_COLOR,border_clr); 

//--- >B>1@078< =0 ?5@54=5< (false) 8;8 704=5< (true) ?;0=5 

   ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back); 

//--- ?5@52545< :=>?:C 2 7040==>5 A>AB>O=85 

   ObjectSetInteger(chart_ID,name,OBJPROP_STATE,state); 

//--- 2:;NG8< (true) 8;8 >B:;NG8< (false) @568< ?5@5<5I5=8O :=>?:8 <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); 

  }

//----

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---