/*
   Generated by EX4-TO-MQ4 decompiler V4.0.224.1 []
   Website: http://purebeam.biz
   E-mail : dynamicgains@rocketmail.com
*/
#property copyright "Copyright � 2007, TrendLaboratory DYNAMIC GAINS INC. Ltd."
#property link      "http://finance.groups.yahoo.com/group/TrendLaboratory"

#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 LightBlue
#property indicator_color2 Orange
#property indicator_color3 LightBlue
#property indicator_color4 Orange

extern int MA_Period = 3;
extern int MA_Method = 2;
extern int UseSignal = 1;
extern int AlertMode = 1;
extern int WarningMode = 1;
extern int UpArrowCode = 233;
extern int DownArrowCode = 234;

double g_ibuf_96[];
double g_ibuf_100[];
double g_ibuf_104[];
double g_ibuf_108[];
double g_ibuf_112[];
double g_ibuf_116[];
double g_ibuf_120[];
int gi_124 = 0;
bool gi_128 = FALSE;
bool gi_132 = FALSE;

int init() {
   string ls_unused_4;
   IndicatorBuffers(7);
   SetIndexStyle(0, DRAW_LINE);
   SetIndexStyle(1, DRAW_LINE);
   SetIndexStyle(2, DRAW_ARROW);
   SetIndexArrow(2, UpArrowCode);
   SetIndexStyle(3, DRAW_ARROW);
   SetIndexArrow(3, DownArrowCode);
   IndicatorDigits(MarketInfo(Symbol(), MODE_DIGITS));
   if (MA_Period < 2) MA_Period = 10;
   int li_0 = MA_Period - 1;
   IndicatorShortName("Dynamic Gains (" + MA_Period + ")");
   SetIndexLabel(0, "UpTrendEnv");
   SetIndexLabel(1, "DnTrendEnv");
   SetIndexLabel(2, "UpSignal");
   SetIndexLabel(3, "DnSignal");
   SetIndexDrawBegin(0, li_0);
   SetIndexDrawBegin(1, li_0);
   SetIndexDrawBegin(2, li_0);
   SetIndexDrawBegin(3, li_0);
   SetIndexBuffer(0, g_ibuf_96);
   SetIndexBuffer(1, g_ibuf_100);
   SetIndexBuffer(2, g_ibuf_104);
   SetIndexBuffer(3, g_ibuf_108);
   SetIndexBuffer(4, g_ibuf_112);
   SetIndexBuffer(5, g_ibuf_116);
   SetIndexBuffer(6, g_ibuf_120);
   return (0);
}

int start() {
   string ls_8;
   if (Bars <= MA_Period) return (0);
   gi_124 = IndicatorCounted();
   if (gi_124 < 0) return (-1);
   if (gi_124 > 0) gi_124--;
   int li_0 = Bars - gi_124;
   for (int li_4 = li_0; li_4 >= 0; li_4--) {
      g_ibuf_112[li_4] = iMA(NULL, 0, MA_Period, 0, MA_Method, PRICE_HIGH, li_4);
      g_ibuf_116[li_4] = iMA(NULL, 0, MA_Period, 0, MA_Method, PRICE_LOW, li_4);
      g_ibuf_120[li_4] = g_ibuf_120[li_4 + 1];
      if (Close[li_4] > g_ibuf_112[li_4 + 1]) g_ibuf_120[li_4] = 1;
      if (Close[li_4] < g_ibuf_116[li_4 + 1]) g_ibuf_120[li_4] = -1;
      if (g_ibuf_120[li_4] > 0.0) {
         if (g_ibuf_116[li_4] < g_ibuf_116[li_4 + 1]) g_ibuf_116[li_4] = g_ibuf_116[li_4 + 1];
         g_ibuf_96[li_4] = g_ibuf_116[li_4];
         if (UseSignal > 0) {
            if (g_ibuf_120[li_4 + 1] < 0.0) {
               g_ibuf_104[li_4] = g_ibuf_116[li_4];
               if (WarningMode > 0 && li_4 == 0) PlaySound("alert2.wav");
            } else g_ibuf_104[li_4] = EMPTY_VALUE;
         }
         g_ibuf_100[li_4] = EMPTY_VALUE;
         g_ibuf_108[li_4] = EMPTY_VALUE;
      } else {
         if (g_ibuf_112[li_4] > g_ibuf_112[li_4 + 1]) g_ibuf_112[li_4] = g_ibuf_112[li_4 + 1];
         g_ibuf_100[li_4] = g_ibuf_112[li_4];
         if (UseSignal > 0) {
            if (g_ibuf_120[li_4 + 1] > 0.0) {
               g_ibuf_108[li_4] = g_ibuf_112[li_4];
               if (WarningMode > 0 && li_4 == 0) PlaySound("alert2.wav");
            } else g_ibuf_108[li_4] = EMPTY_VALUE;
         }
         g_ibuf_96[li_4] = EMPTY_VALUE;
         g_ibuf_104[li_4] = EMPTY_VALUE;
      }
   }
   if (g_ibuf_120[2] < 0.0 && g_ibuf_120[1] > 0.0 && Volume[0] > 1.0 && !gi_128) {
      ls_8 = " " + Symbol() + " M" + Period() + ":  -  CONFIRMED BUY ENTRY  - ";
      if (AlertMode > 0) Alert(ls_8);
      gi_128 = TRUE;
      gi_132 = FALSE;
   }
   if (g_ibuf_120[2] > 0.0 && g_ibuf_120[1] < 0.0 && Volume[0] > 1.0 && !gi_132) {
      ls_8 = " " + Symbol() + " M" + Period() + ":  -  CONFIRMED SELL ENTRY  - ";
      if (AlertMode > 0) Alert(ls_8);
      gi_132 = TRUE;
      gi_128 = FALSE;
   }
   return (0);
}