
#property copyright "Copyright © 2009, TradeWays"
#property link      "http://www.tradeways.org"

extern int Mode = 2;
extern int Magic_N = -1;
string gs_84 = "";
int gi_92 = 0;
extern string s0 = "==== ==== ==== ==== ==== ====";
extern double CloseLots_1 = 0.1;
extern double CloseLots_2 = 0.1;
extern double Range = 100.0;
extern bool UseSimpleThreeStep = TRUE;
extern int Level_1 = 25;
extern int Level_2 = 55;
extern int Level_3 = 75;
extern int Slippage = 3;
extern string s1 = "==== Параметры уровней ====";
extern int TimeFrame = 0;
extern int StartHour = 0;
int gi_164 = 0;
extern int EndHour = 7;
int gi_172 = 0;
extern double Fibo_K_1 = 161.0;
extern double Fibo_K_2 = 200.0;
extern double Fibo_K_3 = 261.0;
extern bool DrawLevels = TRUE;
extern string s2 = "=== Tester ============================================================================";
bool gi_212 = FALSE;
bool gi_216 = FALSE;
string gs_220;
int gia_unused_228[];
int gia_unused_232[];
double gd_236;
double gd_244;
double gd_252;
double gd_260;
double gd_268;
double gd_276;
double gd_284;
double gd_296;
int g_datetime_304 = 0;
int g_datetime_308 = 0;
int g_datetime_312 = 0;
int g_datetime_316 = 0;

int init() {
   Fibo_K_1 /= 100.0;
   Fibo_K_2 /= 100.0;
   Fibo_K_3 /= 100.0;
   gs_220 = "eMSFPCTv1" + Symbol() + "_";
   if (IsTesting()) gs_220 = gs_220 + "t_";
   if (IsDemo()) gs_220 = gs_220 + "d_";
   if (IsTesting()) {
      for (int li_0 = GlobalVariablesTotal() - 1; li_0 >= 0; li_0--)
         if (StringFind(GlobalVariableName(li_0), gs_220, 0) == 0) GlobalVariableDel(GlobalVariableName(li_0));
   }
   return (0);
}

int deinit() {
   if (IsTesting()) {
      for (int li_0 = GlobalVariablesTotal() - 1; li_0 >= 0; li_0--)
         if (StringFind(GlobalVariableName(li_0), gs_220, 0) == 0) GlobalVariableDel(GlobalVariableName(li_0));
   }
   ObjectDelete("MSFP_P");
   ObjectDelete("MSFP_R1");
   ObjectDelete("MSFP_R2");
   ObjectDelete("MSFP_R3");
   ObjectDelete("MSFP_S1");
   ObjectDelete("MSFP_S2");
   ObjectDelete("MSFP_S3");
   return (0);
}

int start() {
   int li_8;
   fLevels();
   //if (TimeCurrent() > StrToTime("2050.04.20")) {
   //   Alert("New version available! Download it using re-activated link from Plimus");
   //   return;
   //}
   if (ND(gd_268) == 0.0) return (0);
   if (IsTesting()) {
      if (OrdersTotal() == 0) {
         if (gi_212) OrderSend(Symbol(), OP_BUY, 4.0, NormalizeDouble(Ask, Digits), 0, 0, 0, 0, 0, 0, CLR_NONE);
         if (gi_216) OrderSend(Symbol(), OP_SELL, 4.0, NormalizeDouble(Bid, Digits), 0, 0, 0, 0, 0, 0, CLR_NONE);
      }
   }
   int li_0 = 0;
   if (ND(Bid) >= ND(gd_244)) li_0 = 1;
   if (ND(Bid) >= ND(gd_252)) li_0 = 2;
   if (ND(Bid) >= ND(gd_260)) li_0 = 3;
   if (ND(Bid) <= ND(gd_268)) li_0 = -1;
   if (ND(Bid) <= ND(gd_276)) li_0 = -2;
   if (ND(Bid) <= ND(gd_284)) li_0 = -3;
   if (DrawLevels) {
      fObjHLine("MSFP_P", gd_236, Yellow, 1, 0, STYLE_SOLID, FALSE);
      fObjHLine("MSFP_R1", gd_244, DodgerBlue, 1, 0, STYLE_SOLID, FALSE);
      fObjHLine("MSFP_R2", gd_252, DodgerBlue, 1, 0, STYLE_SOLID, FALSE);
      fObjHLine("MSFP_R3", gd_260, DodgerBlue, 1, 0, STYLE_SOLID, FALSE);
      fObjHLine("MSFP_S1", gd_268, Red, 1, 0, STYLE_SOLID, FALSE);
      fObjHLine("MSFP_S2", gd_276, Red, 1, 0, STYLE_SOLID, FALSE);
      fObjHLine("MSFP_S3", gd_284, Red, 1, 0, STYLE_SOLID, FALSE);
   }
   if (Mode == 1) {
      if (li_0 > 0) fOrderCloseMarket(1, 0);
      if (li_0 < 0) fOrderCloseMarket(0, 1);
   }
   if (Mode == 2) {
      for (int l_pos_4 = 0; l_pos_4 < OrdersTotal(); l_pos_4++) {
         if (OrderSelect(l_pos_4, SELECT_BY_POS, MODE_TRADES)) {
            if (fOrderThisExpertSelected()) {
               if (OrderType() == OP_BUY) {
                  li_8 = fGetParentTicket(OrderComment());
                  if (li_8 > 0) {
                     GlobalVariableSet(gs_220 + OrderTicket() + "_1", 1);
                     if (GlobalVariableCheck(gs_220 + li_8 + "_2")) GlobalVariableSet(gs_220 + OrderTicket() + "_2", 1);
                  }
                  if (ND(OrderOpenPrice()) > ND(gd_244) || gd_296 > ND(Point * Range)) {
                     if (UseSimpleThreeStep) {
                        if (!GlobalVariableCheck(gs_220 + OrderTicket() + "_1")) {
                           if (ND(Ask) >= ND(OrderOpenPrice() + Point * Level_1)) {
                              if (ND(OrderStopLoss()) < ND(OrderOpenPrice())) {
                                 fModifyOrder(OrderTicket(), OrderOpenPrice(), OrderOpenPrice(), OrderTakeProfit(), OrderExpiration());
                                 if (!(OrderSelect(l_pos_4, SELECT_BY_POS, MODE_TRADES))) continue;
                              }
                              if (ND(OrderStopLoss()) >= ND(OrderOpenPrice())) {
                                 if (!GlobalVariableCheck(gs_220 + OrderTicket() + "_1"))
                                    if (fCloseSelectedOrder(CloseLots_1) == 0) GlobalVariableSet(gs_220 + OrderTicket() + "_1", 1);
                              }
                           }
                        } else {
                           if (!GlobalVariableCheck(gs_220 + OrderTicket() + "_2")) {
                              if (ND(Ask) >= ND(OrderOpenPrice() + Point * Level_2)) {
                                 if (ND(OrderStopLoss()) < ND(OrderOpenPrice() + Point * (Level_2 - Level_1))) {
                                    fModifyOrder(OrderTicket(), OrderOpenPrice(), ND(OrderOpenPrice() + Point * (Level_2 - Level_1)), OrderTakeProfit(), OrderExpiration());
                                    if (!(OrderSelect(l_pos_4, SELECT_BY_POS, MODE_TRADES))) continue;
                                 }
                                 if (ND(OrderStopLoss()) >= ND(OrderOpenPrice() + Point * (Level_2 - Level_1))) {
                                    if (!GlobalVariableCheck(gs_220 + OrderTicket() + "_2"))
                                       if (fCloseSelectedOrder(CloseLots_2) == 0) GlobalVariableSet(gs_220 + OrderTicket() + "_2", 1);
                                 }
                              }
                           } else {
                              if (ND(Ask) >= ND(OrderOpenPrice() + Point * Level_3)) {
                                 if (fCloseSelectedOrder(OrderLots()) == 0) {
                                    GlobalVariableDel(gs_220 + OrderTicket() + "_1");
                                    GlobalVariableDel(gs_220 + OrderTicket() + "_2");
                                 }
                              }
                           }
                        }
                     }
                  } else {
                     switch (li_0) {
                     case 1:
                        if (ND(OrderStopLoss()) < ND(OrderOpenPrice())) {
                           if (ND(OrderOpenPrice()) <= ND(Bid - Point * MarketInfo(Symbol(), MODE_STOPLEVEL))) {
                              fModifyOrder(OrderTicket(), OrderOpenPrice(), OrderOpenPrice(), OrderTakeProfit(), OrderExpiration());
                              if (!(OrderSelect(l_pos_4, SELECT_BY_POS, MODE_TRADES))) continue;
                           }
                        }
                        if (ND(OrderStopLoss()) >= ND(OrderOpenPrice())) {
                           if (!GlobalVariableCheck(gs_220 + OrderTicket() + "_1"))
                              if (fCloseSelectedOrder(CloseLots_1) == 0) GlobalVariableSet(gs_220 + OrderTicket() + "_1", 1);
                        }
                        break;
                     case 2:
                        if (ND(OrderStopLoss()) < ND(gd_244)) {
                           if (ND(gd_244) <= ND(Bid - Point * MarketInfo(Symbol(), MODE_STOPLEVEL))) {
                              fModifyOrder(OrderTicket(), OrderOpenPrice(), ND(gd_244), OrderTakeProfit(), OrderExpiration());
                              if (!(OrderSelect(l_pos_4, SELECT_BY_POS, MODE_TRADES))) continue;
                           }
                        }
                        if (ND(OrderStopLoss()) >= ND(gd_244)) {
                           if (!GlobalVariableCheck(gs_220 + OrderTicket() + "_2"))
                              if (fCloseSelectedOrder(CloseLots_2) == 0) GlobalVariableSet(gs_220 + OrderTicket() + "_2", 1);
                        }
                        break;
                     case 3:
                        if (fCloseSelectedOrder(OrderLots()) == 0) {
                           GlobalVariableDel(gs_220 + OrderTicket() + "_1");
                           GlobalVariableDel(gs_220 + OrderTicket() + "_2");
                        }
                     }
                  }
               }
               if (OrderType() == OP_SELL) {
                  li_8 = fGetParentTicket(OrderComment());
                  if (li_8 > 0) {
                     GlobalVariableSet(gs_220 + OrderTicket() + "_1", 1);
                     if (GlobalVariableCheck(gs_220 + li_8 + "_2")) GlobalVariableSet(gs_220 + OrderTicket() + "_2", 1);
                  }
                  if (ND(OrderOpenPrice()) < ND(gd_268) || gd_296 > ND(Point * Range)) {
                     if (UseSimpleThreeStep) {
                        if (!GlobalVariableCheck(gs_220 + OrderTicket() + "_1")) {
                           if (ND(Bid) <= ND(OrderOpenPrice() - Point * Level_1)) {
                              if (ND(OrderStopLoss()) > ND(OrderOpenPrice()) || ND(OrderStopLoss()) == 0.0) {
                                 fModifyOrder(OrderTicket(), OrderOpenPrice(), OrderOpenPrice(), OrderTakeProfit(), OrderExpiration());
                                 if (!(OrderSelect(l_pos_4, SELECT_BY_POS, MODE_TRADES))) continue;
                              }
                              if (ND(OrderStopLoss()) <= ND(OrderOpenPrice()) && ND(OrderStopLoss()) != 0.0) {
                                 if (!GlobalVariableCheck(gs_220 + OrderTicket() + "_1"))
                                    if (fCloseSelectedOrder(CloseLots_1) == 0) GlobalVariableSet(gs_220 + OrderTicket() + "_1", 1);
                              }
                           }
                        } else {
                           if (!GlobalVariableCheck(gs_220 + OrderTicket() + "_2")) {
                              if (ND(Bid) <= ND(OrderOpenPrice() - Point * Level_2)) {
                                 if (ND(OrderStopLoss()) > ND(OrderOpenPrice() - Point * (Level_2 - Level_1)) || ND(OrderStopLoss()) == 0.0) {
                                    fModifyOrder(OrderTicket(), OrderOpenPrice(), ND(OrderOpenPrice() - Point * (Level_2 - Level_1)), OrderTakeProfit(), OrderExpiration());
                                    if (!(OrderSelect(l_pos_4, SELECT_BY_POS, MODE_TRADES))) continue;
                                 }
                                 if (ND(OrderStopLoss()) <= ND(OrderOpenPrice() - Point * (Level_2 - Level_1)) && ND(OrderStopLoss()) != 0.0) {
                                    if (!GlobalVariableCheck(gs_220 + OrderTicket() + "_2"))
                                       if (fCloseSelectedOrder(CloseLots_2) == 0) GlobalVariableSet(gs_220 + OrderTicket() + "_2", 1);
                                 }
                              }
                           } else {
                              if (ND(Bid) <= ND(OrderOpenPrice() - Point * Level_3)) {
                                 if (fCloseSelectedOrder(OrderLots()) == 0) {
                                    GlobalVariableDel(gs_220 + OrderTicket() + "_1");
                                    GlobalVariableDel(gs_220 + OrderTicket() + "_2");
                                 }
                              }
                           }
                        }
                     }
                  } else {
                     switch (li_0) {
                     case -1:
                        if (ND(OrderStopLoss()) > ND(OrderOpenPrice()) || ND(OrderStopLoss()) == 0.0) {
                           if (ND(OrderOpenPrice()) >= ND(Ask + Point * MarketInfo(Symbol(), MODE_STOPLEVEL))) {
                              fModifyOrder(OrderTicket(), OrderOpenPrice(), OrderOpenPrice(), OrderTakeProfit(), OrderExpiration());
                              if (!(OrderSelect(l_pos_4, SELECT_BY_POS, MODE_TRADES))) break;
                           }
                        }
                        if (ND(OrderStopLoss()) <= ND(OrderOpenPrice()) && ND(OrderStopLoss()) != 0.0) {
                           if (!GlobalVariableCheck(gs_220 + OrderTicket() + "_1"))
                              if (fCloseSelectedOrder(CloseLots_1) == 0) GlobalVariableSet(gs_220 + OrderTicket() + "_1", 1);
                        }
                        break;
                     case -2:
                        if (ND(OrderStopLoss()) > ND(gd_268) || ND(OrderStopLoss()) == 0.0) {
                           if (ND(gd_268) >= ND(Ask + Point * MarketInfo(Symbol(), MODE_STOPLEVEL))) {
                              fModifyOrder(OrderTicket(), OrderOpenPrice(), ND(gd_268), OrderTakeProfit(), OrderExpiration());
                              if (!(OrderSelect(l_pos_4, SELECT_BY_POS, MODE_TRADES))) break;
                           }
                        }
                        if (ND(OrderStopLoss()) <= ND(gd_268) && ND(OrderStopLoss()) != 0.0) {
                           if (!GlobalVariableCheck(gs_220 + OrderTicket() + "_2"))
                              if (fCloseSelectedOrder(CloseLots_2) == 0) GlobalVariableSet(gs_220 + OrderTicket() + "_2", 1);
                        }
                        break;
                     case -3:
                        if (fCloseSelectedOrder(OrderLots()) == 0) {
                           GlobalVariableDel(gs_220 + OrderTicket() + "_1");
                           GlobalVariableDel(gs_220 + OrderTicket() + "_2");
                        }
                     }
                  }
               }
            }
         }
      }
   }
   return (0);
}

int fGetParentTicket(string as_0) {
   int li_12;
   int li_8 = StringFind(as_0, "from");
   if (li_8 >= 0) {
      li_12 = StringFind(as_0, "#");
      if (li_12 > li_8) return (StrToInteger(StringSubstr(as_0, li_12 + 1, StringLen(as_0) - li_12 - 1)));
   }
   return (0);
}

int fOrderCloseMarket(bool ai_0 = TRUE, bool ai_4 = TRUE) {
   int l_error_16;
   int li_ret_8 = 0;
   for (int l_pos_12 = OrdersTotal() - 1; l_pos_12 >= 0; l_pos_12--) {
      if (OrderSelect(l_pos_12, SELECT_BY_POS, MODE_TRADES)) {
         if (fOrderThisExpertSelected()) {
            if (ai_0) {
               if (OrderType() == OP_BUY) {
                  RefreshRates();
                  if (!IsTradeContextBusy()) {
                     if (!OrderClose(OrderTicket(), OrderLots(), ND(Bid), Slippage, CLR_NONE)) {
                        l_error_16 = GetLastError();
                        Print("Error close BUY " + OrderTicket() + " " + fMyErDesc(l_error_16));
                        li_ret_8 = -1;
                     }
                  } else {
                     if (TimeCurrent() > g_datetime_304 + 20) {
                        g_datetime_304 = TimeCurrent();
                        Print("Need close BUY " + OrderTicket() + ". Trade Context Busy");
                     }
                     return (-2);
                  }
               }
            }
            if (ai_4) {
               if (OrderType() == OP_SELL) {
                  RefreshRates();
                  if (!IsTradeContextBusy()) {
                     if (!OrderClose(OrderTicket(), OrderLots(), ND(Ask), Slippage, CLR_NONE)) {
                        l_error_16 = GetLastError();
                        Print("Error close SELL " + OrderTicket() + " " + fMyErDesc(l_error_16));
                        li_ret_8 = -1;
                     }
                  } else {
                     if (TimeCurrent() > g_datetime_308 + 20) {
                        g_datetime_308 = TimeCurrent();
                        Print("Need close SELL " + OrderTicket() + ". Trade Context Busy");
                     }
                     return (-2);
                  }
               }
            }
         }
      }
   }
   return (li_ret_8);
}

int fModifyOrder(int a_ticket_0, double ad_4, double ad_12, double ad_20, int a_datetime_28 = 0) {
   int l_error_32;
   if (!IsTradeContextBusy()) {
      if (!OrderModify(a_ticket_0, ND(ad_4), ND(ad_12), ND(ad_20), a_datetime_28, CLR_NONE)) {
         l_error_32 = GetLastError();
         Print("Error modify order " + a_ticket_0 + ". " + fMyErDesc(l_error_32));
         return (-1);
      }
      return (0);
   }
   if (g_datetime_312 != iTime(NULL, 0, 0)) {
      g_datetime_312 = iTime(NULL, 0, 0);
      Print("Need modify order " + a_ticket_0 + ". Trade Context Busy");
   }
   return (-2);
}

int fCloseSelectedOrder(double ad_0) {
   int l_error_8;
   if (!IsTradeContextBusy()) {
      if (!OrderClose(OrderTicket(), ND(ad_0), ND(OrderClosePrice()), Slippage, CLR_NONE)) {
         l_error_8 = GetLastError();
         Print("Error part close order " + OrderTicket() + ". " + fMyErDesc(l_error_8));
         return (-1);
      }
      return (0);
   }
   if (g_datetime_316 != iTime(NULL, 0, 0)) {
      g_datetime_316 = iTime(NULL, 0, 0);
      Print("Need part close order " + OrderTicket() + ". Trade Context Busy");
   }
   return (-2);
}

bool fOrderThisExpertSelected() {
   if (OrderSymbol() == Symbol()) {
      if (OrderMagicNumber() == Magic_N || Magic_N == -1) {
         switch (gi_92) {
         case 0:
            return (TRUE);
         case 1:
            if (StringFind(OrderComment(), gs_84, 0) == 0) return (TRUE);
            break;
         case 2:
            if (StringFind(OrderComment(), gs_84, 0) >= 0) return (TRUE);
            break;
         case 2:
            if (StringFind(OrderComment(), gs_84, 0) == StringLen(OrderComment()) - StringLen(gs_84)) return (TRUE);
         }
      }
   }
   return (FALSE);
}

double ND(double ad_0) {
   return (NormalizeDouble(ad_0, Digits));
}

void fLevels() {
   double l_ihigh_4;
   double l_ilow_12;
   double ld_28;
   gd_236 = 0;
   int li_0 = 0;
   for (int li_20 = 0; li_20 < iBars(NULL, TimeFrame); li_20++) {
      switch (li_0) {
      case 0:
         if (!fTimeInZone(StartHour, gi_164, EndHour, gi_172, iTime(NULL, TimeFrame, li_20))) li_0 = 1;
         break;
      case 1:
         if (fTimeInZone(StartHour, gi_164, EndHour, gi_172, iTime(NULL, TimeFrame, li_20))) {
            li_0 = 2;
            l_ihigh_4 = iHigh(NULL, TimeFrame, li_20);
            l_ilow_12 = iLow(NULL, TimeFrame, li_20);
         }
         break;
      case 2:
         if (fTimeInZone(StartHour, gi_164, EndHour, gi_172, iTime(NULL, TimeFrame, li_20))) {
            li_0 = 2;
            l_ihigh_4 = MathMax(l_ihigh_4, iHigh(NULL, TimeFrame, li_20));
            l_ilow_12 = MathMin(l_ilow_12, iLow(NULL, TimeFrame, li_20));
         } else {
            gd_236 = (l_ihigh_4 + l_ilow_12) / 2.0;
            ld_28 = l_ihigh_4 - l_ilow_12;
            gd_296 = ld_28;
            gd_268 = l_ihigh_4 - ld_28 * Fibo_K_1;
            gd_276 = l_ihigh_4 - ld_28 * Fibo_K_2;
            gd_284 = l_ihigh_4 - ld_28 * Fibo_K_3;
            gd_244 = l_ilow_12 + ld_28 * Fibo_K_1;
            gd_252 = l_ilow_12 + ld_28 * Fibo_K_2;
            gd_260 = l_ilow_12 + ld_28 * Fibo_K_3;
            li_0 = 3;
         }
      }
      if (li_0 == 3) break;
   }
}

bool fTimeInZone(int ai_0, int ai_4, int ai_8, int ai_12, int ai_16) {
   int li_20 = 3600 * ai_0 + 60 * ai_4;
   int li_24 = 3600 * ai_8 + 60 * ai_12;
   int li_28 = ai_16 - 86400 * (ai_16 / 86400);
   if (li_20 <= li_24) {
      if (li_28 >= li_20 && li_28 < li_24) return (TRUE);
   } else
      if (li_28 >= li_20 || li_28 < li_24) return (TRUE);
   return (FALSE);
}

string fMyErDesc(int ai_0) {
   string ls_4 = "Err Num: " + ai_0 + " - ";
   switch (ai_0) {
   case 0:
      return (ls_4 + "NO ERROR");
   case 1:
      return (ls_4 + "NO RESULT");
   case 2:
      return (ls_4 + "COMMON ERROR");
   case 3:
      return (ls_4 + "INVALID TRADE PARAMETERS");
   case 4:
      return (ls_4 + "SERVER BUSY");
   case 5:
      return (ls_4 + "OLD VERSION");
   case 6:
      return (ls_4 + "NO CONNECTION");
   case 7:
      return (ls_4 + "NOT ENOUGH RIGHTS");
   case 8:
      return (ls_4 + "TOO FREQUENT REQUESTS");
   case 9:
      return (ls_4 + "MALFUNCTIONAL TRADE");
   case 64:
      return (ls_4 + "ACCOUNT DISABLED");
   case 65:
      return (ls_4 + "INVALID ACCOUNT");
   case 128:
      return (ls_4 + "TRADE TIMEOUT");
   case 129:
      return (ls_4 + "INVALID PRICE");
   case 130:
      return (ls_4 + "INVALID STOPS");
   case 131:
      return (ls_4 + "INVALID TRADE VOLUME");
   case 132:
      return (ls_4 + "MARKET CLOSED");
   case 133:
      return (ls_4 + "TRADE DISABLED");
   case 134:
      return (ls_4 + "NOT ENOUGH MONEY");
   case 135:
      return (ls_4 + "PRICE CHANGED");
   case 136:
      return (ls_4 + "OFF QUOTES");
   case 137:
      return (ls_4 + "BROKER BUSY");
   case 138:
      return (ls_4 + "REQUOTE");
   case 139:
      return (ls_4 + "ORDER LOCKED");
   case 140:
      return (ls_4 + "LONG POSITIONS ONLY ALLOWED");
   case 141:
      return (ls_4 + "TOO MANY REQUESTS");
   case 145:
      return (ls_4 + "TRADE MODIFY DENIED");
   case 146:
      return (ls_4 + "TRADE CONTEXT BUSY");
   case 147:
      return (ls_4 + "TRADE EXPIRATION DENIED");
   case 148:
      return (ls_4 + "TRADE TOO MANY ORDERS");
   case 4000:
      return (ls_4 + "NO MQLERROR");
   case 4001:
      return (ls_4 + "WRONG FUNCTION POINTER");
   case 4002:
      return (ls_4 + "ARRAY INDEX OUT OF RANGE");
   case 4003:
      return (ls_4 + "NO MEMORY FOR FUNCTION CALL STACK");
   case 4004:
      return (ls_4 + "RECURSIVE STACK OVERFLOW");
   case 4005:
      return (ls_4 + "NOT ENOUGH STACK FOR PARAMETER");
   case 4006:
      return (ls_4 + "NO MEMORY FOR PARAMETER STRING");
   case 4007:
      return (ls_4 + "NO MEMORY FOR TEMP STRING");
   case 4008:
      return (ls_4 + "NOT INITIALIZED STRING");
   case 4009:
      return (ls_4 + "NOT INITIALIZED ARRAYSTRING");
   case 4010:
      return (ls_4 + "NO MEMORY FOR ARRAYSTRING");
   case 4011:
      return (ls_4 + "TOO LONG STRING");
   case 4012:
      return (ls_4 + "REMAINDER FROM ZERO DIVIDE");
   case 4013:
      return (ls_4 + "ZERO DIVIDE");
   case 4014:
      return (ls_4 + "UNKNOWN COMMAND");
   case 4015:
      return (ls_4 + "WRONG JUMP");
   case 4016:
      return (ls_4 + "NOT INITIALIZED ARRAY");
   case 4017:
      return (ls_4 + "DLL CALLS NOT ALLOWED");
   case 4018:
      return (ls_4 + "CANNOT LOAD LIBRARY");
   case 4019:
      return (ls_4 + "CANNOT CALL FUNCTION");
   case 4020:
      return (ls_4 + "EXTERNAL EXPERT CALLS NOT ALLOWED");
   case 4021:
      return (ls_4 + "NOT ENOUGH MEMORY FOR RETURNED STRING");
   case 4022:
      return (ls_4 + "SYSTEM BUSY");
   case 4050:
      return (ls_4 + "INVALID FUNCTION PARAMETERS COUNT");
   case 4051:
      return (ls_4 + "INVALID FUNCTION PARAMETER VALUE");
   case 4052:
      return (ls_4 + "STRING FUNCTION INTERNAL ERROR");
   case 4053:
      return (ls_4 + "SOME ARRAY ERROR");
   case 4054:
      return (ls_4 + "INCORRECT SERIES ARRAY USING");
   case 4055:
      return (ls_4 + "CUSTOM INDICATOR ERROR");
   case 4056:
      return (ls_4 + "INCOMPATIBLE ARRAYS");
   case 4057:
      return (ls_4 + "GLOBAL VARIABLES PROCESSING ERROR");
   case 4058:
      return (ls_4 + "GLOBAL VARIABLE NOT FOUND");
   case 4059:
      return (ls_4 + "FUNCTION NOT ALLOWED IN TESTING MODE");
   case 4060:
      return (ls_4 + "FUNCTION NOT CONFIRMED");
   case 4061:
      return (ls_4 + "SEND MAIL ERROR");
   case 4062:
      return (ls_4 + "STRING PARAMETER EXPECTED");
   case 4063:
      return (ls_4 + "INTEGER PARAMETER EXPECTED");
   case 4064:
      return (ls_4 + "DOUBLE PARAMETER EXPECTED");
   case 4065:
      return (ls_4 + "ARRAY AS PARAMETER EXPECTED");
   case 4066:
      return (ls_4 + "HISTORY WILL UPDATED");
   case 4067:
      return (ls_4 + "TRADE ERROR");
   case 4099:
      return (ls_4 + "END OF FILE");
   case 4100:
      return (ls_4 + "SOME FILE ERROR");
   case 4101:
      return (ls_4 + "WRONG FILE NAME");
   case 4102:
      return (ls_4 + "TOO MANY OPENED FILES");
   case 4103:
      return (ls_4 + "CANNOT OPEN FILE");
   case 4104:
      return (ls_4 + "INCOMPATIBLE ACCESS TO FILE");
   case 4105:
      return (ls_4 + "NO ORDER SELECTED");
   case 4106:
      return (ls_4 + "UNKNOWN SYMBOL");
   case 4107:
      return (ls_4 + "INVALID PRICE PARAM");
   case 4108:
      return (ls_4 + "INVALID TICKET");
   case 4109:
      return (ls_4 + "TRADE NOT ALLOWED");
   case 4110:
      return (ls_4 + "LONGS  NOT ALLOWED");
   case 4111:
      return (ls_4 + "SHORTS NOT ALLOWED");
   case 4200:
      return (ls_4 + "OBJECT ALREADY EXISTS");
   case 4201:
      return (ls_4 + "UNKNOWN OBJECT PROPERTY");
   case 4202:
      return (ls_4 + "OBJECT DOES NOT EXIST");
   case 4203:
      return (ls_4 + "UNKNOWN OBJECT TYPE");
   case 4204:
      return (ls_4 + "NO OBJECT NAME");
   case 4205:
      return (ls_4 + "OBJECT COORDINATES ERROR");
   case 4206:
      return (ls_4 + "NO SPECIFIED SUBWINDOW");
   case 4207:
      return (ls_4 + "SOME OBJECT ERROR");
   }
   return (ls_4 + "WRONG ERR NUM");
}

void fObjHLine(string a_name_0, double a_price_8, color a_color_16 = 255, int a_width_20 = 1, int a_window_24 = 0, int a_style_28 = 0, bool a_bool_32 = FALSE) {
   if (ObjectFind(a_name_0) != a_window_24) ObjectCreate(a_name_0, OBJ_HLINE, a_window_24, 0, a_price_8);
   ObjectSet(a_name_0, OBJPROP_PRICE1, a_price_8);
   ObjectSet(a_name_0, OBJPROP_COLOR, a_color_16);
   ObjectSet(a_name_0, OBJPROP_WIDTH, a_width_20);
   ObjectSet(a_name_0, OBJPROP_BACK, a_bool_32);
   ObjectSet(a_name_0, OBJPROP_STYLE, a_style_28);
}