/*
   Generated by EX4-TO-MQ4 decompiler V4.0.224.1 []
   Website: http://purebeam.biz
   E-mail : purebeam@gmail.com
*/
#property copyright "Copyright © 2006-2009, Sergey Kravchuk. http://forextools.com.ua"
#property link      "http://forextools.com.ua"

#property indicator_chart_window

#include <WinUser32.mqh>

#import "user32.dll"
   int GetDC(int a0);
   int ReleaseDC(int a0, int a1);
#import "gdi32.dll"
   int GetPixel(int a0, int a1, int a2);
#import

int gi_76;
int g_window_80 = 0;
int g_corner_84 = 1;
int g_count_88;
int gi_unused_92 = -1;
string g_fontname_96 = "FOREXTOOLS";
int gi_104 = 8421504;
int g_fontsize_108 = 8;
int gi_112 = 13;
int gi_116 = 1;
int gi_120 = 1;
int gi_124 = 1;
int gi_128 = 1;
int gi_132;
int g_x_136;
extern string §1 = "VISIBILITY.........................................................";
extern bool ShowInfoLeft = FALSE;
extern bool ShowSymbolOrdersOnly = FALSE;
extern int MaxClosedOrdersCnt = 3;
extern bool ShowStopLevelMarks = TRUE;
bool gi_unused_164 = FALSE;
extern string §2 = "TRADE CONTROL......................................................";
extern int RiskPercent = 2;
extern int FillPercent = 50;
extern int StopTradePercent = 100;
extern int Slippage = 3;
extern string §3 = "ORDERS INFO CONTROL.......................................................";
extern string OrdersInfoFormat = "9@DURATION @SYMBOL @TYPE @LOT @PROFIT";
extern color ColorProfitOrder = ForestGreen;
extern color ColorZeroProfitOrder = Fuchsia;
extern color ColorLossOrder = Crimson;
extern color ColorPendingOrder = LightSlateGray;
extern color ColorClosedOrder = Peru;
extern color ColorInfoText = RoyalBlue;
extern string §4 = "ORDER BOX COLORS...................................................";
extern color ColorBuyOrderBox = SkyBlue;
extern color ColorBuyStopsBox = RoyalBlue;
extern color ColorSellOrderBox = Wheat;
extern color ColorSellStopsBox = SandyBrown;
extern color ColorPendingBuyOrderBox = PaleTurquoise;
extern color ColorPendingBuyStopsBox = SkyBlue;
extern color ColorPendingSellOrderBox = PaleGoldenrod;
extern color ColorPendingSellStopsBox = NavajoWhite;
extern string §6 = "HISTORY MARK COLORS.................................................";
extern color ColorBuyArrows = Blue;
extern color ColorSellArrows = Red;
extern color ColorPendingArrows = LightSlateGray;
string gs_292;
string gs_300 = "FOREXTools";
string gs_308 = "FOREXTools Bold";
int gi_316 = 8;
int gi_320 = 13;
int gi_324;
string gs_328 = "_SelectedTicked";
string g_name_336 = "tmOrderBox";
string g_name_344 = "tmStopBox";
string g_name_352 = "# ";
string g_name_360 = "tm BUY LEVEL";
string g_name_368 = "tm SELL LEVEL";
string gsa_376[256];

int PutStr(string as_0, string as_8 = "", color a_color_16 = -1, color a_color_20 = -1) {
   string l_name_32;
   string l_text_48;
   if (g_window_80 < 0) g_window_80 = 0;
   if (a_color_16 == CLR_NONE) a_color_16 = gi_104;
   if (a_color_20 == CLR_NONE) a_color_20 = GetWindowBackgroundColor();
   int l_str_len_40 = StringLen(as_0);
   if (l_str_len_40 > 62) {
      as_0 = StringSubstr(as_0, 0, 62);
      l_str_len_40 = 62;
   }
   switch (g_corner_84) {
   case 0:
      gi_132 = gi_116;
      g_x_136 = gi_124;
      break;
   case 1:
      gi_132 = gi_116;
      g_x_136 = gi_128;
      break;
   case 2:
      gi_132 = gi_120;
      g_x_136 = gi_124;
      break;
   case 3:
      gi_132 = gi_120;
      g_x_136 = gi_128;
   }
   if (a_color_20 != CLR_NONE) {
      l_name_32 = "tmþ" + g_corner_84 + g_count_88 + "-{" + as_8 + "}-";
      l_text_48 = "";
      for (int l_count_56 = 0; l_count_56 < l_str_len_40; l_count_56++) l_text_48 = l_text_48 + "‰";
      if (ObjectFind(l_name_32) != -1) ObjectDelete(l_name_32);
      ObjectCreate(l_name_32, OBJ_LABEL, g_window_80, 0, 0);
      ObjectSet(l_name_32, OBJPROP_CORNER, g_corner_84);
      ObjectSet(l_name_32, OBJPROP_YDISTANCE, gi_132 + g_count_88 * gi_112);
      ObjectSet(l_name_32, OBJPROP_XDISTANCE, g_x_136);
      ObjectSetText(l_name_32, l_text_48, g_fontsize_108, g_fontname_96, a_color_20);
      ObjectSet(l_name_32, OBJPROP_BACK, FALSE);
   }
   string l_name_24 = "tmÿ" + g_corner_84 + g_count_88 + "-{" + as_8 + "}-";
   if (ObjectFind(l_name_24) != -1) ObjectDelete(l_name_24);
   ObjectCreate(l_name_24, OBJ_LABEL, g_window_80, 0, 0);
   ObjectSet(l_name_24, OBJPROP_CORNER, g_corner_84);
   ObjectSet(l_name_24, OBJPROP_YDISTANCE, g_count_88 * gi_112 + gi_132);
   ObjectSet(l_name_24, OBJPROP_XDISTANCE, g_x_136);
   ObjectSetText(l_name_24, as_0, g_fontsize_108, g_fontname_96, a_color_16);
   ObjectSet(l_name_24, OBJPROP_BACK, FALSE);
   g_count_88++;
   return (l_str_len_40);
}

void ClearFromLine(int ai_0, int ai_4) {
   int li_12;
   for (int li_8 = 0; li_8 < ObjectsTotal(); li_8++) {
      if (StringFind(ObjectName(li_8), "tmÿ" + ai_0) == 0 || StringFind(ObjectName(li_8), "tmþ" + ai_0) == 0) {
         li_12 = StringFind(ObjectName(li_8), "-{");
         if (li_12 >= 0) {
            if (StrToDouble(StringSubstr(ObjectName(li_8), 5, li_12 - 2)) >= ai_4) {
               ObjectDelete(ObjectName(li_8));
               li_8--;
            }
         }
      }
   }
   g_count_88 = ai_4;
}

string Format(string as_0, int a_ticket_8 = 0) {
   string ls_20;
   string ls_28;
   string l_year_36;
   string ls_44;
   string ls_52;
   string ls_60;
   string ls_unused_68;
   string ls_76;
   int l_day_of_week_84;
   int l_datetime_88;
   if (as_0 == "") return ("");
   string ls_12 = " " + as_0;
   if (a_ticket_8 != 0) OrderSelect(a_ticket_8, SELECT_BY_TICKET);
   int l_cmd_92 = OrderType();
   if (l_cmd_92 == OP_BUY) ls_76 = "/";
   else {
      if (l_cmd_92 == OP_SELL) ls_76 = "\\";
      else {
         if (l_cmd_92 == OP_BUYSTOP) ls_76 = "’";
         else {
            if (l_cmd_92 == OP_SELLSTOP) ls_76 = "‘";
            else {
               if (l_cmd_92 == OP_BUYLIMIT) ls_76 = "”";
               else {
                  if (l_cmd_92 == OP_SELLLIMIT) ls_76 = "“";
                  else ls_76 = "?";
               }
            }
         }
      }
   }
   if (l_cmd_92 == OP_BUYSTOP || l_cmd_92 == OP_SELLSTOP || l_cmd_92 == OP_BUYLIMIT || l_cmd_92 == OP_SELLLIMIT) l_datetime_88 = OrderExpiration();
   else {
      l_datetime_88 = OrderCloseTime();
      if (l_datetime_88 == 0) l_datetime_88 = OrderOpenTime();
   }
   if (l_datetime_88 == 0) ls_52 = "  ";
   else {
      ls_52 = TimeHour(l_datetime_88);
      if (TimeHour(l_datetime_88) <= 9) ls_52 = "0" + ls_52;
   }
   if (l_datetime_88 == 0) ls_60 = "  ";
   else {
      ls_60 = TimeMinute(l_datetime_88);
      if (TimeMinute(l_datetime_88) <= 9) ls_60 = "0" + ls_60;
   }
   if (l_datetime_88 == 0) l_day_of_week_84 = 0;
   else l_day_of_week_84 = TimeDayOfWeek(l_datetime_88);
   if (l_datetime_88 == 0) ls_20 = "  ";
   else {
      ls_20 = TimeDay(l_datetime_88);
      if (TimeDay(l_datetime_88) <= 9) ls_20 = "0" + ls_20;
   }
   if (l_datetime_88 == 0) ls_28 = "  ";
   else {
      ls_28 = TimeMonth(l_datetime_88);
      if (TimeMonth(l_datetime_88) <= 9) ls_28 = "0" + ls_28;
   }
   if (l_datetime_88 == 0) l_year_36 = "    ";
   else l_year_36 = TimeYear(l_datetime_88);
   if (l_datetime_88 == 0) ls_44 = "  ";
   else ls_44 = StringSubstr(l_year_36, 2);
   int l_digits_96 = MarketInfo(OrderSymbol(), MODE_DIGITS);
   Substitute(ls_12, "@PROFIT", DoubleToStr(OrderProfit(), 2));
   Substitute(ls_12, "@ACCCUR", AccountCurrency());
   Substitute(ls_12, "@SYMBOL", OrderSymbol());
   Substitute(ls_12, "@TICKET", OrderTicket());
   Substitute(ls_12, "@PRICE", DoubleToStr(OrderOpenPrice(), l_digits_96));
   Substitute(ls_12, "@TYPE", ls_76);
   Substitute(ls_12, "@LOT", DoubleToStr(OrderLots(), 2));
   Substitute(ls_12, "@TP", DoubleToStr(OrderTakeProfit(), l_digits_96));
   Substitute(ls_12, "@SL", DoubleToStr(OrderStopLoss(), l_digits_96));
   Substitute(ls_12, "@DURATION", Duration(l_datetime_88, TimeCurrent()));
   Substitute(ls_12, "@YYYY", l_year_36);
   Substitute(ls_12, "@YY", ls_44);
   Substitute(ls_12, "@MM", ls_28);
   Substitute(ls_12, "@DD", ls_20);
   Substitute(ls_12, "@hh", ls_52);
   Substitute(ls_12, "@mm", ls_60);
   return (StringSubstr(ls_12, 1));
}

void Substitute(string &as_0, string as_8, string as_16, string as_24 = " ") {
   int l_count_40;
   int li_48;
   string ls_52;
   string ls_60;
   string ls_68;
   int li_36 = StringFind(as_0, as_8);
   if (li_36 >= 0) {
      li_48 = 0;
      l_count_40 = 0;
      if (li_36 > 0) {
         ls_60 = StringSubstr(as_0, li_36 - 1, 1);
         if (ls_60 >= "0" && ls_60 <= "9") {
            li_48 = StringGetChar(as_0, li_36 - 1) - 48;
            l_count_40++;
            if (li_36 > 1) {
               ls_60 = StringSubstr(as_0, li_36 - 2, 1);
               if (ls_60 == "-") {
                  li_48 = -li_48;
                  l_count_40++;
               } else {
                  if (ls_60 >= "0" && ls_60 <= "9") {
                     li_48 = 10 * (StringGetChar(as_0, li_36 - 2) - 48) + li_48;
                     l_count_40++;
                     if (li_36 > 2 && StringSubstr(as_0, li_36 - 3, 1) == "-") {
                        li_48 = -li_48;
                        l_count_40++;
                     }
                  }
               }
            }
         }
      }
      ls_68 = "";
      for (int l_count_32 = 0; l_count_32 < MathAbs(li_48) - StringLen(as_16); l_count_32++) ls_68 = ls_68 + as_24;
      if (li_48 == 0) ls_52 = as_16;
      else {
         if (li_48 < 0) ls_52 = as_16 + ls_68;
         else ls_52 = ls_68 + as_16;
      }
      if (li_36 - l_count_40 > 0) as_0 = StringSubstr(as_0, 0, li_36 - l_count_40) + ls_52 + StringSubstr(as_0, li_36 + StringLen(as_8));
      else as_0 = ls_52 + StringSubstr(as_0, li_36 + StringLen(as_8));
   }
}

string Duration(double ad_0, double ad_8) {
   if (ad_0 <= 0.0 || ad_8 <= 0.0) return ("");
   int li_16 = (ad_8 - ad_0) / 60.0;
   if (li_16 < 1) return ("<1‡");
   int li_20 = li_16 / 1440;
   int li_24 = (li_16 - 1440 * li_20) / 60;
   int li_28 = li_16 - 1440 * li_20 - 60 * li_24;
   string ls_ret_32 = "";
   if (li_20 > 0) ls_ret_32 = ls_ret_32 + li_20 + "„";
   if (li_24 > 0) ls_ret_32 = ls_ret_32 + li_24 + "†";
   if (li_28 > 0) ls_ret_32 = ls_ret_32 + li_28 + "‡";
   return (ls_ret_32);
}

int GetWindowBackgroundColor() {
   int li_0 = WindowHandle(Symbol(), Period());
   int li_4 = GetDC(li_0);
   int li_ret_8 = GetPixel(li_4, 1, 2);
   ReleaseDC(li_0, li_4);
   return (li_ret_8);
}

int deinit() {
   for (int li_0 = 0; li_0 < ObjectsTotal(); li_0++) {
      if (StringSubstr(ObjectName(li_0), 0, 3) == "tmÿ" || StringSubstr(ObjectName(li_0), 0, 3) == "tmþ") {
         ObjectDelete(ObjectName(li_0));
         li_0--;
      }
   }
   ObjectDelete(g_name_336);
   ObjectDelete(g_name_344);
   ObjectDelete(g_name_352);
   ObjectDelete(g_name_360);
   ObjectDelete(g_name_368);
   GlobalVariableDel("tm RiskPercent");
   return (0);
}

int init() {
   int li_4;
   for (int l_index_0 = 0; l_index_0 < 256; l_index_0++) gsa_376[l_index_0] = CharToStr(l_index_0);
   Print(gsa_376[102] + gsa_376[116] + gsa_376[46] + gsa_376[84] + gsa_376[114] + gsa_376[97] + gsa_376[100] + gsa_376[105] + gsa_376[110] + gsa_376[103] + gsa_376[77] +
      gsa_376[111] + gsa_376[117] + gsa_376[115] + gsa_376[101] + gsa_376[32] + gsa_376[118] + gsa_376[49] + gsa_376[46] + gsa_376[49] + gsa_376[50] + gsa_376[32] + gsa_376[67] +
      gsa_376[111] + gsa_376[112] + gsa_376[121] + gsa_376[114] + gsa_376[105] + gsa_376[103] + gsa_376[104] + gsa_376[116] + gsa_376[32] + gsa_376[169] + gsa_376[32] +
      gsa_376[50] + gsa_376[48] + gsa_376[48] + gsa_376[54] + gsa_376[45] + gsa_376[50] + gsa_376[48] + gsa_376[48] + gsa_376[57] + gsa_376[46] + gsa_376[32] + gsa_376[83] +
      gsa_376[101] + gsa_376[114] + gsa_376[103] + gsa_376[101] + gsa_376[121] + gsa_376[32] + gsa_376[75] + gsa_376[114] + gsa_376[97] + gsa_376[118] + gsa_376[99] + gsa_376[104] +
      gsa_376[117] + gsa_376[107] + gsa_376[46] + gsa_376[32] + gsa_376[104] + gsa_376[116] + gsa_376[116] + gsa_376[112] + gsa_376[58] + gsa_376[47] + gsa_376[47] + gsa_376[102] +
      gsa_376[111] + gsa_376[114] + gsa_376[101] + gsa_376[120] + gsa_376[116] + gsa_376[111] + gsa_376[111] + gsa_376[108] + gsa_376[115] + gsa_376[46] + gsa_376[99] +
      gsa_376[111] + gsa_376[109] + gsa_376[46] + gsa_376[117] + gsa_376[97]);
   gi_76 = GetWindowBackgroundColor();
   IndicatorShortName("  ");
   GlobalVariableSet("tm ShowInfoLeft", ShowInfoLeft);
   GlobalVariableSet("tm Slippage", Slippage);
   GlobalVariableSet("tm RiskPercent", RiskPercent);
   GlobalVariableSet("tm FillPercent", FillPercent);
   GlobalVariableSet("tm StopTradePercent", StopTradePercent);
   GlobalVariableSet("tm ColorBuyArrows", ColorBuyArrows);
   GlobalVariableSet("tm ColorBuyStopsBox", ColorBuyStopsBox);
   GlobalVariableSet("tm ColorBuyOrderBox", ColorBuyOrderBox);
   GlobalVariableSet("tm ColorSellArrows", ColorSellArrows);
   GlobalVariableSet("tm ColorSellStopsBox", ColorSellStopsBox);
   GlobalVariableSet("tm ColorSellOrderBox", ColorSellOrderBox);
   GlobalVariableSet("tm ColorPendingArrows", ColorPendingArrows);
   GlobalVariableSet("tm ColorPendingBuyStopsBox", ColorPendingBuyStopsBox);
   GlobalVariableSet("tm ColorPendingBuyOrderBox", ColorPendingBuyOrderBox);
   GlobalVariableSet("tm ColorPendingSellStopsBox", ColorPendingSellStopsBox);
   GlobalVariableSet("tm ColorPendingSellOrderBox", ColorPendingSellOrderBox);
   g_fontname_96 = gs_300;
   g_fontsize_108 = gi_316;
   gi_112 = gi_320;
   GlobalVariableSet("tm FontSize", gi_316);
   GlobalVariableSet("tm FontHeight", gi_320);
   if (ShowSymbolOrdersOnly) {
      li_4 = StringFind(OrdersInfoFormat, "@SYMBOL");
      if (li_4 > 0 && StringSubstr(OrdersInfoFormat, li_4 - 1, 1) == " ") OrdersInfoFormat = StringSubstr(OrdersInfoFormat, 0, li_4 - 1) + StringSubstr(OrdersInfoFormat, li_4 + 7);
      else {
         if (li_4 > 0 && StringSubstr(OrdersInfoFormat, li_4 + 7, 1) == " ") gs_292 = StringSubstr(OrdersInfoFormat, 0, li_4) + StringSubstr(OrdersInfoFormat, li_4 + 8);
         else gs_292 = StringSubstr(OrdersInfoFormat, 0, li_4) + StringSubstr(OrdersInfoFormat, li_4 + 7);
      }
   }
   return (0);
}

int start() {
   string ls_84;
   int li_92;
   int li_96;
   double ld_100;
   double ld_124;
   double ld_152;
   int l_str_len_164;
   int li_180;
   gi_76 = GetWindowBackgroundColor();
   double ld_4 = AccountBalance();
   double ld_12 = AccountStopoutLevel();
   if (AccountStopoutMode() == 0) ld_12 = ld_12 / 100.0 * AccountBalance();
   double l_tickvalue_20 = MarketInfo(Symbol(), MODE_TICKVALUE);
   double l_ticksize_28 = MarketInfo(Symbol(), MODE_TICKSIZE);
   double ld_36 = MarketInfo(Symbol(), MODE_SPREAD) * Point;
   double l_minlot_44 = MarketInfo(Symbol(), MODE_MINLOT);
   double l_maxlot_52 = MarketInfo(Symbol(), MODE_MAXLOT);
   double l_lotsize_60 = MarketInfo(Symbol(), MODE_LOTSIZE);
   double l_lotstep_68 = MarketInfo(Symbol(), MODE_LOTSTEP);
   double ld_unused_76 = AccountLeverage();
   double ld_108 = 0;
   double ld_116 = 0;
   double ld_132 = 0;
   if (OrdersTotal() > 0) {
      for (int l_pos_140 = 0; l_pos_140 < OrdersTotal(); l_pos_140++) {
         OrderSelect(l_pos_140, SELECT_BY_POS, MODE_TRADES);
         ld_124 = MathAbs(OrderOpenPrice() - OrderStopLoss()) / MarketInfo(OrderSymbol(), MODE_POINT) * MarketInfo(OrderSymbol(), MODE_TICKVALUE) * OrderLots();
         if ((OrderStopLoss() >= OrderOpenPrice() && OrderType() == OP_BUY) || (OrderStopLoss() <= OrderOpenPrice() && OrderType() == OP_SELL)) ld_108 += ld_124;
         else ld_116 += ld_124;
         ls_84 = OrderComment();
         li_92 = StringFind(ls_84, "[");
         li_96 = StringFind(ls_84, "]");
         if (li_92 < 0 || li_96 < 0 || li_96 < li_92) ld_100 = 0;
         else ld_100 = StrToDouble(StringSubstr(ls_84, li_92 + 1, li_96 - li_92 - 1));
         if (ld_100 <= 0.0) ld_100 = MarketInfo(OrderSymbol(), MODE_MARGINREQUIRED) * OrderLots();
         ld_132 += ld_100;
      }
   }
   double ld_144 = ld_4 + ld_108 - ld_116;
   if (ld_132 > 0.0) ld_152 = 100.0 * (ld_144 / ld_132);
   else ld_152 = 0;
   gi_324 = GlobalVariableGet("tm " + Symbol() + gs_328);
   if (ShowStopLevelMarks) PlaceStoplevelBox();
   else {
      if (ObjectFind(g_name_360) != -1) ObjectDelete(g_name_360);
      if (ObjectFind(g_name_368) != -1) ObjectDelete(g_name_368);
   }
   g_fontname_96 = gs_300;
   g_window_80 = 0;
   if (ShowInfoLeft) g_corner_84 = 2;
   else g_corner_84 = 3;
   ClearFromLine(g_corner_84, 0);
   g_count_88 = 0;
   int li_160 = gi_128;
   gi_128 = 1;
   g_fontname_96 = gs_308;
   PutStr(DoubleToStr(ld_4, 2), "Balance", ColorInfoText);
   g_fontname_96 = gs_300;
   PutStr("Balance", "Balance", ColorInfoText);
   g_count_88 -= 2;
   gi_128 = 70;
   gi_124 = gi_128;
   g_fontname_96 = gs_308;
   PutStr(DoubleToStr(ld_144, 2), "Equity", ColorInfoText);
   g_fontname_96 = gs_300;
   PutStr("Equity", "Equity", ColorInfoText);
   g_count_88 -= 2;
   gi_128 = 140;
   gi_124 = gi_128;
   g_fontname_96 = gs_308;
   PutStr(DoubleToStr(ld_132, 2), "Margin", ColorPendingOrder);
   g_fontname_96 = gs_300;
   PutStr("Margin", "Margin", ColorPendingOrder);
   g_count_88 -= 2;
   gi_128 = 210;
   gi_124 = gi_128;
   g_fontname_96 = gs_308;
   PutStr(DoubleToStr(ld_152, 1) + "%", "Level", ColorInfoText);
   g_fontname_96 = gs_300;
   PutStr("Level", "Level", ColorInfoText);
   gi_128 = li_160;
   ld_100 = AccountProfit();
   int l_color_0 = ColorZeroProfitOrder;
   if (ld_100 > 0.0) l_color_0 = ColorProfitOrder;
   if (ld_100 < 0.0) l_color_0 = ColorLossOrder;
   g_fontname_96 = gs_308;
   PutStr(DoubleToStr(ld_100, 2), "Profit", l_color_0);
   g_fontname_96 = gs_300;
   PutStr("Profit", "Profit", l_color_0);
   g_count_88 -= 2;
   gi_128 = 70;
   gi_124 = TRUE;
   l_color_0 = ColorZeroProfitOrder;
   if (ld_108 > 0.0) l_color_0 = ColorProfitOrder;
   g_fontname_96 = gs_308;
   PutStr(DoubleToStr(ld_108, 2), "Protected", l_color_0);
   g_fontname_96 = gs_300;
   PutStr("Protected", "Protected", l_color_0);
   gi_124 = gi_128;
   g_count_88 -= 2;
   gi_128 = 140;
   g_fontname_96 = gs_308;
   PutStr(DoubleToStr(ld_116, 2), "MaxLoss", ColorLossOrder);
   g_fontname_96 = gs_300;
   PutStr("MaxLoss", "MaxLoss", ColorLossOrder);
   gi_124 = gi_128;
   g_count_88 -= 2;
   gi_128 = 210;
   g_fontname_96 = gs_308;
   if (RiskPercent >= 0) PutStr(RiskPercent + "%", "RiskPercent", ColorInfoText);
   else PutStr((-RiskPercent) + " " + AccountCurrency(), "RiskPercent", ColorInfoText);
   g_fontname_96 = gs_300;
   PutStr("Risk", "RiskPercent", ColorInfoText);
   g_count_88++;
   gi_128 = 1;
   gi_124 = gi_128;
   g_fontname_96 = gs_308;
   PutStr(TimeToStr(TimeCurrent(), TIME_DATE|TIME_MINUTES|TIME_SECONDS), "Time", ColorInfoText);
   g_fontname_96 = gs_300;
   gi_128 = li_160;
   gi_128 = 1;
   gi_124 = gi_128;
   if (ShowInfoLeft) g_corner_84 = 0;
   else g_corner_84 = 1;
   ClearFromLine(g_corner_84, 0);
   g_count_88 = 0;
   int l_str_len_168 = 0;
   int l_str_len_172 = 0;
   for (l_pos_140 = 0; l_pos_140 < OrdersTotal(); l_pos_140++) {
      if (OrderSelect(l_pos_140, SELECT_BY_POS, MODE_TRADES) != FALSE) {
         l_str_len_164 = StringLen(DoubleToStr(OrderProfit(), 2));
         if (l_str_len_168 < l_str_len_164) l_str_len_168 = l_str_len_164;
         l_str_len_164 = StringLen(DoubleToStr(OrderStopLoss(), 2));
         if (l_str_len_172 < l_str_len_164) l_str_len_172 = l_str_len_164;
         l_str_len_164 = StringLen(DoubleToStr(OrderTakeProfit(), 2));
         if (l_str_len_172 < l_str_len_164) l_str_len_172 = l_str_len_164;
      }
   }
   for (l_pos_140 = OrdersHistoryTotal(); l_pos_140 >= 0; l_pos_140--) {
      if (OrderSelect(l_pos_140, SELECT_BY_POS, MODE_HISTORY) != FALSE) {
         l_str_len_164 = StringLen(DoubleToStr(OrderProfit(), 2));
         if (l_str_len_168 < l_str_len_164) l_str_len_168 = l_str_len_164;
         l_str_len_164 = StringLen(DoubleToStr(OrderStopLoss(), 2));
         if (l_str_len_172 < l_str_len_164) l_str_len_172 = l_str_len_164;
         l_str_len_164 = StringLen(DoubleToStr(OrderTakeProfit(), 2));
         if (l_str_len_172 < l_str_len_164) l_str_len_172 = l_str_len_164;
      }
   }
   l_pos_140 = StringFind(OrdersInfoFormat, "@PROFIT");
   if (l_pos_140 >= 0) gs_292 = StringSubstr(OrdersInfoFormat, 0, l_pos_140) + l_str_len_168 + StringSubstr(OrdersInfoFormat, l_pos_140);
   l_pos_140 = StringFind(gs_292, "@PRICE");
   if (l_pos_140 >= 0) gs_292 = StringSubstr(gs_292, 0, l_pos_140) + l_str_len_172 + StringSubstr(gs_292, l_pos_140);
   l_pos_140 = StringFind(gs_292, "@TP");
   if (l_pos_140 >= 0) gs_292 = StringSubstr(gs_292, 0, l_pos_140) + l_str_len_172 + StringSubstr(gs_292, l_pos_140);
   l_pos_140 = StringFind(gs_292, "@SL");
   if (l_pos_140 >= 0) gs_292 = StringSubstr(gs_292, 0, l_pos_140) + l_str_len_172 + StringSubstr(gs_292, l_pos_140);
   for (l_pos_140 = 0; l_pos_140 < OrdersTotal(); l_pos_140++) {
      if (OrderSelect(l_pos_140, SELECT_BY_POS, MODE_TRADES) != FALSE) {
         if (OrderType() != OP_BUY && OrderType() != OP_SELL) continue;
         if (OrderSymbol() == Symbol()) g_fontname_96 = gs_308;
         else g_fontname_96 = gs_300;
         l_color_0 = ColorZeroProfitOrder;
         if (OrderProfit() > 0.0) l_color_0 = ColorProfitOrder;
         if (OrderProfit() < 0.0) l_color_0 = ColorLossOrder;
         if (!ShowSymbolOrdersOnly || (ShowSymbolOrdersOnly && OrderSymbol() == Symbol())) PutStr(Format(gs_292), OrderTicket(), l_color_0);
      }
   }
   for (l_pos_140 = 0; l_pos_140 < OrdersTotal(); l_pos_140++) {
      if (OrderSelect(l_pos_140, SELECT_BY_POS, MODE_TRADES) != FALSE) {
         if (OrderType() == OP_BUY || OrderType() == OP_SELL) continue;
         if (OrderSymbol() == Symbol()) g_fontname_96 = gs_308;
         else g_fontname_96 = gs_300;
         if (!ShowSymbolOrdersOnly || (ShowSymbolOrdersOnly && OrderSymbol() == Symbol())) PutStr(Format(gs_292), OrderTicket(), ColorPendingOrder);
      }
   }
   if (OrdersHistoryTotal() < MaxClosedOrdersCnt) li_180 = OrdersHistoryTotal();
   else li_180 = MaxClosedOrdersCnt;
   int l_count_184 = 0;
   for (l_pos_140 = OrdersHistoryTotal(); l_pos_140 >= 0 && l_count_184 < li_180; l_pos_140--) {
      if (OrderSelect(l_pos_140, SELECT_BY_POS, MODE_HISTORY) != FALSE) {
         if (OrderSymbol() == Symbol()) g_fontname_96 = gs_308;
         else g_fontname_96 = gs_300;
         if (OrderType() == OP_BUY || OrderType() == OP_SELL && !ShowSymbolOrdersOnly || (ShowSymbolOrdersOnly && OrderSymbol() == Symbol())) {
            l_count_184++;
            PutStr(Format(gs_292), OrderTicket(), ColorClosedOrder);
         }
      }
   }
   gi_324 = GlobalVariableGet("tm " + Symbol() + gs_328);
   if (gi_324 > 0) ShowOrderBox(gi_324);
   return (0);
}

void PlaceStoplevelBox() {
   double ld_8 = MarketInfo(Symbol(), MODE_STOPLEVEL);
   double l_price_0 = Ask;
   if (ObjectFind(g_name_360) != -1) ObjectDelete(g_name_360);
   ObjectCreate(g_name_360, OBJ_ARROW, 0, Time[0] + (Time[0] - Time[3]), l_price_0 + ld_8 * Point);
   ObjectSet(g_name_360, OBJPROP_ARROWCODE, 4);
   ObjectSet(g_name_360, OBJPROP_COLOR, ColorBuyStopsBox);
   ObjectSet(g_name_360, OBJPROP_BACK, FALSE);
   l_price_0 = Bid;
   if (ObjectFind(g_name_368) != -1) ObjectDelete(g_name_368);
   ObjectCreate(g_name_368, OBJ_ARROW, 0, Time[0] + (Time[0] - Time[3]), l_price_0 - ld_8 * Point);
   ObjectSet(g_name_368, OBJPROP_ARROWCODE, 4);
   ObjectSet(g_name_368, OBJPROP_COLOR, ColorSellStopsBox);
   ObjectSet(g_name_368, OBJPROP_BACK, FALSE);
}

void RemoveOrderBox() {
   GlobalVariableDel("tm " + Symbol() + gs_328);
   if (ObjectFind(g_name_336) >= 0) ObjectDelete(g_name_336);
   if (ObjectFind(g_name_344) >= 0) ObjectDelete(g_name_344);
   color l_color_0 = GetWindowBackgroundColor();
   for (int li_4 = 0; li_4 < ObjectsTotal(); li_4++)
      if (StringFind(ObjectName(li_4), "tmþ" + "1") == 0) ObjectSet(ObjectName(li_4), OBJPROP_COLOR, l_color_0);
   int li_8 = WindowHandle(Symbol(), Period());
   if (li_8 != 0) PostMessageA(li_8, WM_COMMAND, 33324, 0);
}

void ShowOrderBox(int a_ticket_0) {
   color l_color_4;
   color l_color_8;
   int l_datetime_12;
   int l_datetime_16;
   double l_ord_open_price_20;
   double l_price_28;
   bool li_36;
   color l_color_40;
   color l_color_48;
   if (OrderSelect(a_ticket_0, SELECT_BY_TICKET) == FALSE) {
      MessageBox("Order # " + a_ticket_0 + " not found", "ERROR", MB_ICONHAND);
      RemoveOrderBox();
      GlobalVariableDel("tm " + Symbol() + gs_328);
      return;
   }
   if (OrderSymbol() == Symbol()) {
      if (OrderType() == OP_BUY) {
         l_color_8 = ColorBuyOrderBox;
         l_color_4 = ColorBuyStopsBox;
      }
      if (OrderType() == OP_SELL) {
         l_color_8 = ColorSellOrderBox;
         l_color_4 = ColorSellStopsBox;
      }
      if (OrderType() == OP_BUYSTOP || OrderType() == OP_BUYLIMIT) {
         l_color_8 = ColorPendingBuyOrderBox;
         l_color_4 = ColorPendingBuyStopsBox;
      }
      if (OrderType() == OP_SELLSTOP || OrderType() == OP_SELLLIMIT) {
         l_color_8 = ColorPendingSellOrderBox;
         l_color_4 = ColorPendingSellStopsBox;
      }
      GlobalVariableSet("tm " + Symbol() + gs_328, OrderTicket());
      l_datetime_12 = OrderOpenTime();
      l_ord_open_price_20 = OrderOpenPrice();
      if (OrderCloseTime() > 0) {
         l_datetime_16 = OrderCloseTime();
         l_price_28 = OrderClosePrice();
      } else {
         if (OrderType() == OP_BUY || OrderType() == OP_BUYSTOP || OrderType() == OP_BUYLIMIT) l_price_28 = Bid;
         if (OrderType() == OP_SELL || OrderType() == OP_SELLSTOP || OrderType() == OP_SELLLIMIT) l_price_28 = Ask;
         l_datetime_16 = Time[0];
         if (OrderType() == OP_BUYSTOP || OrderType() == OP_BUYLIMIT || OrderType() == OP_SELLSTOP || OrderType() == OP_SELLLIMIT && OrderExpiration() > 0) l_datetime_16 = OrderExpiration();
         else l_datetime_16 = -1;
      }
      if (l_datetime_12 >= l_datetime_16) l_datetime_16 = Time[0] + (Time[0] - Time[1]);
      if (ObjectFind(g_name_336) >= 0) ObjectDelete(g_name_336);
      ObjectCreate(g_name_336, OBJ_RECTANGLE, 0, l_datetime_12, l_ord_open_price_20, l_datetime_16, l_price_28, 0, 0);
      ObjectSet(g_name_336, OBJPROP_COLOR, l_color_8);
      ObjectSet(g_name_344, OBJPROP_BACK, TRUE);
      l_ord_open_price_20 = OrderStopLoss();
      if (l_ord_open_price_20 == 0.0) {
         if (OrderType() == OP_BUY || OrderType() == OP_BUYSTOP || OrderType() == OP_BUYLIMIT) l_ord_open_price_20 = 0;
         if (OrderType() == OP_SELL || OrderType() == OP_SELLSTOP || OrderType() == OP_SELLLIMIT) l_ord_open_price_20 = 10.0 * Bid;
      }
      l_price_28 = OrderTakeProfit();
      if (l_price_28 == 0.0) {
         if (OrderType() == OP_BUY || OrderType() == OP_BUYSTOP || OrderType() == OP_BUYLIMIT) l_price_28 = 10.0 * Ask;
         if (OrderType() == OP_SELL || OrderType() == OP_SELLSTOP || OrderType() == OP_SELLLIMIT) l_price_28 = 0;
      }
      if (ObjectFind(g_name_344) >= 0) ObjectDelete(g_name_344);
      ObjectCreate(g_name_344, OBJ_RECTANGLE, 0, l_datetime_12, l_ord_open_price_20, l_datetime_16, l_price_28, 0, 0);
      ObjectSet(g_name_344, OBJPROP_COLOR, l_color_4);
      ObjectSet(g_name_344, OBJPROP_BACK, FALSE);
      if (GlobalVariableGet("tm ShowInfoLeft") == 1.0) li_36 = FALSE;
      else li_36 = TRUE;
      l_color_40 = GetWindowBackgroundColor();
      for (int li_44 = 0; li_44 < ObjectsTotal(); li_44++)
         if (StringFind(ObjectName(li_44), "tmþ" + li_36) == 0) ObjectSet(ObjectName(li_44), OBJPROP_COLOR, l_color_40);
      for (li_44 = 0; li_44 < ObjectsTotal(); li_44++) {
         if (StringFind(ObjectName(li_44), "tmþ" + li_36) == 0 && StringFind(ObjectName(li_44), "-{" + a_ticket_0 + "}-") > 0) {
            l_color_48 = CLR_NONE;
            if (a_ticket_0 > 0 && a_ticket_0 == OrderTicket()) {
               if (OrderType() == OP_BUY) l_color_48 = ColorBuyOrderBox;
               if (OrderType() == OP_BUYSTOP) l_color_48 = ColorPendingBuyOrderBox;
               if (OrderType() == OP_BUYLIMIT) l_color_48 = ColorPendingBuyOrderBox;
               if (OrderType() == OP_SELL) l_color_48 = ColorSellOrderBox;
               if (OrderType() == OP_SELLSTOP) l_color_48 = ColorPendingSellOrderBox;
               if (OrderType() == OP_SELLLIMIT) l_color_48 = ColorPendingSellOrderBox;
            }
            ObjectSet(ObjectName(li_44), OBJPROP_COLOR, l_color_48);
            return;
         }
      }
   }
}
