Navigation:Home > Content >

Volamat3_fullMA.mq4

Time: 2018-03-01 | Download file:Volamat3_fullMA.mq4

//+------------------------------------------------------------------+
//|                                      Volamat3.mq4                                                      |
//|                         Gemeinnuetziger Strenzfeld Fonds - GSF - e.V.                |
//|                                Strenzfeldfonds@email.de                                           |
//+-------------------------------------------------------------------+
#property copyright "Copyright © 2008 Gemeinnuetziger Strenzfeld Fonds - GSF - e.V."
#property link      "Strenzfeldfonds@email.de"

/*
   Generated by EX4-TO-MQ4 decompiler V4.0.215.5
   E-mail : getmq4@gmail.com
*/

#property indicator_separate_window
#property indicator_buffers 7
#property indicator_color1 Aqua
#property indicator_color2 Red
#property indicator_color3 Yellow
#property indicator_color4 Blue
#property indicator_color5 Red
#property indicator_color6 Blue
#property indicator_color7 Red


double g_ibuf_76[];
extern int key = 777777777;
extern double Smooth = 1.0;
double gd_92 = 100.0;
extern int bars = 100;
int gi_104 = 0;
extern int Progression = 3;
extern int Len = 3;
extern int Sensitivity = 30;
int gi_120 = 1;
int gi_124 = 0;
double gd_128 = 0.0;
double gd_136;
double gd_144;
double gd_152;
double gd_160;
double gd_168;
double gd_176;
double gd_184;
double gd_192;
double gd_200 = 0.0;
int g_index_208;
int gi_212;
int gi_216;
int gi_220;
int gi_224;
int gi_228;
int gi_232;
int gi_236;
int gi_240;
int gi_244;
int gi_248;
int gi_252;
int gi_256 = 0;
double gd_260;
double gd_268;
double gd_276;
double gd_284;
double gd_292;
double gd_300;
double gd_308;
double gd_316;
double gd_324;
double gd_332;
double gd_340;
double gd_348;
double gd_356;
double gd_364;
double gd_372;
double gd_380;
double gd_388;
double gd_396;
double gd_404;
double gd_412;
double gd_420;
double gd_428;
double gd_436;
double gd_444;
double gd_452;
double gd_460 = 0.0;
bool gi_468;
int gi_472;
int gi_476;
int gi_480;
int gi_484;
int gi_488 = 0;
double gda_492[128];
double gda_496[128];
double gda_500[11];
double gda_504[62];
double gda_unused_508[300];
int gi_unused_512;
int g_index_516;
int gi_520;
int gi_528;
double g_ibuf_556[];
double gda_560[15000];
double gda_564[15000];
double g_icustom_568;
double g_icustom_576 = 0.0;
double gd_584;
double gd_592;
double g_bars_600 = 0.0;

string scriptname="Ultratrend";
extern string __UltraTrend_Manuell_____ = "_________________________";
extern bool   UltraTrend_Manuell        = false;
extern double UltraTrendKorrekturfaktor = 1.0;
extern double Korrektur_X_Prozent       = 10.0; 
extern string __Moving_Average_________ = "_________________________";
extern bool   MAZeichnen                = false;
extern bool   UseMAPeriodeByUser        = false;   // false - use value2[MAPeriodeValue1Shift] as period of MA, true - use MAPeriodeByUser as period of MA
extern int    MAPeriodeByUser           = 7;       // constant period of MA
extern int    MAPeriodeValue1Shift      = 0;
extern int    MA_Method                 = 0;       // method of МА: 0-Simple, 1-Exponential, 2-Smoothed, 3-Weighted
extern string __Alerts_Erlauben________ = "_________________________";
extern bool   Alertsignale              = false;         
extern string __Soundsalert____________ = "_________________________";
extern bool   Soundalert                = false;
extern int    Sound_Play_X_Mal          = 5;
extern int    Sound_Play_Abstand_Sk     = 5;
extern string Sounddatei_1              = "Ultra_Trend_Up.wav";
extern string Sounddatei_2              = "Ultra_Trend_Down.wav";
extern string Sounddatei_3              = "Ultra_Trend_MACross_Up.wav";
extern string Sounddatei_4              = "Ultra_Trend_MACross_Down.wav";
extern string __Pfeilalert_____________ = "_________________________";
extern bool   Pfeilalert                = false;

//----Buffers
double v2[];
double v3[];
double v4[];
double v5[];
double v6[];
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int init() {
//----
   for (g_index_208 = 0; g_index_208 < 128; g_index_208++) gda_492[g_index_208] = 0.0;
   for (g_index_208 = 0; g_index_208 < 128; g_index_208++) gda_496[g_index_208] = 0.0;
   for (g_index_208 = 0; g_index_208 < 11; g_index_208++) gda_500[g_index_208] = 0.0;
   for (g_index_208 = 0; g_index_208 < 62; g_index_208++) gda_504[g_index_208] = 0.0;
   //----
   SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, 1);
   SetIndexBuffer(0, g_ibuf_76);
   //----
   SetIndexStyle(1, DRAW_LINE, STYLE_SOLID, 1);
   SetIndexBuffer(1, g_ibuf_556);
   //----
   SetIndexStyle(2,DRAW_LINE);
   SetIndexBuffer(2,v4);
   //---- Pfeil  
   SetIndexBuffer(3,v2);
   SetIndexStyle(3,DRAW_ARROW,0,1);
   SetIndexArrow(3,233);
   //---- Pfeil
   SetIndexBuffer(4,v3);
   SetIndexStyle(4,DRAW_ARROW,0,1);
   SetIndexArrow(4,234);
   //---- Pfeil  
   SetIndexBuffer(5,v5);
   SetIndexStyle(5,DRAW_ARROW,0,3);
   SetIndexArrow(5,233);
   //---- Pfeil
   SetIndexBuffer(6,v6);
   SetIndexStyle(6,DRAW_ARROW,0,3);
   SetIndexArrow(6,234);
   //---- 
   //----Windows Fenster ID
   string WH_BB="WH_BB "+WindowHandle(Symbol(),0);
   if(GlobalVariableCheck(WH_BB))GlobalVariableDel(WH_BB);
   //----
   string Ultra_Trend="Ultra_Trend "+WindowHandle(Symbol(),0);
   if(GlobalVariableCheck(Ultra_Trend))GlobalVariableDel(Ultra_Trend);
   //----
   return (0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
string WH_BB="WH_BB "+WindowHandle(Symbol(),0);
if(GlobalVariableCheck(WH_BB))GlobalVariableDel(WH_BB);
string Ultra_Trend="Ultra_Trend "+WindowHandle(Symbol(),0);
if(GlobalVariableCheck(Ultra_Trend))GlobalVariableDel(Ultra_Trend);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start() {
//----
/*
Achtung, je hцher die periode von Sensitivity desto mehr Arbeitsspeicher wird 
verbraucht bis hin zu Ьberlauf.
*/
   if(Sensitivity<=0){Sensitivity=1;}
   if(Sensitivity>200){Sensitivity=1;}
   if(UltraTrendKorrekturfaktor<=0) UltraTrendKorrekturfaktor=1;
   if(UltraTrend_Manuell==false)
   {
    string ChannelPips="ChannelPips "+WindowHandle(Symbol(),0);
    if(GlobalVariableCheck(ChannelPips))
     {
     Sensitivity=((Korrektur_X_Prozent/100)*GlobalVariableGet(ChannelPips)) * UltraTrendKorrekturfaktor;
     //Print("Sensitivity",Sensitivity,"  ",GlobalVariableGet(ChannelPips),"  ",Korrektur_X_Prozent,"  ",10.0/100);         
     if(Sensitivity<=0) Sensitivity=1;
     if(Sensitivity>200){Sensitivity=1;}
     //----Anzeigen
     string t1="Sens";
     if(ObjectFind(t1) >= 0) ObjectDelete(t1);
     if(!ObjectCreate(t1,OBJ_LABEL,0,0,0))Print("error: cant create ",t1," ! 0   code #",GetLastError());
     if(!ObjectSet(t1,OBJPROP_XDISTANCE,4))Print("error: cant set xdistance ",t1," ! 0   code #",GetLastError());
     if(!ObjectSet(t1,OBJPROP_YDISTANCE,130))Print("error: cant set ydistance ",t1," ! 0   code #",GetLastError());
     if(!ObjectSet(t1,OBJPROP_WIDTH,1))Print("error: cant set width ",t1," ! 0   code #",GetLastError());
     ObjectSetText(t1, CharToStr(167), 22, "Wingdings", White);  
     t1="Sens_";
     if(ObjectFind(t1) >= 0) ObjectDelete(t1);
     if(!ObjectCreate(t1,OBJ_LABEL,0,0,0))Print("error: cant create ",t1," ! ",scriptname,"   code #",GetLastError());
     if(!ObjectSet(t1,OBJPROP_XDISTANCE,19))Print("error: cant set xdistance ",t1," ! ",scriptname,"   code #",GetLastError());
     if(!ObjectSet(t1,OBJPROP_YDISTANCE,137))Print("error: cant set ydistance ",t1," ! ",scriptname,"   code #",GetLastError());
     if(!ObjectSet(t1,OBJPROP_WIDTH,1))Print("error: cant set width ",t1," ! ",scriptname,"   code #",GetLastError());
     ObjectSetText(t1, "Sensitivity Periode: "+DoubleToStr(Sensitivity,0), 11, "Arial", White);      
    }
    else Print("Global Variable fьr Channel nicht gefunden.");
   }
   else {
   if(ObjectFind("Sens") >= 0) ObjectDelete("Sens");if(ObjectFind("Sens_") >= 0) ObjectDelete("Sens_");
   }
   //----
   int li_unused_16;
   int li_12 = key;
   if (li_12 == 34562788) {
      loadJMA();
      return (0);
   }
   int err = GetLastError(); if(err>0  && err != 4058)Print("Error Nr.1.2 Error  #",err); 
   if (Bars > g_bars_600) {
      g_bars_600 = Bars;
      li_unused_16 = 0;
      for (int l_index_20 = 0; l_index_20 < bars; l_index_20++) {
         gd_584 = 0;
         gd_592 = 0;
         for (int li_24 = Len; li_24 <= Len + Progression * Sensitivity; li_24 += Progression) {         
            g_icustom_568 = iCustom(NULL, 0, "ULTRA_TREND", 34562788, li_24, bars, 0, l_index_20);
            g_icustom_576 = iCustom(NULL, 0, "ULTRA_TREND", 34562788, li_24, bars, 0, l_index_20 + 1);            
            if (g_icustom_568 > g_icustom_576) gd_584++;
            else gd_592++;
         }
         gda_560[l_index_20] = gd_584;
         gda_564[l_index_20] = gd_592;         
      }
      lenars(gda_560, 1);
      lenars(gda_564, 2);     
   } 
        
   //----   
   err = GetLastError(); if(err>0  && err != 4058)Print("Error Nr.1.4 Error  #",err);  
   if(MAZeichnen)
     {
      if(UseMAPeriodeByUser) int p = MAPeriodeByUser;
      else
        {
         p = g_ibuf_76[MAPeriodeValue1Shift];
         if(p < 2) p = 2;
        }
      Moving_Averages(MA_Method,p,bars);    
     }    
   //----Value1 und MA
   string Ultra_Trend="Ultra_Trend "+WindowHandle(Symbol(),0);
   static int tickcount,tickcount2,merk1,merk2,Startzeit1,Startzeit2,signal,merk3,merk4,signal2;
   int Durchlauf=Bars-IndicatorCounted();if(Durchlauf<10)Durchlauf=1;
   if(Durchlauf>2)int dd2=bars-5; else dd2=0;   
   while(dd2>=0)
   {
    if(Alertsignale==true)
     {      
      //----Value1 und MA Pfeil
      if(Pfeilalert==true && NormalizeDouble(v4[dd2+1],0)=NormalizeDouble(g_ibuf_76[dd2+2],0) && merk1<=0){ArrayInitialize(v2,EMPTY_VALUE);v2[dd2+0]=NormalizeDouble(g_ibuf_76[dd2],Digits);merk1++;merk2=0;signal=1;}
      if(Pfeilalert==true && NormalizeDouble(v4[dd2+1],0)>NormalizeDouble(g_ibuf_76[dd2+1],0) && NormalizeDouble(v4[dd2+2],0)<=NormalizeDouble(g_ibuf_76[dd2+2],0) && merk2<=0){ArrayInitialize(v3,EMPTY_VALUE);v3[dd2+0]=NormalizeDouble(g_ibuf_76[dd2],Digits);merk2++;merk1=0;signal=2;}
      //----Value1 und Value2 Pfeil
      if(Pfeilalert==true && NormalizeDouble(g_ibuf_556[dd2+1],0)=NormalizeDouble(g_ibuf_76[dd2+2],0) && merk3<=0)
      {ArrayInitialize(v5,EMPTY_VALUE);v5[dd2+0]=NormalizeDouble(g_ibuf_76[dd2],Digits);merk3++;merk4=0;signal2=1;}
      if(Pfeilalert==true && NormalizeDouble(g_ibuf_556[dd2+1],0)>NormalizeDouble(g_ibuf_76[dd2+1],0) && NormalizeDouble(g_ibuf_556[dd2+2],0)<=NormalizeDouble(g_ibuf_76[dd2+2],0) && merk4<=0)
      {ArrayInitialize(v6,EMPTY_VALUE);v6[dd2+0]=NormalizeDouble(g_ibuf_76[dd2],Digits);merk4++;merk3=0;signal2=2;}
     }
    //----
    dd2--;
    //----     
   }
   err = GetLastError(); if(err>0  && err != 4058)Print("Error Nr.1.44 Error  #",err);    
   //----Value1 und MA
   static int abc,abc2;
   if(abc==0 && signal==1) {tickcount2=0;abc=1;abc2=0;}
   if(abc2==0 && signal==2){tickcount=0;abc2=1;abc=0;}
   if(Soundalert == true && Alertsignale == true)
   {
     //----Signal von unten nach oben - "Hoch"
     if(merk1>0 && tickcount=Startzeit1+(Sound_Play_Abstand_Sk*1000) || Startzeit1==0) )
       {
        PlaySound(Sounddatei_1);
        tickcount++;  
        Startzeit1=GetTickCount();     
       }
     //----Signal von oben nach unten - "Runter"                   
     if(merk2>0 && tickcount2=Startzeit2+(Sound_Play_Abstand_Sk*1000) || Startzeit2==0) )
       {
        PlaySound(Sounddatei_2);
        tickcount2++;
        Startzeit2=GetTickCount();
       }            
   }
   err = GetLastError(); if(err>0  && err != 4058)Print("Error Nr.1.456 Error  #",err); 

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
   //----Value1 und Value2
   static int tickcount3,tickcount4,Startzeit3,Startzeit4;
   err = GetLastError(); if(err>0  && err != 4058)Print("Error Nr.1.434 Error  #",err);    
   //----Value1 und Value2
   static int abc3,abc4;
   if(abc3==0 && signal2==1) {tickcount4=0;abc3=1;abc4=0;}
   if(abc4==0 && signal2==2){tickcount3=0;abc4=1;abc3=0;}
   if(Soundalert == true && Alertsignale == true)
   {
     //----Signal von unten nach oben - "Hoch"
     if(merk3>0 && tickcount3=Startzeit3+(Sound_Play_Abstand_Sk*1000) || Startzeit3==0) )
       {
        PlaySound(Sounddatei_3);
        tickcount3++;
        Startzeit3=GetTickCount();
       }
     //----Signal von oben nach unten - "Runter"
     if(merk4>0 && tickcount4=Startzeit4+(Sound_Play_Abstand_Sk*1000) || Startzeit4==0) )
       {
        PlaySound(Sounddatei_4);
        tickcount4++;
        Startzeit4=GetTickCount();
       }
   }
   err = GetLastError(); if(err>0  && err != 4058)Print("Error Nr.1.3456 Error  #",err);

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+              
if(Bars-IndicatorCounted()>10 || Bars-IndicatorCounted()>=2){
for(int i=0; i<40; i++){
g_ibuf_76[bars+1+i]=EMPTY_VALUE;
g_ibuf_556[bars+1+i]=EMPTY_VALUE;
}
}else {
g_ibuf_76[bars+1]=EMPTY_VALUE;
g_ibuf_556[bars+1]=EMPTY_VALUE;
}
//----
v4[bars+1]=EMPTY_VALUE;
v2[bars+1]=EMPTY_VALUE;
v3[bars+1]=EMPTY_VALUE;
v5[bars+1]=EMPTY_VALUE;
v6[bars+1]=EMPTY_VALUE;
//----
err = GetLastError(); if(err>0  && err != 4058)Print("Error Nr.1.33 Error  #",err); 
//----
//Comment(NormalizeDouble(g_ibuf_556[1],0),"  ",NormalizeDouble(g_ibuf_76[1],0),"  ",NormalizeDouble(g_ibuf_556[2],0),"   ",NormalizeDouble(g_ibuf_76[2],0));
if(NormalizeDouble(g_ibuf_556[1],0)NormalizeDouble(g_ibuf_76[1],0))
{GlobalVariableSet(Ultra_Trend,2);}
//----Windows Fenster ID
string WH_BB="WH_BB "+WindowHandle(Symbol(),0);
if(GlobalVariableCheck(WH_BB)==false) GlobalVariableSet(WH_BB, WindowHandle(Symbol(),Period()) );
//----
return(0);
}

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void loadJMA() {
   double ld_0;
   gi_220 = 63;
   gi_224 = 64;
   if (gi_120 == TRUE) {
      for (g_index_208 = 1; g_index_208 < gi_220 + 1; g_index_208++) gda_492[g_index_208] = -1000000;
      for (g_index_208 = gi_224; g_index_208 < 128; g_index_208++) gda_492[g_index_208] = 1000000;
      gi_120 = FALSE;
   }
   gi_468 = TRUE;
   if (Smooth <= 1.0) gd_380 = 0.0000000001;
   else gd_380 = (Smooth - 1.0) / 2.0;
   if (gd_92 < -100.0) gd_268 = 0.5;
   else {
      if (gd_92 > 100.0) gd_268 = 2.5;
      else gd_268 = gd_92 / 100.0 + 1.5;
   }
   gd_144 = MathLog(MathSqrt(gd_380));
   gd_152 = gd_144;
   if (gd_144 / MathLog(2.0) + 2.0 < 0.0) gd_160 = 0;
   else gd_160 = gd_152 / MathLog(2.0) + 2.0;
   gd_404 = gd_160;
   if (gd_404 - 2.0 >= 0.5) gd_388 = gd_404 - 2.0;
   else gd_388 = 0.5;
   gd_372 = MathSqrt(gd_380) * gd_404;
   gd_396 = gd_372 / (gd_372 + 1.0);
   gd_380 = 0.9 * gd_380;
   gd_332 = gd_380 / (gd_380 + 2.0);
   gi_468 = TRUE;
   if (bars == 0) bars = Bars;
   for (gi_124 = bars + 1000; gi_124 >= 0; gi_124--) {
      switch (gi_104) {
      case 0:
         ld_0 = Close[gi_124];
         break;
      case 1:
         ld_0 = Open[gi_124];
         break;
      case 2:
         ld_0 = (Open[gi_124] + High[gi_124] + Low[gi_124] + Close[gi_124]) / 4.0;
         break;
      case 3:
         ld_0 = High[gi_124];
         break;
      case 4:
         ld_0 = Low[gi_124];
         break;
      default:
         ld_0 = Close[gi_124];
      }
      if (gi_484 < 61) {
         gi_484++;
         gda_504[gi_484] = ld_0;
      }
      if (gi_484 > 30) {
         if (gi_468 != FALSE) {
            gi_468 = FALSE;
            gi_212 = 0;
            for (g_index_208 = 1; g_index_208 < 30; g_index_208++)
               if (gda_504[g_index_208 + 1] != gda_504[g_index_208]) gi_212 = 1;
            gi_472 = 30 * gi_212;
            if (gi_472 == 0) gd_308 = ld_0;
            else gd_308 = gda_504[1];
            gd_276 = gd_308;
            if (gi_472 > 29) gi_472 = 29;
         } else gi_472 = 0;
         for (g_index_208 = gi_472; g_index_208 >= 0; g_index_208--) {
            if (g_index_208 == 0) gd_260 = ld_0;
            else gd_260 = gda_504[31 - g_index_208];
            gd_292 = gd_260 - gd_276;
            gd_324 = gd_260 - gd_308;
            if (MathAbs(gd_292) > MathAbs(gd_324)) gd_152 = MathAbs(gd_292);
            else gd_152 = MathAbs(gd_324);
            gd_412 = gd_152;
            gd_136 = gd_412 + 0.0000000001;
            if (gi_236 <= 1) gi_236 = 127;
            else gi_236--;
            if (gi_240 <= 1) gi_240 = 10;
            else gi_240--;
            if (gi_256 < 128) gi_256++;
            gd_176 = gd_176 + gd_136 - gda_500[gi_240];
            gda_500[gi_240] = gd_136;
            if (gi_256 > 10) gd_200 = gd_176 / 10.0;
            else gd_200 = gd_176 / gi_256;
            if (gi_256 == 30) g_index_516 = 0;
            if (gi_256 > 127) {
               gd_184 = gda_496[gi_236];
               gda_496[gi_236] = gd_200;
               gi_252 = 64;
               gi_244 = gi_252;
               gi_unused_512 = gi_244;
               while (gi_252 > 1) {
                  if (gda_492[gi_244] < gd_184) {
                     gi_252 /= 2;
                     gi_244 += gi_252;
                     gi_unused_512 = gi_244;
                  } else {
                     if (gda_492[gi_244] <= gd_184) gi_252 = 1;
                     else {
                        gi_252 /= 2;
                        gi_244 -= gi_252;
                        gi_unused_512 = gi_244;
                     }
                  }
               }
            } else {
               gda_496[gi_236] = gd_200;
               if (gi_220 + gi_224 > 127) {
                  gi_224--;
                  gi_244 = gi_224;
                  gi_unused_512 = gi_244;
               } else {
                  gi_220++;
                  gi_244 = gi_220;
                  gi_unused_512 = gi_244;
               }
               if (gi_220 > 96) gi_228 = 96;
               else gi_228 = gi_220;
               if (gi_224 < 32) gi_232 = 32;
               else gi_232 = gi_224;
            }
            gi_252 = 64;
            gi_248 = gi_252;
            while (gi_252 > 1) {
               if (gda_492[gi_248] >= gd_200) {
                  if (gda_492[gi_248 - 1] <= gd_200) gi_252 = 1;
                  else {
                     gi_252 /= 2;
                     gi_248 -= gi_252;
                  }
               } else {
                  gi_252 /= 2;
                  gi_248 += gi_252;
               }
               if (gi_248 == 127 && gd_200 > gda_492[127]) gi_248 = 128;
            }
            if (gi_256 > 127) {
               if (gi_244 >= gi_248) {
                  if (gi_228 + 1 > gi_248 && gi_232 - 1 < gi_248) gd_192 += gd_200;
                  else
                     if (gi_232 > gi_248 && gi_232 - 1 < gi_244) gd_192 += gda_492[gi_232 - 1];
               } else {
                  if (gi_232 >= gi_248) {
                     if (gi_228 + 1 < gi_248 && gi_228 + 1 > gi_244) gd_192 += gda_492[gi_228 + 1];
                  } else {
                     if (gi_228 + 2 > gi_248) gd_192 += gd_200;
                     else
                        if (gi_228 + 1 < gi_248 && gi_228 + 1 > gi_244) gd_192 += gda_492[gi_228 + 1];
                  }
               }
               if (gi_244 > gi_248) {
                  if (gi_232 - 1 < gi_244 && gi_228 + 1 > gi_244) gd_192 -= gda_492[gi_244];
                  else
                     if (gi_228 < gi_244 && gi_228 + 1 > gi_248) gd_192 -= gda_492[gi_228];
               } else {
                  if (gi_228 + 1 > gi_244 && gi_232 - 1 < gi_244) gd_192 -= gda_492[gi_244];
                  else
                     if (gi_232 > gi_244 && gi_232 < gi_248) gd_192 -= gda_492[gi_232];
               }
            }
            if (gi_244 <= gi_248) {
               if (gi_244 >= gi_248) gda_492[gi_248] = gd_200;
               else {
                  for (g_index_516 = gi_244 + 1; g_index_516 < gi_248; g_index_516++) gda_492[g_index_516 - 1] = gda_492[g_index_516];
                  gda_492[gi_248 - 1] = gd_200;
               }
            } else {
               for (gi_520 = gi_244 - 1; gi_520 >= gi_248; gi_520--) gda_492[gi_520 + 1] = gda_492[gi_520];
               gda_492[gi_248] = gd_200;
            }
            if (gi_256 <= 127) {
               gd_192 = 0;
               for (gi_528 = gi_232; gi_528 < gi_228 + 1; gi_528++) gd_192 += gda_492[gi_528];
            }
            gd_348 = gd_192 / (gi_228 - gi_232 + 1);
            if (gi_488 + 1 > 31) gi_488 = 31;
            else gi_488++;
            if (gi_488 <= 30) {
               if (gd_292 > 0.0) gd_276 = gd_260;
               else gd_276 = gd_260 - gd_292 * gd_396;
               if (gd_324 < 0.0) gd_308 = gd_260;
               else gd_308 = gd_260 - gd_324 * gd_396;
               gd_436 = ld_0;
               if (gi_488 != 30) continue;
               gd_444 = ld_0;
               if (MathCeil(gd_372) >= 1.0) gd_168 = MathCeil(gd_372);
               else gd_168 = 1;
               gi_480 = gd_168;
               if (MathFloor(gd_372) >= 1.0) gd_152 = MathFloor(gd_372);
               else gd_152 = 1;
               gi_476 = gd_152;
               if (gi_480 == gi_476) gd_356 = 1;
               else {
                  gd_168 = gi_480 - gi_476;
                  gd_356 = (gd_372 - gi_476) / gd_168;
               }
               if (gi_476 <= 29) gi_212 = gi_476;
               else gi_212 = 29;
               if (gi_480 <= 29) gi_216 = gi_480;
               else gi_216 = 29;
               gd_420 = (ld_0 - (gda_504[gi_484 - gi_212])) * (1 - gd_356) / gi_476 + (ld_0 - (gda_504[gi_484 - gi_216])) * gd_356 / gi_480;
            } else {
               if (gd_404 >= MathPow(MathAbs(gd_412 / gd_348), gd_388)) gd_144 = MathPow(MathAbs(gd_412 / gd_348), gd_388);
               else gd_144 = gd_404;
               if (gd_144 < 1.0) gd_152 = 1.0;
               else {
                  if (gd_404 >= MathPow(MathAbs(gd_412 / gd_348), gd_388)) gd_160 = MathPow(MathAbs(gd_412 / gd_348), gd_388);
                  else gd_160 = gd_404;
                  gd_152 = gd_160;
               }
               gd_340 = gd_152;
               gd_364 = MathPow(gd_396, MathSqrt(gd_340));
               if (gd_292 > 0.0) gd_276 = gd_260;
               else gd_276 = gd_260 - gd_292 * gd_364;
               if (gd_324 < 0.0) gd_308 = gd_260;
               else gd_308 = gd_260 - gd_324 * gd_364;
            }
         }
         if (gi_488 > 30) {
            gd_300 = MathPow(gd_332, gd_340);
            gd_444 = (1 - gd_300) * ld_0 + gd_300 * gd_444;
            gd_452 = (ld_0 - gd_444) * (1 - gd_332) + gd_332 * gd_452;
            gd_460 = gd_268 * gd_452 + gd_444;
            gd_284 = -2.0 * gd_300;
            gd_316 = gd_300 * gd_300;
            gd_428 = gd_284 + gd_316 + 1.0;
            gd_420 = (gd_460 - gd_436) * gd_428 + gd_316 * gd_420;
            gd_436 += gd_420;
         }
      }
      gd_128 = gd_436;
      g_ibuf_76[gi_124] = gd_128;
   }
}

void lenars(double ada_0[15000], int ai_4) {
   double ld_8;
   gi_220 = 63;
   gi_224 = 64;
   if (gi_120 == TRUE) {
      for (g_index_208 = 1; g_index_208 < gi_220 + 1; g_index_208++) gda_492[g_index_208] = -1000000;
      for (g_index_208 = gi_224; g_index_208 < 128; g_index_208++) gda_492[g_index_208] = 1000000;
      gi_120 = FALSE;
   }
   gi_468 = TRUE;
   if (Smooth <= 1.0) gd_380 = 0.0000000001;
   else gd_380 = (Smooth - 1.0) / 2.0;
   if (gd_92 < -100.0) gd_268 = 0.5;
   else {
      if (gd_92 > 100.0) gd_268 = 2.5;
      else gd_268 = gd_92 / 100.0 + 1.5;
   }
   gd_144 = MathLog(MathSqrt(gd_380));
   gd_152 = gd_144;
   if (gd_144 / MathLog(2.0) + 2.0 < 0.0) gd_160 = 0;
   else gd_160 = gd_152 / MathLog(2.0) + 2.0;
   gd_404 = gd_160;
   if (gd_404 - 2.0 >= 0.5) gd_388 = gd_404 - 2.0;
   else gd_388 = 0.5;
   gd_372 = MathSqrt(gd_380) * gd_404;
   gd_396 = gd_372 / (gd_372 + 1.0);
   gd_380 = 0.9 * gd_380;
   gd_332 = gd_380 / (gd_380 + 2.0);
   gi_468 = TRUE;
   if (bars == 0) bars = Bars;
   for (gi_124 = bars + 30; gi_124 >= 0; gi_124--) {
      ld_8 = ada_0[gi_124];
      if (gi_484 < 61) {
         gi_484++;
         gda_504[gi_484] = ld_8;
      }
      if (gi_484 > 30) {
         if (gi_468 != FALSE) {
            gi_468 = FALSE;
            gi_212 = 0;
            for (g_index_208 = 1; g_index_208 < 30; g_index_208++)
               if (gda_504[g_index_208 + 1] != gda_504[g_index_208]) gi_212 = 1;
            gi_472 = 30 * gi_212;
            if (gi_472 == 0) gd_308 = ld_8;
            else gd_308 = gda_504[1];
            gd_276 = gd_308;
            if (gi_472 > 29) gi_472 = 29;
         } else gi_472 = 0;
         for (g_index_208 = gi_472; g_index_208 >= 0; g_index_208--) {
            if (g_index_208 == 0) gd_260 = ld_8;
            else gd_260 = gda_504[31 - g_index_208];
            gd_292 = gd_260 - gd_276;
            gd_324 = gd_260 - gd_308;
            if (MathAbs(gd_292) > MathAbs(gd_324)) gd_152 = MathAbs(gd_292);
            else gd_152 = MathAbs(gd_324);
            gd_412 = gd_152;
            gd_136 = gd_412 + 0.0000000001;
            if (gi_236 <= 1) gi_236 = 127;
            else gi_236--;
            if (gi_240 <= 1) gi_240 = 10;
            else gi_240--;
            if (gi_256 < 128) gi_256++;
            gd_176 = gd_176 + gd_136 - gda_500[gi_240];
            gda_500[gi_240] = gd_136;
            if (gi_256 > 10) gd_200 = gd_176 / 10.0;
            else gd_200 = gd_176 / gi_256;
            if (gi_256 == 30) g_index_516 = 0;
            if (gi_256 > 127) {
               gd_184 = gda_496[gi_236];
               gda_496[gi_236] = gd_200;
               gi_252 = 64;
               gi_244 = gi_252;
               gi_unused_512 = gi_244;
               while (gi_252 > 1) {
                  if (gda_492[gi_244] < gd_184) {
                     gi_252 /= 2;
                     gi_244 += gi_252;
                     gi_unused_512 = gi_244;
                  } else {
                     if (gda_492[gi_244] <= gd_184) gi_252 = 1;
                     else {
                        gi_252 /= 2;
                        gi_244 -= gi_252;
                        gi_unused_512 = gi_244;
                     }
                  }
               }
            } else {
               gda_496[gi_236] = gd_200;
               if (gi_220 + gi_224 > 127) {
                  gi_224--;
                  gi_244 = gi_224;
                  gi_unused_512 = gi_244;
               } else {
                  gi_220++;
                  gi_244 = gi_220;
                  gi_unused_512 = gi_244;
               }
               if (gi_220 > 96) gi_228 = 96;
               else gi_228 = gi_220;
               if (gi_224 < 32) gi_232 = 32;
               else gi_232 = gi_224;
            }
            gi_252 = 64;
            gi_248 = gi_252;
            while (gi_252 > 1) {
               if (gda_492[gi_248] >= gd_200) {
                  if (gda_492[gi_248 - 1] <= gd_200) gi_252 = 1;
                  else {
                     gi_252 /= 2;
                     gi_248 -= gi_252;
                  }
               } else {
                  gi_252 /= 2;
                  gi_248 += gi_252;
               }
               if (gi_248 == 127 && gd_200 > gda_492[127]) gi_248 = 128;
            }
            if (gi_256 > 127) {
               if (gi_244 >= gi_248) {
                  if (gi_228 + 1 > gi_248 && gi_232 - 1 < gi_248) gd_192 += gd_200;
                  else
                     if (gi_232 > gi_248 && gi_232 - 1 < gi_244) gd_192 += gda_492[gi_232 - 1];
               } else {
                  if (gi_232 >= gi_248) {
                     if (gi_228 + 1 < gi_248 && gi_228 + 1 > gi_244) gd_192 += gda_492[gi_228 + 1];
                  } else {
                     if (gi_228 + 2 > gi_248) gd_192 += gd_200;
                     else
                        if (gi_228 + 1 < gi_248 && gi_228 + 1 > gi_244) gd_192 += gda_492[gi_228 + 1];
                  }
               }
               if (gi_244 > gi_248) {
                  if (gi_232 - 1 < gi_244 && gi_228 + 1 > gi_244) gd_192 -= gda_492[gi_244];
                  else
                     if (gi_228 < gi_244 && gi_228 + 1 > gi_248) gd_192 -= gda_492[gi_228];
               } else {
                  if (gi_228 + 1 > gi_244 && gi_232 - 1 < gi_244) gd_192 -= gda_492[gi_244];
                  else
                     if (gi_232 > gi_244 && gi_232 < gi_248) gd_192 -= gda_492[gi_232];
               }
            }
            if (gi_244 <= gi_248) {
               if (gi_244 >= gi_248) gda_492[gi_248] = gd_200;
               else {
                  for (g_index_516 = gi_244 + 1; g_index_516 < gi_248; g_index_516++) gda_492[g_index_516 - 1] = gda_492[g_index_516];
                  gda_492[gi_248 - 1] = gd_200;
               }
            } else {
               for (gi_520 = gi_244 - 1; gi_520 >= gi_248; gi_520--) gda_492[gi_520 + 1] = gda_492[gi_520];
               gda_492[gi_248] = gd_200;
            }
            if (gi_256 <= 127) {
               gd_192 = 0;
               for (gi_528 = gi_232; gi_528 < gi_228 + 1; gi_528++) gd_192 += gda_492[gi_528];
            }
            gd_348 = gd_192 / (gi_228 - gi_232 + 1);
            if (gi_488 + 1 > 31) gi_488 = 31;
            else gi_488++;
            if (gi_488 <= 30) {
               if (gd_292 > 0.0) gd_276 = gd_260;
               else gd_276 = gd_260 - gd_292 * gd_396;
               if (gd_324 < 0.0) gd_308 = gd_260;
               else gd_308 = gd_260 - gd_324 * gd_396;
               gd_436 = ld_8;
               if (gi_488 != 30) continue;
               gd_444 = ld_8;
               if (MathCeil(gd_372) >= 1.0) gd_168 = MathCeil(gd_372);
               else gd_168 = 1;
               gi_480 = gd_168;
               if (MathFloor(gd_372) >= 1.0) gd_152 = MathFloor(gd_372);
               else gd_152 = 1;
               gi_476 = gd_152;
               if (gi_480 == gi_476) gd_356 = 1;
               else {
                  gd_168 = gi_480 - gi_476;
                  gd_356 = (gd_372 - gi_476) / gd_168;
               }
               if (gi_476 <= 29) gi_212 = gi_476;
               else gi_212 = 29;
               if (gi_480 <= 29) gi_216 = gi_480;
               else gi_216 = 29;
               gd_420 = (ld_8 - (gda_504[gi_484 - gi_212])) * (1 - gd_356) / gi_476 + (ld_8 - (gda_504[gi_484 - gi_216])) * gd_356 / gi_480;
            } else {
               if (gd_404 >= MathPow(MathAbs(gd_412 / gd_348), gd_388)) gd_144 = MathPow(MathAbs(gd_412 / gd_348), gd_388);
               else gd_144 = gd_404;
               if (gd_144 < 1.0) gd_152 = 1.0;
               else {
                  if (gd_404 >= MathPow(MathAbs(gd_412 / gd_348), gd_388)) gd_160 = MathPow(MathAbs(gd_412 / gd_348), gd_388);
                  else gd_160 = gd_404;
                  gd_152 = gd_160;
               }
               gd_340 = gd_152;
               gd_364 = MathPow(gd_396, MathSqrt(gd_340));
               if (gd_292 > 0.0) gd_276 = gd_260;
               else gd_276 = gd_260 - gd_292 * gd_364;
               if (gd_324 < 0.0) gd_308 = gd_260;
               else gd_308 = gd_260 - gd_324 * gd_364;
            }
         }
         if (gi_488 > 30) {
            gd_300 = MathPow(gd_332, gd_340);
            gd_444 = (1 - gd_300) * ld_8 + gd_300 * gd_444;
            gd_452 = (ld_8 - gd_444) * (1 - gd_332) + gd_332 * gd_452;
            gd_460 = gd_268 * gd_452 + gd_444;
            gd_284 = -2.0 * gd_300;
            gd_316 = gd_300 * gd_300;
            gd_428 = gd_284 + gd_316 + 1.0;
            gd_420 = (gd_460 - gd_436) * gd_428 + gd_316 * gd_420;
            gd_436 += gd_420;
         }
      }
      gd_128 = gd_436;
      if (ai_4 == 1) g_ibuf_76[gi_124] = gd_128;
      else g_ibuf_556[gi_124] = gd_128;
   }
}

//+------------------------------------------------------------------+
//| Moving Average                                                   |
//+------------------------------------------------------------------+
void Moving_Averages(int methode, int periode, int MaxBars2)
  {
   for(int i=MaxBars2; i>=0; i--) v4[i] = iMAOnArray(g_ibuf_76,0,periode,0,methode,i);
   return(0);
  }

Recommend