Navigation:Home > Content >

Volamat6.mq4

Time: 2014-11-09 | Download file:Volamat6.mq4

//+------------------------------------------------------------------+
//|                                      Volamat6.mq4                                                      |
//|                         Gemeinnuetziger Strenzfeld Fonds - GSF - e.V.                |
//|                                Strenzfeldfonds@email.de                                           |
//+-------------------------------------------------------------------+
//+------------------------------------------------------------------+
//|                                               Custom BB_MACD.mq4 |
//|                                     Copyright © 2005, adoleh2000 |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008 Gemeinnuetziger Strenzfeld Fonds - GSF - e.V."
#property link     "Strenzfeldfonds@email.de"
//---- indicator settings
#property  indicator_separate_window
#property  indicator_buffers 4
#property  indicator_color1  Lime    //bbMacd up
#property  indicator_color2  Magenta //bbMacd up
#property  indicator_color3  Blue    //Upperband
#property  indicator_color4  Red     //Lowerband
//______________ indicator parameters
extern int    FastLen                   = 12;
extern int    SlowLen                   = 26;
extern int    Length                    = 10;
extern int    barsCount                 = 400;
extern double StDv                      = 2.5;
extern string __Manuel_Bedienen________ = "____________________________";
extern bool   Manuell_Bedienen          = false;
extern double MACD_Korrekturfaktor      = 1.0;
extern int    Abstand_FastLen_SlowLen   = 1000;
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              = "MADC-UP.wav";
extern string Sounddatei_2              = "MADC-DOWN.wav";
extern bool   Pfeilalert                = false;
//----
int loopbegin;
int shift;
double zeroline;
//---- indicator buffers
double ExtMapBuffer1[];  // bbMacd
double ExtMapBuffer2[];  // bbMacd
double ExtMapBuffer3[];  // Upperband Line
double ExtMapBuffer4[];  // Lowerband Line
//---- buffers
double bbMacd[];
double Upperband[];
double Lowerband[];
double avg[];
double bbMacdline;
double sDev;
double mean;
double sumSqr;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  { 
//---- 6 additional buffers are used for counting.
   IndicatorBuffers(8);   
//---- drawing settings     
   SetIndexBuffer(0, ExtMapBuffer1); // bbMacd line
   SetIndexStyle(0, DRAW_ARROW);
   SetIndexArrow(0, 108);
   IndicatorDigits(Digits + 1);
//----
   SetIndexBuffer(1, ExtMapBuffer2); // bbMacd line
   SetIndexStyle(1, DRAW_ARROW);
   SetIndexArrow(1, 108);
   IndicatorDigits(Digits + 1);
//----   
   SetIndexBuffer(2, ExtMapBuffer3); // Upperband line
   SetIndexStyle(2, DRAW_LINE, STYLE_SOLID, 1);
   IndicatorDigits(Digits + 1);
//----   
   SetIndexBuffer(3, ExtMapBuffer4); // Lowerband line
   SetIndexStyle(3, DRAW_LINE, STYLE_SOLID, 1);
   IndicatorDigits(Digits + 1);
//----
   SetIndexBuffer(4, bbMacd);
   SetIndexBuffer(5, Upperband);        
   SetIndexBuffer(6, Lowerband);
   SetIndexBuffer(7, avg);    
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("BB MACD(" + FastLen + "," + SlowLen + "," + Length+")");
   SetIndexLabel(0, "bbMacd");
   SetIndexLabel(1, "Upperband");
   SetIndexLabel(2, "Lowerband");  
//---- initialization done
   string WU_Hoehe="WU_Hoehe "+WindowHandle(Symbol(),0);
   if(GlobalVariableCheck(WU_Hoehe))GlobalVariableDel(WU_Hoehe);
   string BBMACD_Trend="BBMACD_Trend "+WindowHandle(Symbol(),0);
   if(GlobalVariableCheck(BBMACD_Trend))GlobalVariableDel(BBMACD_Trend);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
string WU_Hoehe="WU_Hoehe "+WindowHandle(Symbol(),0);
if(GlobalVariableCheck(WU_Hoehe))GlobalVariableDel(WU_Hoehe);
string BBMACD_Trend="BBMACD_Trend "+WindowHandle(Symbol(),0);
if(GlobalVariableCheck(BBMACD_Trend))GlobalVariableDel(BBMACD_Trend);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom BB_MACD                                                   |
//+------------------------------------------------------------------+
int start()
  {
   if(Manuell_Bedienen==false)
   {
   string ChannelPips="ChannelPips "+WindowHandle(Symbol(),0);  
   if(GlobalVariableCheck(ChannelPips))
     {
      double a=10,b=100;
      FastLen=((a/b)*GlobalVariableGet(ChannelPips))*MACD_Korrekturfaktor;      
      SlowLen=(FastLen*Abstand_FastLen_SlowLen)/100;            
      //Comment(SlowLen,"   ",FastLen,"  ",GlobalVariableGet(ChannelPips),"\n",ChannelPips);
      IndicatorShortName("BB MACD(" + FastLen + "," + SlowLen + "," + Length+")");
     }else Alert("BB_MACD Global Variable nicht gefunden fьr Automatik Steuerung.");   
   }
   
   int limit;
   int counted_bars = IndicatorCounted();
   if(counted_bars < 0) return(-1);
   if(counted_bars > 0) counted_bars--;
      if (barsCount > 0)
            limit = MathMin(Bars - counted_bars,barsCount);
      else  limit = Bars - counted_bars;
//----
   for(int i = 0; i < limit; i++)
       bbMacd[i] = iMA(NULL, 0, FastLen, 0, MODE_EMA, PRICE_CLOSE, i) - 
                   iMA(NULL, 0, SlowLen, 0, MODE_EMA, PRICE_CLOSE, i);
//----
   for(i = 0; i < limit; i++)
     {
       avg[i] = iMAOnArray(bbMacd, 0, Length, 0, MODE_EMA, i);
       sDev   = iStdDevOnArray(bbMacd, 0, Length, MODE_EMA, 0, i);  
       Upperband[i] = avg[i] + (StDv * sDev);
       Lowerband[i] = avg[i] - (StDv * sDev);
       ExtMapBuffer1[i]=bbMacd[i];     // Uptrend bbMacd
       ExtMapBuffer2[i]=bbMacd[i];     // downtrend bbMacd
       ExtMapBuffer3[i]=Upperband[i];  // Upperband
       ExtMapBuffer4[i]=Lowerband[i];  // Lowerband
       //----

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
 int dd2;static int tickcount,tickcount2,merk1,merk2,Startzeit1,Startzeit2,signal;
 if(Bars-IndicatorCounted()>=2) dd2=barsCount; else dd2=0;
        int ik=1;
        int ik2=2;
      if(Pfeilalert==true)
      while(dd2>=0)
       {  
        if(bbMacd[dd2+ik]>=bbMacd[dd2+ik2] && merk1<=0)
          { //Hoch
          string objekt = "MACDH";
          if(ObjectFind(objekt) >= 0) ObjectDelete(objekt);
          if(!ObjectCreate(objekt, OBJ_ARROW, WindowOnDropped(), Time[dd2+ik], bbMacd[dd2+ik])) Print("error: cant create ",objekt," on Window ",WindowOnDropped(),"! code #",GetLastError());
          if(!ObjectSet(objekt, OBJPROP_ARROWCODE, 233)) Print("error: cant set xdistance ",objekt," on Window ",WindowOnDropped(),"! code #",GetLastError());
          if(!ObjectSet(objekt, OBJPROP_WIDTH, 1)) Print("error: cant set width ",objekt," on Window ",WindowOnDropped(),"! code #",GetLastError());
          if(!ObjectSet(objekt, OBJPROP_COLOR, DeepSkyBlue)) Print("error: cant set color ",objekt," on Window ",WindowOnDropped(),"! code #",GetLastError());
          merk1++;merk2=0;signal=1;
          }           
         if(bbMacd[dd2+ik]<=bbMacd[dd2+ik2] && merk2<=0)
          { //Runter
          objekt = "MACDR";
          if(ObjectFind(objekt) >= 0) ObjectDelete(objekt);
          if(!ObjectCreate(objekt, OBJ_ARROW, WindowOnDropped(), Time[dd2+ik], bbMacd[dd2+ik]+0.00030)) Print("error: cant create ",objekt," on Window ",WindowOnDropped(),"! code #",GetLastError());
          if(!ObjectSet(objekt, OBJPROP_ARROWCODE, 234)) Print("error: cant set xdistance ",objekt," on Window ",WindowOnDropped(),"! code #",GetLastError());
          if(!ObjectSet(objekt, OBJPROP_WIDTH, 1)) Print("error: cant set width ",objekt," on Window ",WindowOnDropped(),"! code #",GetLastError());
          if(!ObjectSet(objekt, OBJPROP_COLOR, Red)) Print("error: cant set color ",objekt," on Window ",WindowOnDropped(),"! code #",GetLastError());
          merk2++;merk1=0;signal=2;
          }
       dd2--;
       }
string BBMACD_Trend="BBMACD_Trend "+WindowHandle(Symbol(),0);
if(bbMacd[0]>=bbMacd[1])
{
   string objektname4 ="long";   
   if( ObjectFind("short")  >= 0)ObjectDelete("short");
   if( ObjectFind("short_") >= 0)ObjectDelete("short_");
   if( ObjectFind(objektname4) >= 0)                                        ObjectDelete(objektname4);
   if(!ObjectCreate(objektname4, OBJ_LABEL, WindowOnDropped(), 0, 0))       Print("error: cant create ",objektname4," on Window ",WindowOnDropped(),"! code #",GetLastError());
   if(!ObjectSet(objektname4, OBJPROP_XDISTANCE, 2))                       Print("error: cant set xdistance ",objektname4," on Window ",WindowOnDropped(),"! code #",GetLastError());
   if(!ObjectSet(objektname4, OBJPROP_YDISTANCE, 18))                       Print("error: cant set ydistance ",objektname4," on Window ",WindowOnDropped(),"! code #",GetLastError());
   if(!ObjectSetText(objektname4, "Trend Long", 9, "Arial Black", Blue)) Print("error: cant et Text ",objektname4," on Window ",WindowOnDropped(),"! code #",GetLastError());  
   objektname4 = "long_";   
   if( ObjectFind(objektname4) >= 0)                                                       ObjectDelete(objektname4);
   if(!ObjectCreate(objektname4, OBJ_LABEL, WindowOnDropped(), 0, 0))                      Print("error: cant create ",objektname4," on Window ",WindowOnDropped(),"! code #",GetLastError());
   if(!ObjectSet(objektname4, OBJPROP_XDISTANCE, 80))                                       Print("error: cant set xdistance ",objektname4," on Window ",WindowOnDropped(),"! code #",GetLastError());
   if(!ObjectSet(objektname4, OBJPROP_YDISTANCE, 14))                                       Print("error: cant set ydistance ",objektname4," on Window ",WindowOnDropped(),"! code #",GetLastError());
   if(!ObjectSetText(objektname4, CharToStr(110), 20, "Wingdings", Blue)) Print("error: cant set Text ",objektname4," on Window ",WindowOnDropped(),"! code #",GetLastError());      
   GlobalVariableSet(BBMACD_Trend,1);
}
if(bbMacd[0]<=bbMacd[1])
{
   if( ObjectFind("long")  >= 0)ObjectDelete("long");
   if( ObjectFind("long_") >= 0)ObjectDelete("long_");
   objektname4 ="short";   
   if( ObjectFind(objektname4) >= 0)                                        ObjectDelete(objektname4);
   if(!ObjectCreate(objektname4, OBJ_LABEL, WindowOnDropped(), 0, 0))       Print("error: cant create ",objektname4," on Window ",WindowOnDropped(),"! code #",GetLastError());
   if(!ObjectSet(objektname4, OBJPROP_XDISTANCE, 2))                       Print("error: cant set xdistance ",objektname4," on Window ",WindowOnDropped(),"! code #",GetLastError());
   if(!ObjectSet(objektname4, OBJPROP_YDISTANCE, 18))                       Print("error: cant set ydistance ",objektname4," on Window ",WindowOnDropped(),"! code #",GetLastError());
   if(!ObjectSetText(objektname4, "Trend Short", 9, "Arial Black", Red)) Print("error: cant et Text ",objektname4," on Window ",WindowOnDropped(),"! code #",GetLastError());  
   objektname4 = "short_";   
   if( ObjectFind(objektname4) >= 0)                                                       ObjectDelete(objektname4);
   if(!ObjectCreate(objektname4, OBJ_LABEL, WindowOnDropped(), 0, 0))                      Print("error: cant create ",objektname4," on Window ",WindowOnDropped(),"! code #",GetLastError());
   if(!ObjectSet(objektname4, OBJPROP_XDISTANCE, 80))                                       Print("error: cant set xdistance ",objektname4," on Window ",WindowOnDropped(),"! code #",GetLastError());
   if(!ObjectSet(objektname4, OBJPROP_YDISTANCE, 14))                                       Print("error: cant set ydistance ",objektname4," on Window ",WindowOnDropped(),"! code #",GetLastError());
   if(!ObjectSetText(objektname4, CharToStr(110), 20, "Wingdings", Red)) Print("error: cant set Text ",objektname4," on Window ",WindowOnDropped(),"! code #",GetLastError());      
   GlobalVariableSet(BBMACD_Trend,2);
}      
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
//----Sounds
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)
  {
     if(merk1>0 && tickcount=Startzeit1+(Sound_Play_Abstand_Sk*1000) || Startzeit1==0))
           {//Hoch
           PlaySound(Sounddatei_1);
           tickcount++;
           Startzeit1=GetTickCount();
           }
     if(merk2>0 && tickcount2=Startzeit2+(Sound_Play_Abstand_Sk*1000) || Startzeit2==0))
           {//Runter
           PlaySound(Sounddatei_2);
           tickcount2++;
           Startzeit2=GetTickCount();
           }
  }
//----
     string t1="BB_Macd_fastlen", scriptname="BB_MACD";
     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,172))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="BB_Macd_fastlen_";
     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,179))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, "BB_MACD FastLen: "+DoubleToStr(FastLen,2), 11, "Arial", White);
     //----Windows Fenster ID
     string WH_BB="WH_BB "+WindowHandle(Symbol(),0);
     GlobalVariableSet(WH_BB, WindowHandle(Symbol(),Period()) );     
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+ 
       if(bbMacd[i] > bbMacd[i+1])
           ExtMapBuffer2[i] = EMPTY_VALUE;
       //----
       if(bbMacd[i] < bbMacd[i+1])
           ExtMapBuffer1[i] = EMPTY_VALUE;
     }      
//---- done
   return(0);
  }
//+------------------------------------------------------------------+
 

Recommend