
#property copyright "Wim. All rights reserved."
#property link      "http://www.forexscanners.com"

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Green
#property indicator_color2 Blue

string gs_unused_76 = "Last Modified: 2008.07.21 2:30";
extern bool AlertOn = TRUE;
extern bool EmailOn = FALSE;
extern bool SnapShotOn = TRUE;
extern int BarsCount = 5000;
double RedMax;
double RedMin;
int RedTrend;
int RedPeriods[16] = {125, 130, 135, 140, 145, 150, 155, 160, 165, 170, 175, 180, 185, 190, 195, 200};
double GreenMax;
double GreenMin;
int GreenTrend;
int GreenPeriods[12] = {78, 82, 86, 90, 94, 98, 102, 106, 110, 114, 118, 122};
double BlueMax;
double BlueMin;
int BlueTrend;
int BluePeriods[11] = {44, 47, 50, 53, 56, 59, 62, 65, 68, 71, 74};
double OrangeMax;
double OrangeMin;
int OrangeTrend;
int OrangePeriods[13] = {17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41};
double YellowMax;
double YellowMin;
int YellowTrend;
int YellowPeriods[14] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
int SignalTrend;
int SlopeTrend;
int MACDTrend;
int LaguerreTrend;
int InvTrend;
int InvestorTrend;
int TradingIndicator;
int gi_unused_248 = 233;
int gi_unused_252 = 234;
int gi_unused_256 = 32768;
int gi_unused_260 = 16711680;
int gi_unused_264 = 4;
int gi_unused_268 = 4;
int gi_unused_272 = 0;
int gi_unused_276 = 20;
int g_time_280 = 0;
double ShortBuff[];
double LongBuff[];
bool gi_292 = TRUE;
double gd_296 = 0.0;
double gd_304 = 0.0;
double gd_312 = 0.0;
double gd_320 = 0.0;
double gd_328 = 0.0;
double gd_336 = 0.0;
double gd_344 = 0.0;
double gd_352 = 0.0;
extern int expiration_date = D'08.10.2010 06:00';
string gs_364 = "Your trail/subscription period is over! Please go to http://www.forexscanners.com to subscribe.";
int count = 0;
int g_time_376 = 0;

int init() {
   SetIndexStyle(0, DRAW_ARROW, STYLE_SOLID, 3);
   SetIndexStyle(1, DRAW_ARROW, STYLE_SOLID, 3);
   SetIndexArrow(0, 233);
   SetIndexArrow(1, 234);
   SetIndexLabel(0, "BUY");
   SetIndexLabel(1, "SELL");
   SetIndexBuffer(0, LongBuff);
   SetIndexBuffer(1, ShortBuff);
   DeletePrints();
   DrawFlat();
   Draw_Pivots();
   switch (Period()) {
   case PERIOD_M1:
      gi_unused_272 = 5;
      break;
   case PERIOD_M5:
      gi_unused_272 = 7;
      break;
   case PERIOD_M15:
      gi_unused_272 = 10;
      break;
   case PERIOD_M30:
      gi_unused_272 = 15;
      break;
   case PERIOD_H1:
      gi_unused_272 = 20;
      break;
   case PERIOD_H4:
      gi_unused_272 = 30;
      break;
   case PERIOD_D1:
      gi_unused_272 = 80;
      break;
   case PERIOD_W1:
      gi_unused_272 = 150;
      break;
   case PERIOD_MN1:
      gi_unused_272 = 250;
   }
   SignalTrend = 0;
   SlopeTrend = 0;
   MACDTrend = 0;
   LaguerreTrend = 0;
   InvestorTrend = 0;
   InvTrend = 0;
   TradingIndicator = 0;
   NewBar2();
   CalculateIndicators(1);
   return (0);
}

int deinit() {
   DeletePivots();
   DeletePrints();
   return (0);
}

int start() {
   if (TimeCurrent() >= expiration_date) {
      Alert(gs_364);
      return (0);
   }
   Draw_Pivots();
   int li_0 = 5;
   switch (Period()) {
   case PERIOD_M1:
      li_0 = 10;
      break;
   case PERIOD_M5:
      li_0 = 15;
      break;
   case PERIOD_M15:
      li_0 = 25;
      break;
   case PERIOD_M30:
      li_0 = 0;
      break;
   case PERIOD_H1:
      li_0 = 250;
      break;
   case PERIOD_H4:
      li_0 = 0;
      break;
   case PERIOD_D1:
      li_0 = 1000;
      break;
   case PERIOD_W1:
      li_0 = 1000;
      break;
   case PERIOD_MN1:
      li_0 = 0;
   }
   if (NewBar2()) {
      CalculateIndicators(1);
      if (TradingIndicator == 1 && Close[0] < gd_320 && MA_Distance(0) <= li_0) {
         g_time_280 = Time[0];
         DeletePrints();
         DrawBuy();
         LongBuff[1] = Low[1] - 5.0 * Point;
         if (AlertOn) Alert("ForexScanner LT " + " " + Symbol() + " " + Period() + "Min -  All Indicators UP - GO LONG");
         if (EmailOn) SendMail("STF Long Alert " + Symbol(), Symbol() + " " + Period() + "Min -  All Indicators UP - GO LONG");
         if (SnapShotOn) WindowScreenShot("ForexScannerLT " + Year() + "\\TF " + Month() + "" + Day() + " " + Symbol() + " GO LONG @M" + Period() + " TIME=" + Hour() + "-" + Minute() + ".gif", 800, 600);
      } else {
         if (TradingIndicator == 2 && Close[0] > gd_344 && MA_Distance(0) <= li_0) {
            g_time_280 = Time[0];
            DeletePrints();
            DrawSell();
            ShortBuff[1] = High[1] + 5.0 * Point;
            if (AlertOn) Alert("ForexScanner LT " + " " + Symbol() + " " + Period() + "Min -  All Indicators DOWN - GO SHORT");
            if (EmailOn) SendMail("STF Short Alert " + Symbol(), Symbol() + " " + Period() + "Min -  All Indicators DOWN - GO SHORT");
            if (SnapShotOn) WindowScreenShot("ForexScannerLT " + Year() + "\\TF " + Month() + "" + Day() + " " + Symbol() + " GO SHORT @M" + Period() + " TIME=" + Hour() + "-" + Minute() + ".gif", 800, 600);
         } else {
            if (TradingIndicator == 0) {
               DeletePrints();
               DrawFlat();
            }
         }
      }
   }
   int ind_count = IndicatorCounted();
   if (ind_count > 0) ind_count--;
   int bars = Bars - ind_count;
   if (bars > BarsCount) bars = BarsCount;
   if (gi_292) {
      for (int l = 2; l < bars; l++) {
         CalculateIndicators(l);
         if (TradingIndicator == 1 && MA_Distance(l) <= li_0) LongBuff[l] = Low[l] - 5.0 * Point;
         if (TradingIndicator == 2 && MA_Distance(l) <= li_0) ShortBuff[l] = High[l] + 5.0 * Point;
      }
      gi_292 = FALSE;
   }
   CalculateIndicators(1);
   int GTr = GetTrend(1);
   count = 0;
   DisplayAlerts(0, "FLAT");
   if (GTr == 1) {
      count = 0;
      if (SignalTrend == 1) count++;
      if (LaguerreTrend == 1) count++;
      if (InvTrend == 1) count++;
      if (MA_Distance(0) <= li_0) count++;
      DisplayAlerts(count, "SCAN LONG");
   }
   if (GTr == 2) {
      count = 0;
      if (SignalTrend == 2) count++;
      if (LaguerreTrend == 2) count++;
      if (InvTrend == 2) count++;
      if (MA_Distance(0) <= li_0) count++;
      DisplayAlerts(count, "SCAN SHORT");
   }
   return (0);
}

void CalculateIndicators(int shift) {
   SignalTrend = 0;
   SlopeTrend = 0;
   MACDTrend = 0;
   LaguerreTrend = 0;
   InvestorTrend = 0;
   InvTrend = 0;
   TradingIndicator = 0;
   double f1 = iMA(NULL, 0, 4, 0, MODE_EMA, PRICE_CLOSE, shift);
   double s1 = iMA(NULL, 0, 8, 0, MODE_EMA, PRICE_CLOSE, shift);
   double f2 = iMA(NULL, 0, 4, 0, MODE_EMA, PRICE_CLOSE, shift + 1);
   double s2 = iMA(NULL, 0, 8, 0, MODE_EMA, PRICE_CLOSE, shift + 1);
   if (f1 > s1 && f2 < s2) SignalTrend = 1;
   else
      if (f1 < s1 && f2 > s2) SignalTrend = 2;
   if (SignalTrend == 0) {
      f1 = iMA(NULL, 0, 4, 0, MODE_EMA, PRICE_CLOSE, shift + 1);
      s1 = iMA(NULL, 0, 8, 0, MODE_EMA, PRICE_CLOSE, shift + 1);
      f2 = iMA(NULL, 0, 4, 0, MODE_EMA, PRICE_CLOSE, shift + 2);
      s2 = iMA(NULL, 0, 8, 0, MODE_EMA, PRICE_CLOSE, shift + 2);
      if (f1 > s1 && f2 < s2) SignalTrend = 1;
      else
         if (f1 < s1 && f2 > s2) SignalTrend = 2;
   }
   double up = iCustom(NULL, 0, "Slope Direction Line", 80, 3, 0, shift);
   double dn = iCustom(NULL, 0, "Slope Direction Line", 80, 3, 1, shift);
   if (up == EMPTY_VALUE && dn != EMPTY_VALUE) SlopeTrend = 2;
   else
      if (dn == EMPTY_VALUE && up != EMPTY_VALUE) SlopeTrend = 1;
   double MACD0 = iMACD(NULL, 0, 5, 35, 5, PRICE_CLOSE, MODE_MAIN, shift);
   if (MACD0 > 0.0) MACDTrend = 1;
   else
      if (MACD0 < 0.0) MACDTrend = 2;
   double L0 = iCustom(NULL, 0, "Laguerre", 0.66, 9500, 0, shift);
   double L1 = iCustom(NULL, 0, "Laguerre", 0.66, 9500, 0, shift + 1);
   if (L0 <= 0.15 && L1 < 0.15) LaguerreTrend = 1;
   else
      if (L0 >= 0.75 && L1 > 0.75) LaguerreTrend = 2;
   if (LaguerreTrend == 0) {
      L0 = iCustom(NULL, 0, "Laguerre", 0.66, 9500, 0, shift + 1);
      L1 = iCustom(NULL, 0, "Laguerre", 0.66, 9500, 0, shift + 2);
      if (L0 <= 0.15 && L1 < 0.15) LaguerreTrend = 1;
      else
         if (L0 >= 0.75 && L1 > 0.75) LaguerreTrend = 2;
   }
   CalculateGuppy(shift);
   if (SignalTrend == 1 && LaguerreTrend == 1 && InvTrend == 1) {
      TradingIndicator = 1;
      return;
   }
   if (SignalTrend == 2 && LaguerreTrend == 2 && InvTrend == 2) TradingIndicator = 2;
}

int CalculateGuppy(int shift) {
   double curr;
   double prev;
   RedTrend = 0;
   RedMin = 0;
   RedMax = 0;
   GreenTrend = 0;
   GreenMin = 0;
   GreenMax = 0;
   BlueTrend = 0;
   BlueMin = 0;
   BlueMax = 0;
   OrangeTrend = 0;
   OrangeMin = 0;
   OrangeMax = 0;
   YellowTrend = 0;
   YellowMin = 0;
   YellowMax = 0;
   InvestorTrend = 0;
   InvTrend = 0;
   int count = 0;
   for (int i = 0; i < 16; i++) {
      curr = iMA(NULL, 0, RedPeriods[i], 0, MODE_EMA, PRICE_CLOSE, shift);
      prev = iMA(NULL, 0, RedPeriods[i], 0, MODE_EMA, PRICE_CLOSE, shift + 1);
      if (RedMax == 0.0 || curr > RedMax) RedMax = curr;
      if (RedMin == 0.0 || curr < RedMin) RedMin = curr;
      if (curr > prev) count++;
      else
         if (curr < prev) count--;
   }
   if (count == 16) RedTrend = 1;
   else {
      if (count == -16) RedTrend = 2;
      else RedTrend = 0;
   }
   count = 0;
   for (i = 0; i < 12; i++) {
      curr = iMA(NULL, 0, GreenPeriods[i], 0, MODE_EMA, PRICE_CLOSE, shift);
      prev = iMA(NULL, 0, GreenPeriods[i], 0, MODE_EMA, PRICE_CLOSE, shift + 1);
      if (GreenMax == 0.0 || curr > GreenMax) GreenMax = curr;
      if (GreenMin == 0.0 || curr < GreenMin) GreenMin = curr;
      if (curr > prev) count++;
      else
         if (curr < prev) count--;
   }
   if (count == 12) GreenTrend = 1;
   else {
      if (count == -12) GreenTrend = 2;
      else GreenTrend = 0;
   }
   count = 0;
   for (i = 0; i < 11; i++) {
      curr = iMA(NULL, 0, BluePeriods[i], 0, MODE_EMA, PRICE_CLOSE, shift);
      prev = iMA(NULL, 0, BluePeriods[i], 0, MODE_EMA, PRICE_CLOSE, shift + 1);
      if (BlueMax == 0.0 || curr > BlueMax) BlueMax = curr;
      if (BlueMin == 0.0 || curr < BlueMin) BlueMin = curr;
      if (curr > prev) count++;
      else
         if (curr < prev) count--;
   }
   if (count == 11) BlueTrend = 1;
   else {
      if (count == -11) BlueTrend = 2;
      else BlueTrend = 0;
   }
   count = 0;
   for (i = 0; i < 13; i++) {
      curr = iMA(NULL, 0, OrangePeriods[i], 0, MODE_EMA, PRICE_CLOSE, shift);
      prev = iMA(NULL, 0, OrangePeriods[i], 0, MODE_EMA, PRICE_CLOSE, shift + 1);
      if (OrangeMax == 0.0 || curr > OrangeMax) OrangeMax = curr;
      if (OrangeMin == 0.0 || curr < OrangeMin) OrangeMin = curr;
      if (curr > prev) count++;
      else
         if (curr < prev) count--;
   }
   if (count == 13) OrangeTrend = 1;
   else {
      if (count == -13) OrangeTrend = 2;
      else OrangeTrend = 0;
   }
   count = 0;
   for (i = 0; i < 14; i++) {
      curr = iMA(NULL, 0, YellowPeriods[i], 0, MODE_EMA, PRICE_CLOSE, shift);
      prev = iMA(NULL, 0, YellowPeriods[i], 0, MODE_EMA, PRICE_CLOSE, shift + 1);
      if (YellowMax == 0.0 || curr > YellowMax) YellowMax = curr;
      if (YellowMin == 0.0 || curr < YellowMin) YellowMin = curr;
      if (curr > prev) count++;
      else
         if (curr < prev) count--;
   }
   if (count == 14) YellowTrend = 1;
   else {
      if (count == -14) YellowTrend = 2;
      else YellowTrend = 0;
   }
   if (RedTrend == 1 && GreenTrend == 1 && RedMax < GreenMin) InvestorTrend = 1;
   else {
      if (RedTrend == 2 && GreenTrend == 2 && RedMin > GreenMax) InvestorTrend = 2;
      else InvestorTrend = 0;
   }
   if (InvestorTrend == 1) InvTrend = 1;
   else {
      if (InvestorTrend == 2) InvTrend = 2;
      else InvTrend = 0;
   }
   return (0);
}

int GetTrend(int shift) {
   double curr;
   double prev;
   RedTrend = 0;
   RedMin = 0;
   RedMax = 0;
   GreenTrend = 0;
   GreenMin = 0;
   GreenMax = 0;
   InvestorTrend = 0;
   int count = 0;
   for (int i = 0; i < 16; i++) {
      curr = iMA(NULL, 0, RedPeriods[i], 0, MODE_EMA, PRICE_CLOSE, shift);
      prev = iMA(NULL, 0, RedPeriods[i], 0, MODE_EMA, PRICE_CLOSE, shift + 1);
      if (RedMax == 0.0 || curr > RedMax) RedMax = curr;
      if (RedMin == 0.0 || curr < RedMin) RedMin = curr;
      if (curr > prev) count++;
      else
         if (curr < prev) count--;
   }
   RedTrend = 0;
   if (count == 16) RedTrend = 1;
   if (count == -16) RedTrend = 2;
   int l_count_28 = 0;
   for (i = 0; i < 12; i++) {
      curr = iMA(NULL, 0, GreenPeriods[i], 0, MODE_EMA, PRICE_CLOSE, shift);
      prev = iMA(NULL, 0, GreenPeriods[i], 0, MODE_EMA, PRICE_CLOSE, shift + 1);
      if (GreenMax == 0.0 || curr > GreenMax) GreenMax = curr;
      if (GreenMin == 0.0 || curr < GreenMin) GreenMin = curr;
      if (curr > prev) l_count_28++;
      else
         if (curr < prev) l_count_28--;
   }
   GreenTrend = 0;
   if (l_count_28 == 12) GreenTrend = 1;
   if (l_count_28 == -12) GreenTrend = 2;
   if (RedTrend == 1 && GreenTrend == 1 && RedMax < GreenMin) return (1);
   if (RedTrend == 2 && GreenTrend == 2 && RedMin > GreenMax) return (2);
   return (0);
}

bool NewBar2(int shift = 0) {
   if (Time[shift] != g_time_376) {
      g_time_376 = Time[0];
      if (g_time_280 == 0) return (TRUE);
      if (Time[shift] - 60 * Period() == g_time_280) return (FALSE);
      return (TRUE);
   }
   return (FALSE);
}

void CPrint(int shift, int ai_4, string a_text_8, int a_fontsize_16 = 10, color a_color_20 = 65535, int ai_24 = 5, int a_y_28 = 20, int ai_32 = 80, int ai_36 = 15) {
   bool li_40 = FALSE;
   string ls_44 = "CPrint_Line" + shift + "_" + ai_4;
   for (int l_objs_total_52 = ObjectsTotal(); l_objs_total_52 >= 0; l_objs_total_52--)
      if (StringFind(ObjectName(l_objs_total_52), ls_44, 0) > -1) li_40 = TRUE;
   if (li_40) {
      ObjectSetText(ls_44, a_text_8, a_fontsize_16, "Arial Bold", a_color_20);
      ObjectsRedraw();
      return;
   }
   ObjectCreate(ls_44, OBJ_LABEL, 0, 0, 0);
   ObjectSetText(ls_44, a_text_8, a_fontsize_16, "Arial Bold", a_color_20);
   ObjectSet(ls_44, OBJPROP_XDISTANCE, ai_24 + (ai_4 - 1) * ai_32);
   if (shift == 1) {
      ObjectSet(ls_44, OBJPROP_YDISTANCE, a_y_28);
      return;
   }
   ObjectSet(ls_44, OBJPROP_YDISTANCE, a_y_28 + ai_36 * (shift - 1));
}

void DeletePrints() {
   string l_name_4;
   int li_unused_0 = ObjectsTotal();
   for (int ind_count = ObjectsTotal() - 1; ind_count >= 0; ind_count--) {
      l_name_4 = ObjectName(ind_count);
      if (StringFind(l_name_4, "CPrint_", 0) > -1) ObjectDelete(l_name_4);
      if (StringFind(l_name_4, "L_", 0) > -1) ObjectDelete(l_name_4);
      ObjectsRedraw();
   }
}

void DrawBuy() {
   CPrint(2, 1, "Trade Signal:", 18, Green, 5, 10);
   CPrint(2, 3, "BUY", 18, Green, 5, 10, 77);
}

void DrawSell() {
   CPrint(2, 1, "Trade Signal:", 18, Red, 5, 10);
   CPrint(2, 3, "SELL", 18, Red, 5, 10, 77);
}

void DrawFlat() {
   CPrint(2, 1, "Trade Signal:", 18, DimGray, 5, 10);
   CPrint(2, 3, "FLAT", 18, DimGray, 5, 10, 77);
}

void DisplayAlerts(int shift, string as_4) {
   CPrint2(4, 1, "Trade Conditions: " + shift + "/4 " + as_4, 10, DimGray, 5, 25);
   CPrint2(5, 1, "Average Daily Range: " + CalcDailyRange() + " pips", 10, DimGray, 5, 25);
   CPrint2(7, 1, "ForexScannerLT: Mid & Long Term", 8, DimGray, 5, 25);
   CPrint2(8, 1, "http://www.forexscanners.com", 8, DimGray, 5, 25);
}

void CPrint2(int shift, int ai_4, string a_text_8, int a_fontsize_16 = 10, color a_color_20 = 65535, int ai_24 = 5, int a_y_28 = 20, int ai_32 = 80, int ai_36 = 15) {
   bool li_40 = FALSE;
   string ls_44 = "CPrint_Line" + shift + "_" + ai_4;
   for (int l_objs_total_52 = ObjectsTotal(); l_objs_total_52 >= 0; l_objs_total_52--)
      if (StringFind(ObjectName(l_objs_total_52), ls_44, 0) > -1) li_40 = TRUE;
   if (li_40) {
      ObjectSetText(ls_44, a_text_8, a_fontsize_16, "Arial", a_color_20);
      ObjectsRedraw();
      return;
   }
   ObjectCreate(ls_44, OBJ_LABEL, 0, 0, 0);
   ObjectSetText(ls_44, a_text_8, a_fontsize_16, "Arial", a_color_20);
   ObjectSet(ls_44, OBJPROP_XDISTANCE, ai_24 + (ai_4 - 1) * ai_32);
   if (shift == 1) {
      ObjectSet(ls_44, OBJPROP_YDISTANCE, a_y_28);
      return;
   }
   ObjectSet(ls_44, OBJPROP_YDISTANCE, a_y_28 + ai_36 * (shift - 1));
}

void Draw_Pivots() {
   double lda_0[1][6];
   double ld_4;
   double ld_12;
   double ld_20;
   ArrayCopyRates(lda_0, Symbol(), PERIOD_D1);
   if (DayOfWeek() == 1) {
      if (TimeDayOfWeek(iTime(Symbol(), PERIOD_D1, 1)) == 5) {
         ld_4 = lda_0[1][4];
         ld_12 = lda_0[1][3];
         ld_20 = lda_0[1][2];
      } else {
         for (int li_28 = 5; li_28 >= 0; li_28--) {
            if (TimeDayOfWeek(iTime(Symbol(), PERIOD_D1, li_28)) == 5) {
               ld_4 = lda_0[li_28][4];
               ld_12 = lda_0[li_28][3];
               ld_20 = lda_0[li_28][2];
            }
         }
      }
   } else {
      ld_4 = lda_0[1][4];
      ld_12 = lda_0[1][3];
      ld_20 = lda_0[1][2];
   }
   gd_296 = ld_12 - ld_20;
   gd_304 = (ld_12 + ld_20 + ld_4) / 3.0;
   gd_312 = ld_12 + 2.0 * (gd_304 - ld_20);
   gd_320 = gd_304 + (2.0 * gd_304 - ld_20 - (2.0 * gd_304 - ld_12));
   gd_328 = 2.0 * gd_304 - ld_20;
   gd_336 = 2.0 * gd_304 - ld_12;
   gd_344 = gd_304 - (2.0 * gd_304 - ld_20 - (2.0 * gd_304 - ld_12));
   gd_352 = ld_20 - 2.0 * (ld_12 - gd_304);
   drawLine(gd_312, "R3", DarkGreen, 0, 0);
   drawLabel("Resistance 3", gd_312, DarkGreen);
   drawLine(gd_320, "R2", DarkGreen, 0, 0);
   drawLabel("Resistance 2", gd_320, DarkGreen);
   drawLine(gd_328, "R1", DarkGreen, 0, 0);
   drawLabel("Resistance 1", gd_328, DarkGreen);
   drawLine(gd_304, "PIVIOT", DimGray, 1, 1);
   drawLabel("Piviot level", gd_304, DimGray);
   drawLine(gd_336, "S1", Maroon, 0, 0);
   drawLabel("Support 1", gd_336, Red);
   drawLine(gd_344, "S2", Maroon, 0, 0);
   drawLabel("Support 2", gd_344, Red);
   drawLine(gd_352, "S3", Maroon, 0, 0);
   drawLabel("Support 3", gd_352, Red);
}

void drawLabel(string a_name_0, double a_price_8, color a_color_16) {
   if (ObjectFind(a_name_0) != 0) {
      ObjectCreate(a_name_0, OBJ_TEXT, 0, Time[10], a_price_8);
      ObjectSetText(a_name_0, a_name_0, 8, "Arial", CLR_NONE);
      ObjectSet(a_name_0, OBJPROP_COLOR, a_color_16);
      return;
   }
   ObjectMove(a_name_0, 0, Time[10], a_price_8);
}

void drawLine(double a_price_0, string a_name_8, color a_color_16, int ai_20, int a_width_24) {
   if (ObjectFind(a_name_8) == -1) {
      ObjectCreate(a_name_8, OBJ_HLINE, 0, Time[0], a_price_0, Time[0], a_price_0);
      if (ai_20 == 1) ObjectSet(a_name_8, OBJPROP_STYLE, STYLE_SOLID);
      else ObjectSet(a_name_8, OBJPROP_STYLE, STYLE_DOT);
      ObjectSet(a_name_8, OBJPROP_COLOR, a_color_16);
      ObjectSet(a_name_8, OBJPROP_WIDTH, a_width_24);
   } else {
      ObjectDelete(a_name_8);
      ObjectCreate(a_name_8, OBJ_HLINE, 0, Time[0], a_price_0, Time[0], a_price_0);
      if (ai_20 == 1) ObjectSet(a_name_8, OBJPROP_STYLE, STYLE_SOLID);
      else ObjectSet(a_name_8, OBJPROP_STYLE, STYLE_DOT);
      ObjectSet(a_name_8, OBJPROP_COLOR, a_color_16);
      ObjectSet(a_name_8, OBJPROP_WIDTH, a_width_24);
   }
   ObjectsRedraw();
}

void DeletePivots() {
   ObjectDelete("S1");
   ObjectDelete("S2");
   ObjectDelete("S3");
   ObjectDelete("R1");
   ObjectDelete("R2");
   ObjectDelete("R3");
   ObjectDelete("PIVIOT");
   ObjectDelete("Support 1");
   ObjectDelete("Support 2");
   ObjectDelete("Support 3");
   ObjectDelete("Piviot level");
   ObjectDelete("Resistance 1");
   ObjectDelete("Resistance 2");
   ObjectDelete("Resistance 3");
}

int MA_Distance(int shift) {
   double l_ima_4 = iMA(NULL, 0, RedPeriods[0], 0, MODE_EMA, PRICE_CLOSE, shift);
   double l_ima_12 = iMA(NULL, 0, RedPeriods[15], 0, MODE_EMA, PRICE_CLOSE, shift);
   return (MathAbs(l_ima_4 - l_ima_12) / Point);
}

int CalcDailyRange() {
   int li_0 = 0;
   int li_ret_4 = 0;
   RefreshRates();
   for (li_0 = 1; li_0 <= 10; li_0++) {
      RefreshRates();
      li_ret_4 = li_ret_4 + (iHigh(NULL, PERIOD_D1, li_0) - iLow(NULL, PERIOD_D1, li_0)) / Point;
   }
   li_ret_4 /= 10;
   return (li_ret_4);
}