InfoPanel_v1

Author: Copyright © 2016, Evbut
Orders Execution
Checks for the total of open orders
0 Views
0 Downloads
0 Favorites
InfoPanel_v1
ÿþ#property copyright "Copyright © 2016, Evbut"

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

#property version   "1.0"

#property description "This Indicator helps to calculate Risk and shows your trading results"

#property indicator_chart_window

#property strict





#define prefix           "InfoPanel_"

#define FonColor        clrAliceBlue          

#define txtfont         "Times New Roman"          

#define txtsize            10                      

#define txtcolor         clrBlack

#define Color1           clrWhite

#define Color2           clrTeal

#define Color3           clrRed

#define Color4           clrSilver

#define Color5           clrLightGray

#define marketinfo_size     10                  //  07<5@ <0AA820 4;O >1J5:B>2 ?0=5;8 <0@:5B 8=D>

#define risk_size            7                   //  07<5@ <0AA820 4;O >1J5:B>2 ?0=5;8 





//--- =5H=85 ?5@5<5==K5

extern  int     BarsCount  = 24;                // Bars for Volatility Calculation

//-----

//-- ,+  +

int stopout, stoploss = 0;

long   X=30, Y=30;

double Lot, balance, free, totallot, acc_maxlot, symbprof, symblot,

       marga,risk,totalprofit, pros, freelots;

string AC;

//-----

double spread = 0, stoplvl = 0, maxlot=0,ticksize=0.0,tickvalue=0.0,swaplong=0.0,

       swapshort=0.0, minlot=0.0, lotstep=0.0,  margreq=0.0;

       

//----- 0AA82K AB@>: 4;O MarketInfo ---------------------------------------------------------

string lable_name[marketinfo_size] =  {"spread", "stoplvl", "tickvalue", "ticksize", "swaplong", 

                                       "swapshort", "minlot", "lotstep", "maxlot",   "margreq"};

string lable_value[marketinfo_size] = {"v_spread", "v_stoplvl", "v_tickvalue", "v_ticksize", "v_swaplong", 

                                       "v_swapshort", "v_minlot", "v_lotstep", "v_maxlot", "v_margreq"};

//------------------------------------------------------------------------------------------------

//----- 0AA82K ?>4?8A59 4;O Risk Manager ---------------------

string lable_name1[risk_size] = {"balance", "freemargin", "risklot", "reallot", 

                                  "freelot", "curdrawdn", "stopout"};

string lable_value1[risk_size] = {"v_balance", "v_freemargin", "v_risklot",  "v_reallot",

                                 "v_freelot", "v_curdrawdn", "v_stopout"};

bool isRussianLang;

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

//| Custom indicator initialization function                         |

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

int OnInit()

{

   if (!IsTuningParametersCorrect()) return INIT_FAILED; 

      

   AC=AccountCurrency();

    if(AC == "USD") AC = " usd";

    if(AC == "EUR") AC = " eur";

        if(AC == "RUR")  AC = isRussianLang? " @C1" : " rur";

   

   return(INIT_SUCCEEDED);

}

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

//| Custom indicator deinitialization function                       |

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

void OnDeinit(const int reason)

{

   Del();

}

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

//| Custom indicator Start function                                  |

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

int start()

{

   balance    = AccountBalance();

   free       = AccountFreeMargin();

   minlot     = MarketInfo(Symbol(), MODE_MINLOT);

   maxlot     = MarketInfo(Symbol(), MODE_MAXLOT);

   lotstep    = MarketInfo(Symbol(), MODE_LOTSTEP);

   stoplvl    = MarketInfo(Symbol(), MODE_STOPLEVEL);

   marga      = MarketInfo(Symbol(), MODE_MARGINREQUIRED);

   ticksize   = MarketInfo(Symbol(), MODE_TICKSIZE);

   tickvalue  = (Symbol() == "GOLD")? MarketInfo("XAUUSD", MODE_TICKVALUE)/5:

                                      MarketInfo(Symbol(), MODE_TICKVALUE);

   stopout = (int)AccountEquity()*AccountStopoutLevel()/100;



   Redraw();

   return(0);

}

//--------------------------------------------------------------------

void Del()

{

   ObjectsDeleteAll(0,prefix);

}

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

//| Checking the correctness of input parameters                   |

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

bool IsTuningParametersCorrect()

{

   isRussianLang = (TerminalInfoString(TERMINAL_LANGUAGE) == "Russian");

   

  return(true);

}

//--------------------------------------------------------------------

void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam)

{

   if(id==CHARTEVENT_OBJECT_CLICK)

   {

      string clickedChartObject=sparam;

      if (clickedChartObject==prefix +"kn MM")

      {

         if (ObjectGetInteger(0,prefix +"kn MarketInfo",OBJPROP_STATE))

         {

            Del();

            RectLabelCreate(0,prefix ,0,X,Y,300,105,Color1,txtcolor,STYLE_SOLID,3,false,true,true,0);

            ObjectSetInteger(0,prefix +"kn MarketInfo",OBJPROP_STATE,false);

         }

         if (!ObjectGetInteger(0,prefix +"kn MM",OBJPROP_STATE))

         {

            if (ObjectFind(prefix +"risk1")==0) Del();

            RectLabelCreate(0,prefix ,0,X,Y,300,105,Color1,txtcolor,STYLE_SOLID,3,false,true,true,0);

         }

      }

      if (clickedChartObject==prefix +"kn MarketInfo")

      {

         if (ObjectGetInteger(0,prefix +"kn MM",OBJPROP_STATE))

         {

            if (ObjectFind(prefix +"risk1")==0) Del();

            RectLabelCreate(0,prefix ,0,X,Y,300,105,Color1,txtcolor,STYLE_SOLID,3,false,true,true,0);

            ObjectSetInteger(0,prefix +"kn MM",OBJPROP_STATE,false);

         }

         if (!ObjectGetInteger(0,prefix +"kn MarketInfo",OBJPROP_STATE))

         {

            Del();

            RectLabelCreate(0,prefix ,0,X,Y,300,105,Color1,txtcolor,STYLE_SOLID,3,false,true,true,0);

         }

      }

      Redraw();

   }

}

//============ >;CG8< 40==K5 AB@>:8 87 <0AA820 ?> MArketInfo ======= 

string GetMarketInfoTxt(int number)

{

     switch(number)

        {

         case 0  : return(!isRussianLang? "SPREAD: "     : "! : ");                break;

         case 1  : return(!isRussianLang? "STOP_LEVEL: " : "# , !": ");       break;

         case 2  : return(!isRussianLang? "TICK_VALUE: " : "!"!", #": ");     break;

         case 3  : return(!isRussianLang? "TICK_SIZE: "  : "   ": ");          break;

         case 4  : return(!isRussianLang? "SWAP_LONG: "  : "! / #: ");     break;

         case 5  : return(!isRussianLang? "SWAP_SHORT: " : "! /  : ");      break;

         case 6  : return(!isRussianLang? "MIN_LOT: "    : ",+ ": ");      break;

         case 7  : return(!isRussianLang? "LOT_STEP: "   : "( / ": ");   break;

         case 8  : return(!isRussianLang? "MAX_LOT: "    : "!,+ ": ");     break;

         case 9  : return(!isRussianLang? "MARGIN_REQUIRED: " : "  1 ": ");  break;

        }

    return("");

}

//==== 5@54048< 7=0G5=8O 2 AB@>:C 87 <0AA820 MarketInfo =====

string GetMarketInfoValue(int number)

{

   string value;

     switch(number)

        {

         case 0  : value = DoubleToString(MarketInfo(Symbol(), MODE_SPREAD),0);         break;

         case 1  : value = DoubleToString(stoplvl,0);                                   break;

         case 2  : value = DoubleToString(tickvalue,2);                                 break;

         case 3  : value = DoubleToString(ticksize,Digits);  break;

         case 4  : value = DoubleToString(MarketInfo(Symbol(), MODE_SWAPLONG),2);       break;

         case 5  : value = DoubleToString(MarketInfo(Symbol(), MODE_SWAPSHORT),2);      break;

         case 6  : value = DoubleToString(minlot,2);                                    break;

         case 7  : value = DoubleToString(lotstep,2);                                   break;

         case 8  : value = DoubleToString(maxlot,0);                                    break;

         case 9  : value = DoubleToString(marga,2);                                     break;

        }

  return value;

}

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

//| ">1@078< ;591;K 0@:5B=DK                                                         |

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

void ShowMarketInfo()

{

   long y_property = Y+115;

   int  y_prop_array[marketinfo_size]={0};



      RectLabelCreate(0,prefix ,0,X,Y,300,310,Color1,txtcolor,STYLE_SOLID,3,false,true,true,0);

      RectLabelCreate(0,prefix +"fon1",0,X+1  ,Y+1 ,298,308,FonColor,Color4,STYLE_SOLID,1,false,false,true,0);

      

//--- 0?>;=8< <0AA82 :>>@48=0B0<8 4;O :064>9 AB@>:8 =0 8=D>@<0F8>==>9 ?0=5;8

   for(int i=0; i<marketinfo_size; i++)

     {

      if(i==0) 

          y_prop_array[i] = (int)y_property;

      else     

          y_prop_array[i] = (int)y_property+20*i;

     LabelCreate(0,prefix + lable_name[i],0,X+10,y_prop_array[i],CORNER_LEFT_UPPER,GetMarketInfoTxt(i),txtfont, txtsize,txtcolor,0,ANCHOR_LEFT,false,false,true,0);

     LabelCreate(0,prefix +lable_value[i],0,X+200,y_prop_array[i],CORNER_LEFT_UPPER,GetMarketInfoValue(i),txtfont, txtsize,txtcolor,0,ANCHOR_LEFT,false,false,true,0);

     }

}

// ==== >;CG8< 87 <0AA820 AB@>: RiskManagment AB@>:8 0720=89 

string GetRiskTxt(int number)

{

    switch(number)

     {

      case 0 : return(isRussianLang? StringConcatenate("0;0=A AG5B0, ", AC)  :

                                     StringConcatenate("Account balance, ", AC));           break;

      case 1 : return(isRussianLang? StringConcatenate("!2>1>4=K5 A@54AB20, ", AC) :

                                     StringConcatenate("Free margin, ", AC));               break;                          

      case 2 : if(stoploss ==0)

                  return(isRussianLang? "0:A. >B ?> @8A:C" : "Max Lot by risk");

               else

                  return(isRussianLang? "Ma:A. >B ?> !B>?;>AAC" : "Max Lot By Stoploss");  break;

                

      case 3 : return(isRussianLang? "!59G0A >B 2 @K=:5"    : "Current Lot in market");    break;

      case 4 : return(isRussianLang? ">ABC?=> >B ?> @8A:C" : "Available Lot by risk");    break;

      case 5 : return(isRussianLang? "@>A04:0 AG5B0, %"     : "Account DrawDown, %");      break;

     }

   return("");

}

// ==== @54AB028< 2 AB@>:5 7=0G5=8O Risk Managment =======

string GetRiskValue(int number)

{

     switch(number)

       {

        case 0 : return(DoubleToString(balance,2));    break;

        case 1 : return(DoubleToString(free,2));       break;

        case 2 : return(DoubleToString(GetLots(),2));  break;

        case 3 : return(DoubleToString(totallot,2));   break;

        case 4 : return(DoubleToString(freelots,2));   break;

        case 5 : return(DoubleToString(DrawDown(),2)); break;

       }

     return("");

}

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

//|  0AG5B 8 >B>1@065=85 Risk Managment                                                 |

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

void CalcAndShowRM()

{

   color col=clrNONE, cvet=clrNONE;

   totallot     = 0.0;

   totalprofit  = 0.0;

   pros         = DrawDown();

   

   string lable1, lable2, lable3;

        lable1   = isRussianLang? "  +(   !!!!" : "DON'T  EXCEED  RISK!!!";

        lable2   = isRussianLang? "!B>?>AA, ??" : "StopLoss, pt:";

        lable3   = isRussianLang? " 8A::" : "Risk:";

    long y = Y+155;

    int  y_array[risk_size]={0};

//----- 

  for (int i=0; i<OrdersTotal(); i++)

   if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))

    { 

     if(OrderType() == OP_BUY || OrderType() == OP_SELL) 

      totallot += OrderLots();

       {

         if (OrderSymbol()==Symbol())

         totalprofit  += OrderProfit() + OrderCommission() + OrderSwap();;

       }

     }

    freelots    =  GetLots() - totallot;

    if(freelots < 0) freelots = 0.0;



//-----

    RectLabelCreate(0,prefix ,0,X,Y,300,290,Color1,txtcolor,STYLE_SOLID,3,false,true,true,0);

    RectLabelCreate(0,prefix +"fon1",0,X+1  ,Y+1 ,298,288,FonColor,Color4,STYLE_SOLID,1,false,false,true,0);

//StopLoss

    LabelCreate(0,prefix +"stoploss",0 ,X+15,Y+114,CORNER_LEFT_UPPER,lable2,txtfont,txtsize+1,txtcolor,0,ANCHOR_LEFT,false,false,true,0);

    EditCreate(0,prefix +"stoploss1" ,0, X+105,Y+105,50,18, IntegerToString(stoploss,0),txtfont,txtsize+1,ALIGN_CENTER,false,CORNER_LEFT_UPPER); 

//CanToRisk(PercentOfFreeMargin)

    LabelCreate(0,prefix +"risk",0 ,X+175,Y+114,CORNER_LEFT_UPPER,lable3,txtfont,txtsize+1,txtcolor,0,ANCHOR_LEFT,false,false,true,0);

    EditCreate(0,prefix +"risk1" ,0, X+215,Y+105,50,18,DoubleToStr(0.01,2),txtfont,txtsize+1,ALIGN_CENTER,false,CORNER_LEFT_UPPER); 

    LabelCreate(0,prefix +"risk2",0 ,X+269,Y+114,CORNER_LEFT_UPPER,"%",txtfont,txtsize+1,txtcolor,0,ANCHOR_LEFT,false,false,true,0);

    LabelCreate(0,prefix +"alert" ,0 ,X+150,Y+135,CORNER_LEFT_UPPER,lable1,txtfont, txtsize+2,txtcolor,0,ANCHOR_CENTER,false,false,true,0);

    

    for(int j=0; j<risk_size; j++)

     {

      if(j==0) 

          y_array[j] = (int)y;

      else     

          y_array[j] = (int)y+20*j;

       LabelCreate(0,prefix + lable_name1[j],0 ,X+15,y_array[j],CORNER_LEFT_UPPER,GetRiskTxt(j),txtfont, txtsize+1,txtcolor,0,ANCHOR_LEFT,false,false,true,0);

       LabelCreate(0,prefix + lable_value1[j],0,X+260,y_array[j],CORNER_LEFT_UPPER,GetRiskValue(j),txtfont, txtsize+1,txtcolor,0,ANCHOR_CENTER,false,false,true,0);

    }

//========  0A:@0A8< >1J5:BK ?> CA;>28O< =====

//  ?@>A04:5

      if(pros < 0) col = clrGreen;

      if(pros > 0 && pros < 30) col = clrYellowGreen;

      if(pros > 30 && pros < 50) col = clrOrangeRed;

      if(pros > 50) col = clrCrimson;

        ObjectSetInteger(0,prefix +"v_curdrawdn",OBJPROP_COLOR, col);

        ObjectSetInteger(0,prefix +"v_freemargin",OBJPROP_COLOR, col);

// > ;>B=>AB8       

     if(totallot < GetLots()) cvet = clrMediumSeaGreen; else  cvet = clrTomato;

      ObjectSetInteger(0,prefix +"v_risklot",OBJPROP_COLOR, cvet);

      ObjectSetInteger(0,prefix +"v_reallot",OBJPROP_COLOR, cvet);

      ObjectSetInteger(0,prefix +"v_freelot",OBJPROP_COLOR, cvet);

      ObjectSetInteger(0,prefix +"alert",OBJPROP_COLOR, cvet);

      

}

//--------------------------------------------------------------------

void Redraw()

{

   string but1, but2, but3,lable0;

//---------------------------------   

        but1 = isRussianLang? "5=5465@ @8A:>2" : "Risk Manager";

        but2 = isRussianLang? " K=>G=0O 8=D>@<0F8O" : "Market Info";

        but3 = isRussianLang? "@45@0 =0 3@0D8:5" : "Orders on Chart";

        lable0 = isRussianLang? StringConcatenate("!C<<0@=> ?>   ", Symbol()) :

                                StringConcatenate(Symbol(), "      Summary");

//----------------------------------       

   if (ObjectFind(prefix)==0)

     {

      ObjectGetInteger(0,prefix+"",OBJPROP_XDISTANCE,0,X);

      ObjectGetInteger(0,prefix+"",OBJPROP_YDISTANCE,0,Y);

     }

   else

     {

      RectLabelCreate(0,prefix ,0,X,Y,300,105,Color1,txtcolor,STYLE_SOLID,3,false,true,true,0);

     }

   RectLabelCreate(0,prefix +"fon1",0,X+1  ,Y+1 ,298,103,FonColor,Color4,STYLE_SOLID,1,false,false,true,0);

   ButtonCreate(0   ,prefix +"kn Orders Line"  ,0,X+5  ,Y+27,114,30 ,but3,txtfont,txtsize,txtcolor,Color5,Color4,false);

   RectLabelCreate(0,prefix +"0_" ,0 ,X+1,Y+1,90,20,Color2,Color4,STYLE_SOLID,1,false,false,true,0);

   RectLabelCreate(0,prefix +"9_" ,0 ,X+198,Y+1,100,20,Color2,Color4,STYLE_SOLID,1,false,false,true,0);

   RectLabelCreate(0,prefix +"09_" ,0 ,X+91,Y+1,107,20,Color2,Color4,STYLE_SOLID,1,false,false,true,0);

   

   LabelCreate(0,prefix +"sym",0 ,X+45,Y+11,CORNER_LEFT_UPPER,Symbol(),txtfont,txtsize+4,Color1,0,ANCHOR_CENTER,false,false,true,0);

   LabelCreate(0,prefix +"ATR",0 ,X+145,Y+11,CORNER_LEFT_UPPER,StringConcatenate("ATR: ", DoubleToStr(volatility(),0)),txtfont,txtsize+4,Color1,0,ANCHOR_CENTER,false,false,true,0);

   LabelCreate(0,prefix +"Timer",0 ,X+255,Y+11,CORNER_LEFT_UPPER,StringConcatenate(CandlesTimer()),txtfont,txtsize+4,Color1,0,ANCHOR_CENTER,false,false,true,0);



   double OOP;

   double stoplevel=stoplvl*Point;

   int b=0,s=0,bs=0,ss=0,bl=0,sl=0,tip;

   double OL,LB=0,LS=0,ProfitB=0,ProfitS=0, Profit=0;

   double price_b=0,price_s=0;

   int i,Ticket;string NameLine;datetime OOT;

   color cvetPR=clrNONE,cvetPS = clrNONE, cvetPB = clrNONE;

   bool ViewOrdersLine=ObjectGetInteger(0,prefix +"kn Orders Line",OBJPROP_STATE);

   

   for (i=0; i<OrdersTotal(); i++)

   {    

      if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))

      { 

         if (OrderSymbol()==Symbol())

         { 

            OOP = NormalizeDouble(OrderOpenPrice(),Digits);

            OOT = OrderOpenTime();

            Ticket=OrderTicket();

            tip = OrderType(); 

            OL = OrderLots();

            if (tip==OP_BUY)             

            {  

               b++; 

               LB+=OL;price_b+=(Bid-OOP)*OL+(OrderCommission()+OrderSwap())*Point;

               ProfitB+=OrderProfit()+OrderCommission()+OrderSwap();

               if (ViewOrdersLine)

               {

                  NameLine=StringConcatenate("Buy, Lot ",DoubleToStr(OL,2),"  Ticket ",DoubleToStr(Ticket,0));

                  ObjectDelete(NameLine);

                  ObjectCreate(NameLine,OBJ_TREND,0,OOT,OOP,Time[0],Bid);

                  ObjectSetInteger(0,NameLine, OBJPROP_COLOR,Color2); 

               }

            }

            if (tip==OP_SELL) 

            {

               s++;

               LS+=OL;price_s+=(OOP-Ask)*OL+(OrderCommission()+OrderSwap())*Point;

               ProfitS+=OrderProfit()+OrderCommission()+OrderSwap();

               if (ViewOrdersLine)

               {

                  NameLine=StringConcatenate("Sell, Lot ",DoubleToStr(OL,2),"  Ticket ",DoubleToStr(Ticket,0));

                  ObjectDelete(NameLine);

                  ObjectCreate(NameLine,OBJ_TREND,0,OOT,OOP,Time[0],Ask);

                  ObjectSetInteger(0,NameLine, OBJPROP_COLOR,Color3);

               }

            }

             Profit = ProfitB + ProfitS;

            if (ViewOrdersLine)

            {

               ObjectSetInteger(0,NameLine, OBJPROP_STYLE, STYLE_DOT);

               ObjectSetInteger(0,NameLine, OBJPROP_RAY,   false);

               ObjectSetInteger(0,NameLine,OBJPROP_SELECTABLE,false);

               ObjectSetInteger(0,NameLine,OBJPROP_SELECTED,false);

               ObjectSetInteger(0,NameLine,OBJPROP_HIDDEN,true);

            }

         }

      }

   }

//----

   if(Profit >=0) cvetPR = clrGreen;   else   cvetPR = clrRed;

   if(ProfitS >=0) cvetPS = clrGreen;  else   cvetPS = clrRed;

   if(ProfitB >=0) cvetPB = clrGreen;  else   cvetPB = clrRed;

   

   RectLabelCreate(0,prefix +"1_" ,0 ,X+121,Y+22,58,18,Color1,Color4,STYLE_SOLID,1,false,false,true,0);

   RectLabelCreate(0,prefix +"2_" ,0 ,X+180,Y+22,48,18,Color1,Color4,STYLE_SOLID,1,false,false,true,0);

   RectLabelCreate(0,prefix +"02_" ,0 ,X+229,Y+22,69,18,Color1,Color4,STYLE_SOLID,1,false,false,true,0);

   LabelCreate(0,prefix +"BuyCnt" ,0 ,X+146,Y+30,CORNER_LEFT_UPPER,StringConcatenate("Buy ",DoubleToStr(b,0)),txtfont,txtsize+0,txtcolor,0,ANCHOR_CENTER,false,false,true,0);

   LabelCreate(0,prefix +"BuyLots"  ,0 ,X+202,Y+30,CORNER_LEFT_UPPER,DoubleToStr(LB,2),txtfont,txtsize+0,txtcolor,0,ANCHOR_CENTER,false,false,true,0);

   LabelCreate(0,prefix +"BuyProfit"  ,0 ,X+265,Y+30,CORNER_LEFT_UPPER,DoubleToStr(ProfitB,2),txtfont,txtsize+0,cvetPB,0,ANCHOR_CENTER,false,false,true,0);



   RectLabelCreate(0,prefix +"3_" ,0 ,X+121,Y+42,58,18,Color1,Color4,STYLE_SOLID,1,false,false,true,0);

   RectLabelCreate(0,prefix +"4_" ,0 ,X+180,Y+42,48,18,Color1,Color4,STYLE_SOLID,1,false,false,true,0);

   RectLabelCreate(0,prefix +"04_" ,0 ,X+229,Y+42,69,18,Color1,Color4,STYLE_SOLID,1,false,false,true,0);

   LabelCreate(0    ,prefix +"SellCnt",0 ,X+146,Y+50,CORNER_LEFT_UPPER,StringConcatenate("Sell ",DoubleToStr(s,0)),txtfont,txtsize+0,txtcolor,0,ANCHOR_CENTER,false,false,true,0);

   LabelCreate(0    ,prefix +"SellLots"  ,0 ,X+202,Y+50,CORNER_LEFT_UPPER,DoubleToStr(LS,2),txtfont,txtsize+0,txtcolor,0,ANCHOR_CENTER,false,false,true,0);

   LabelCreate(0    ,prefix +"SellProfit"  ,0 ,X+265,Y+50,CORNER_LEFT_UPPER,DoubleToStr(ProfitS,2),txtfont,txtsize+0,cvetPS,0,ANCHOR_CENTER,false,false,true,0);

   if(!ViewOrdersLine) ObjectsDeleteAll(0,OBJ_TREND);

//---

   RectLabelCreate(0,prefix +"20_" ,0 ,X+5,Y+62,174,18,Color1,Color4,STYLE_SOLID,1,false,false,true,0);

   LabelCreate(0    ,prefix +"Summ"  ,0 ,X+95,Y+70,CORNER_LEFT_UPPER,lable0,txtfont,txtsize+0,txtcolor,0,ANCHOR_CENTER,false,false,true,0);

   RectLabelCreate(0,prefix +"23_" ,0 ,X+180,Y+62,48,18,Color1,Color4,STYLE_SOLID,1,false,false,true,0);

   LabelCreate(0    ,prefix +"SumLots"  ,0 ,X+202,Y+71,CORNER_LEFT_UPPER,DoubleToStr((LS+LB),2),txtfont,txtsize+0,txtcolor,0,ANCHOR_CENTER,false,false,true,0);

   RectLabelCreate(0,prefix +"044_" ,0 ,X+229,Y+62,69,18,Color1,Color4,STYLE_SOLID,1,false,false,true,0);

   LabelCreate(0    ,prefix +"SummProfit"  ,0 ,X+265,Y+71,CORNER_LEFT_UPPER,DoubleToStr(Profit,2),txtfont,txtsize,cvetPR,0,ANCHOR_CENTER,false,false,true,0);

   ButtonCreate(0,prefix +"kn MM" ,0,X+5  ,Y+81,140,20 , but1,txtfont,txtsize,txtcolor,Color5,Color4,false);

   ButtonCreate(0,prefix +"kn MarketInfo"   ,0,X+155 ,Y+81,140,20 ,but2,txtfont,txtsize,txtcolor,Color5,Color4,false);

//----------------------------------------  

   if (ObjectGetInteger(0,prefix +"kn MM",OBJPROP_STATE))

   {

     CalcAndShowRM();

     ChartRedraw();

   }

//-----------------------------

   if (ObjectGetInteger(0,prefix +"kn MarketInfo",OBJPROP_STATE))

   {

   ShowMarketInfo();

   ChartRedraw();

   }

}

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

//|  0AG5B 0:A >B0 AE>4O 87 A2>1>4=KE A@54AB2 8;8 ;>B0 ?@8 AB>?0E                     |

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

double GetLots()

{

  stoploss = (int)StringToInteger(ObjectGetString(0,prefix +"stoploss1",OBJPROP_TEXT));

 //----------- @0AG5B ;>B0 A 8A?>;L7>20=85< AB>?-;>A0 ------------------

  if(tickvalue ==0 ||lotstep == 0)

     return(0);

  if(stoploss != 0)

     Lot =  (free*GetRisk()/100)/(stoploss*tickvalue);

  else

     Lot = free*GetRisk()/100/marga;

  

   return(Lot);                      

}

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

//| >;CG8< 40==K5 > @8A:5                                                              |

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

double GetRisk()

{

   risk = StringToDouble(ObjectGetString(0,prefix +"risk1",OBJPROP_TEXT));

   if(risk >100.0) risk = 100.0;

   ObjectSetString(0,prefix +"risk1",OBJPROP_TEXT,DoubleToString(risk,2));

   

   return(risk);

}

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

//| @5<O  >:>=G0=8O A25G8                                                              |

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

string CandlesTimer()

{

   int min = (int)Time[0] + 60 * Period() - (int)TimeCurrent();

   int sec = min % 60;

   int hour = (min - sec) / 3600;

   min = (min - sec) / 60 - hour*60;

   string timetoback = StringConcatenate(IntegerToString(hour,2,'0'), 

                       ":", IntegerToString(min,2,'0'), ":", IntegerToString(sec,2,'0'));

   return(timetoback);

}

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

//|  0AG5B ?@>A04:8                                                                     |

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

double DrawDown()

{

   if(balance == 0)

    return(0);

    

   return((balance - free)/balance*100);

}

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

//| KG8A;8< 2>;0B8;L=>ABL                                                              |

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

double volatility()

{

   double s = 0.0;

   for(int i = 1; i <= BarsCount; i++)

     {

      s += (High[i]-Low[i])/Point;

     }

   return(s/BarsCount);

}

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

//| !>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 long               x=0,                     // :>>@48=0B0 ?> >A8 X

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

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

                  const int               height=18,                // 2KA>B0 :=>?: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=clrNONE,      //F25B B5:AB0

                  const color             clrON=clrNONE,    //F25B D>=0

                  const color             clrOFF=clrNONE,   //F25B D>=0

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

  {

   if (ObjectFind(chart_ID,name)==-1)

   {

      ObjectCreate(chart_ID,name,OBJ_BUTTON,sub_window,0,0);

      ObjectSetInteger(chart_ID,name,OBJPROP_XSIZE,width);

      ObjectSetInteger(chart_ID,name,OBJPROP_YSIZE,height);

      ObjectSetInteger(chart_ID,name,OBJPROP_CORNER,CORNER_LEFT_UPPER);

      ObjectSetString(chart_ID,name,OBJPROP_FONT,font);

      ObjectSetInteger(chart_ID,name,OBJPROP_FONTSIZE,font_size);

      ObjectSetInteger(chart_ID,name,OBJPROP_BACK,0);

      ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,0);

      ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,0);

      ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,1);

      ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,0);

      ObjectSetInteger(chart_ID,name,OBJPROP_STATE,state);

      ObjectSetInteger(chart_ID,name,OBJPROP_BORDER_COLOR,clrNONE);

   }

   color back_clr;

   if (ObjectGetInteger(chart_ID,name,OBJPROP_STATE)) back_clr=clrON; else back_clr=clrOFF;

   ObjectSetInteger(chart_ID,name,OBJPROP_BGCOLOR,back_clr);

   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);

   ObjectSetString(chart_ID,name,OBJPROP_TEXT,text);

   ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,x);

   ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,y);

   return(true);

}

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

//| !>7405B ?@O<>C3>;L=CN <5B:C                                      | 

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

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

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

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

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

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

                     const int              width=50,                 // H8@8=0

                     const int              height=18,                // 2KA>B0

                     const color            back_clr=clrNONE,         // F25B D>=0

                     const color            clr=clrNONE,              //F25B ?;>A:>9 3@0=8FK (Flat)

                     const ENUM_LINE_STYLE  style=STYLE_SOLID,        // AB8;L ?;>A:>9 3@0=8FK

                     const int              line_width=1,             // B>;I8=0 ?;>A:>9 3@0=8FK

                     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

  {

   ResetLastError();

   if (ObjectFind(chart_ID,name)==-1)

   {

      ObjectCreate(chart_ID,name,OBJ_RECTANGLE_LABEL,sub_window,0,0);

      ObjectSetInteger(chart_ID,name,OBJPROP_BORDER_TYPE,BORDER_FLAT);

      ObjectSetInteger(chart_ID,name,OBJPROP_CORNER,CORNER_LEFT_UPPER);

      ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style);

      ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,line_width);

      ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);

      ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);

      ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);

      ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);

      ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);

   }

   ObjectSetInteger(chart_ID,name,OBJPROP_BGCOLOR,back_clr);

   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);

   ObjectSetInteger(chart_ID,name,OBJPROP_XSIZE,width);

   ObjectSetInteger(chart_ID,name,OBJPROP_YSIZE,height);

   ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,x);

   ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,y);

   return(true);

}

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

//| !>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 long              x=0,                      // :>>@48=0B0 ?> >A8 X

                 const long              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=clrNONE,      

                 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

{

   ResetLastError();

   if (ObjectFind(chart_ID,name)==-1)

   {

      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);

      }

      ObjectSetInteger(chart_ID,name,OBJPROP_CORNER,corner);

      ObjectSetString(chart_ID,name,OBJPROP_FONT,font);

      ObjectSetInteger(chart_ID,name,OBJPROP_FONTSIZE,font_size);

      ObjectSetDouble(chart_ID,name,OBJPROP_ANGLE,angle);

      ObjectSetInteger(chart_ID,name,OBJPROP_ANCHOR,anchor);

      ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);

      ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);

      ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);

      ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);

      ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);

   }

   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);

   ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,x);

   ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,y);

   ObjectSetString(chart_ID,name,OBJPROP_TEXT,text);

   return(true);

}

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

//| !>7405B >1J5:B ">;5 22>40"                                      | 

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

bool EditCreate(const long             chart_ID=0,

                const string           name="Edit", 

                const int              sub_window=0, 

                const long              x=0,     

                const long              y=0,          

                const int              width=50,       

                const int              height=18,  

                const string           text="Text",  

                const string           font="Arial",

                const int              font_size=10,     

                const ENUM_ALIGN_MODE  align=ALIGN_CENTER,

                const bool             read_only=true,     

                const ENUM_BASE_CORNER corner=CORNER_LEFT_LOWER,

                const color            clr=clrBlack,  

                const color            back_clr=clrWhite, 

                const color            border_clr=clrNONE,

                const bool             back=false,   

                const bool             selection=false, 

                const bool             hidden=true,  

                const long             z_order=0) 

{

  ResetLastError(); 

  if (ObjectFind(chart_ID,name)==-1)

   {

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

     { 

      return(false); 

     } 

      ObjectSetInteger(chart_ID,name,OBJPROP_XSIZE,width); 

      ObjectSetInteger(chart_ID,name,OBJPROP_YSIZE,height);

      ObjectSetString(chart_ID,name,OBJPROP_TEXT,text); 

      ObjectSetString(chart_ID,name,OBJPROP_FONT,font); 

      ObjectSetInteger(chart_ID,name,OBJPROP_FONTSIZE,font_size);   

      ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr); 

      ObjectSetInteger(chart_ID,name,OBJPROP_ALIGN,align); 

      ObjectSetInteger(chart_ID,name,OBJPROP_READONLY,read_only); 

      ObjectSetInteger(chart_ID,name,OBJPROP_CORNER,corner); 

      ObjectSetInteger(chart_ID,name,OBJPROP_BGCOLOR,back_clr); 

      ObjectSetInteger(chart_ID,name,OBJPROP_BORDER_COLOR,border_clr); 

      ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back); 

      ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection); 

      ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection); 

      ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden); 

      ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order); 

    }

   ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,x); 

   ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,y); 



   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 ---