/*
   Generated by ex4-to-mq4 decompiler FREEWARE 4.0.451.7
   Website:  ht T p:/ /w W W. meT AqU o t E S . N E T
   E-mail :  S u P pORT@m eT A q UOtES .N et
*/
#property copyright "Copyright © 2011, AZM."
#property link      ""

#property indicator_chart_window

extern int Loss = 50;
extern double Percent = 1.0;


extern color Color = Navy;
extern int размер_шрифта = 5;
extern int угол = 0;
extern int горизонтальное_положение = 5;
extern int вертикальное_положение = 45;

string Gs_calc_112 = "Calc";
int calk_incr=1;


int Gi_136;
double G_digits_140;
double Gd_148;
double Gd_156;
double Gd_164;
string G_text_172;
double G_tickvalue_180;

// E37F0136AA3FFAF149B351F6A4C948E9
int init() {
   G_digits_140 = MarketInfo(Symbol(), MODE_DIGITS);
   if (G_digits_140 == 5.0 || G_digits_140 == 3.0) Gi_136 = 10;
   if (G_digits_140 == 4.0 || G_digits_140 == 2.0) Gi_136 = 1;
   Print("");
   return (0);
}

// 52D46093050F38C27267BCE42543EF60
int deinit() {
for(int i=1;i<=100;i++)
{
   ObjectDelete(Gs_calc_112+i);
 
  } 
   
   
   ObjectDelete("logo");
   ObjectDelete("Loss");
   
   return (0);
}

// EA2B2676C28C0DB26D39331A336C6B92
int start() {
   string Ls_4;
   string Ls_12;
   string Ls_20;
   int y_0 = 15;
   int Li_28 = размер_шрифта + 10;
   double tickvalue_32 = MarketInfo(Symbol(), MODE_TICKVALUE);
   if (tickvalue_32 != G_tickvalue_180) {
      G_tickvalue_180 = tickvalue_32;
      if (ObjectFind("logo") == -1) {
         ObjectCreate("logo", OBJ_LABEL, 0, 0, 0);
         ObjectSet("logo", OBJPROP_CORNER, угол);
         ObjectSet("logo", OBJPROP_XDISTANCE, 5);
         ObjectSet("logo", OBJPROP_YDISTANCE, вертикальное_положение+y_0);
      }
      ObjectSetText("logo", "", размер_шрифта, "Arial", MediumBlue);
      y_0 += Li_28;
      if (Percent != 0.0) {
         Gd_148 = f0_0(Gi_136 * Loss, Percent);
         Gd_156 = Gi_136 * Gd_148 * tickvalue_32;
         Gd_164 = Gd_156 * Loss;
         if (Percent < 10.0) Ls_4 = "% 0" + DoubleToStr(Percent, 2);
         else Ls_4 = "% " + DoubleToStr(Percent, 2);
         if (Gd_148 < 10.0) Ls_12 = "  Lot 0" + DoubleToStr(Gd_148, 2);
         else Ls_12 = "  Lot " + DoubleToStr(Gd_148, 2);
         if (Gd_156 < 10.0) Ls_20 = "  | 1пункт= 0" + DoubleToStr(Gd_156, 2);
         else Ls_20 = "  | 1пункт= " + DoubleToStr(Gd_156, 2);
         G_text_172 = Ls_4 + Ls_12 + Ls_20 + "  | лосс -" + DoubleToStr(Gd_164, 2);
         if (ObjectFind(Gs_calc_112+calk_incr) == -1) {
            ObjectCreate(Gs_calc_112+calk_incr, OBJ_LABEL, 0, 0, 0);
            ObjectSet(Gs_calc_112+calk_incr, OBJPROP_CORNER, угол);
            ObjectSet(Gs_calc_112+calk_incr, OBJPROP_XDISTANCE, горизонтальное_положение);
            ObjectSet(Gs_calc_112+calk_incr, OBJPROP_YDISTANCE, вертикальное_положение+y_0);
         }
         ObjectSetText(Gs_calc_112+calk_incr, G_text_172, размер_шрифта, "MS Sans Serif", Color);
         y_0 += Li_28;
      }
         
         
         ////////////////////////
         /////////////////////////
      
          ////////////////////////
         /////////////////////////
         /////////////////////////
      
      
      if (ObjectFind("loss") == -1) {
         ObjectCreate("loss", OBJ_LABEL, 0, 0, 0);
         ObjectSet("loss", OBJPROP_CORNER, угол);
         ObjectSet("loss", OBJPROP_XDISTANCE, горизонтальное_положение);
         ObjectSet("loss", OBJPROP_YDISTANCE, вертикальное_положение+y_0);
      }
      ObjectSetText("loss", "стоп лосс = " + Loss + " пунктов", размер_шрифта, "MS Sans Serif", Color);
      y_0 = 15;
   }
   return (0);
}

// 6CB3E39E26CE3772478B75336C46C4E7
double f0_0(int Ai_0, double Ad_4) {
   double Ld_12 = AccountBalance();
   double tickvalue_20 = MarketInfo(Symbol(), MODE_TICKVALUE);
   double Ld_28 = MarketInfo(Symbol(), MODE_MINLOT);
   double Ld_36 = MarketInfo(Symbol(), MODE_MAXLOT);
   double lotstep_44 = MarketInfo(Symbol(), MODE_LOTSTEP);
   double Ld_ret_52 = MathFloor(Ld_12 * Ad_4 / 100.0 / (Ai_0 * tickvalue_20) / lotstep_44) * lotstep_44;
   if (Ld_ret_52 < Ld_28) Ld_ret_52 = Ld_28;
   if (Ld_ret_52 > Ld_36) Ld_ret_52 = Ld_36;
   return (Ld_ret_52);
}