
#property copyright "Gratitude4"
#property link      "gratitude4@aol.com"

#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 DodgerBlue
#property indicator_color2 OrangeRed
#property indicator_color3 Lime
#property indicator_color4 Lime
//#property strict

extern int MA_Period = 12;
input ENUM_MA_METHOD MA_Method = 2;

extern bool Alert_Mode = true; 
input bool Push_Notification = false;
extern bool Use_Signal = true;
input bool Warning_Mode = false;
extern int Up_Arrow_Code = 250;
extern int Down_Arrow_Code = 250;
double G_ibuf_104[];
double G_ibuf_108[];
double G_ibuf_112[];
double G_ibuf_116[];
double G_ibuf_120[];
double G_ibuf_124[];
double G_ibuf_128[];
int Gi_132 = 0;
bool Gi_136 = FALSE;
bool Gi_140 = FALSE;

// E37F0136AA3FFAF149B351F6A4C948E9
int init() {
  // string Ls_unused_0;
   IndicatorBuffers(7);
   SetIndexStyle(0, DRAW_LINE);
   SetIndexStyle(1, DRAW_LINE);
   SetIndexStyle(2, DRAW_ARROW);
   SetIndexArrow(2, Up_Arrow_Code);
   SetIndexStyle(3, DRAW_ARROW);
   SetIndexArrow(3, Down_Arrow_Code);
   IndicatorDigits(MarketInfo(Symbol(), MODE_DIGITS));
   IndicatorDigits(MODE_DIGITS);
   if (MA_Period < 2) MA_Period = 13;
   int Li_8 = MA_Period - 1;
   IndicatorShortName("G420 (" + IntegerToString(MA_Period) + ")");
   SetIndexLabel(0, "UpTrendEnv");
   SetIndexLabel(1, "DnTrendEnv");
   SetIndexLabel(2, "UpSignal");
   SetIndexLabel(3, "DnSignal");
   SetIndexDrawBegin(0, Li_8);
   SetIndexDrawBegin(1, Li_8);
   SetIndexDrawBegin(2, Li_8);
   SetIndexDrawBegin(3, Li_8);
   SetIndexBuffer(0, G_ibuf_104);
   SetIndexBuffer(1, G_ibuf_108);
   SetIndexBuffer(2, G_ibuf_112);
   SetIndexBuffer(3, G_ibuf_116);
   SetIndexBuffer(4, G_ibuf_120);
   SetIndexBuffer(5, G_ibuf_124);
   SetIndexBuffer(6, G_ibuf_128);
   return (0);
}

// EA2B2676C28C0DB26D39331A336C6B92
int start() {
   string Ls_0;
   if (Bars <= MA_Period) return (0);
   Gi_132 = IndicatorCounted();
   if (Gi_132 < 0) return (-1);
   if (Gi_132 > 0) Gi_132--;
   int Li_8 = Bars - Gi_132;
   for (int Li_12 = Li_8; Li_12 >= 0; Li_12--) {
      G_ibuf_120[Li_12] = iMA(NULL, 0, MA_Period, 0, MA_Method, PRICE_HIGH, Li_12);
      G_ibuf_124[Li_12] = iMA(NULL, 0, MA_Period, 0, MA_Method, PRICE_LOW, Li_12);
      G_ibuf_128[Li_12] = G_ibuf_128[Li_12 + 1];
      if (Close[Li_12] > G_ibuf_120[Li_12 + 1]) G_ibuf_128[Li_12] = 1;
      if (Close[Li_12] < G_ibuf_124[Li_12 + 1]) G_ibuf_128[Li_12] = -1;
      if (G_ibuf_128[Li_12] > 0.0) {
         if (G_ibuf_124[Li_12] < G_ibuf_124[Li_12 + 1]) G_ibuf_124[Li_12] = G_ibuf_124[Li_12 + 1];
         G_ibuf_104[Li_12] = G_ibuf_124[Li_12];
         if (Use_Signal == true) {
            if (G_ibuf_128[Li_12 + 1] < 0.0) {
               G_ibuf_112[Li_12] = G_ibuf_124[Li_12];
               if (Warning_Mode == true  && Li_12 == 0) PlaySound("alert2.wav");
            } else G_ibuf_112[Li_12] = EMPTY_VALUE;
         }
         G_ibuf_108[Li_12] = EMPTY_VALUE;
         G_ibuf_116[Li_12] = EMPTY_VALUE;
      } else 
      {
         if (G_ibuf_120[Li_12] > G_ibuf_120[Li_12 + 1]) G_ibuf_120[Li_12] = G_ibuf_120[Li_12 + 1];
         G_ibuf_108[Li_12] = G_ibuf_120[Li_12];
         if (Use_Signal ==true) {
            if (G_ibuf_128[Li_12 + 1] > 0.0) {
               G_ibuf_116[Li_12] = G_ibuf_120[Li_12];
               if (Warning_Mode == true && Li_12 == 0) PlaySound("alert2.wav");
            } else G_ibuf_116[Li_12] = EMPTY_VALUE;
         }
         G_ibuf_104[Li_12] = EMPTY_VALUE;
         G_ibuf_112[Li_12] = EMPTY_VALUE;
      }
   }
   if (G_ibuf_128[2] < 0.0 && G_ibuf_128[1] > 0.0 && Volume[0] > 1.0 && (!Gi_136)) 
   {
      Ls_0 = Symbol() + " M" + IntegerToString(Period()) + ": Signal  CONFIRMED!! -  BUY  - " + " \n" +  AccountCompany();
      if (Alert_Mode == true) Alert(Ls_0);
      if (Push_Notification == true) SendNotification (Ls_0);
      Gi_136 = TRUE;
      Gi_140 = FALSE;
   }
   if (G_ibuf_128[2] > 0.0 && G_ibuf_128[1] < 0.0 && Volume[0] > 1.0 && (!Gi_140)) 
   {
      Ls_0 = Symbol() + " M" + IntegerToString(Period()) + ": Signal  CONFIRMED!! -  SELL  - " + " \n" + AccountCompany();
      if (Alert_Mode == true) Alert(Ls_0);
      if (Push_Notification == true) SendNotification (Ls_0);
      Gi_140 = TRUE;
      Gi_136 = FALSE;
   }
   return (0);
}