Navigation:Home > Content >

macd_osma_v3.2.mq4

Time: 2014-11-22 | Download file:macd_osma_v3.2.mq4

//+------------------------------------------------------------------+
//| CoreWinTT желает Вам успехов и удачи! :)                           
//|   Previously called b_v2_macd_osmax.mq4 from MQL4.com
//| Code corrected and made more readable and faster by Big Be, March 2011
//| This version also agrees with OsMA indicator
//+------------------------------------------------------------------+
//|  More info: http://www.forex-tsd.com/indicators-metatrader-4/9542-repainting-indicators-17.html

#property indicator_separate_window
#property indicator_buffers 6
#property indicator_color1 Yellow
#property indicator_width1 3
#property indicator_color2 Magenta
#property indicator_width2 3
#property indicator_color3 Aqua
#property indicator_width3 3
#property indicator_color4 Silver //White
#property indicator_width4 1
#property indicator_color5 Red
#property indicator_width5 1
#property indicator_color6 DodgerBlue
#property indicator_width6 2
#property indicator_level1 0
#property indicator_levelstyle STYLE_DOT
#property indicator_levelcolor Gold


extern int FastEMA   = 12;  //12;
extern int SlowEMA   = 26; //26;
extern int SignalEMA = 9;  //9;
extern int OsmaX     = 2;  //2;
extern bool ShowLines = true;

double OsMA_un_buffer1[]; //Yellow
double OsMA_Dn_buffer2[]; //Magenta
double OsMA_Up_buffer3[]; //Aqua
double OsMA_buffer4[];
double Signal_buffer5[];
double MACD_buffer6[];

int init()
{

   SetIndexBuffer(0,OsMA_un_buffer1); SetIndexStyle(0,DRAW_HISTOGRAM); SetIndexLabel(0,"OsMA_un  MACD_OsMA_v3.2");
   SetIndexBuffer(1,OsMA_Dn_buffer2); SetIndexStyle(1,DRAW_HISTOGRAM); SetIndexLabel(1,"OsMA_Dn");
   SetIndexBuffer(2,OsMA_Up_buffer3); SetIndexStyle(2,DRAW_HISTOGRAM); SetIndexLabel(2,"OsMA_Up"); 
   SetIndexBuffer(3,OsMA_buffer4);    SetIndexStyle(3,DRAW_LINE);      SetIndexLabel(3,"OsMA");   
   SetIndexBuffer(4,Signal_buffer5); 
   SetIndexBuffer(5,MACD_buffer6);
   if(ShowLines == True)
        {SetIndexStyle(4,DRAW_LINE);    SetIndexLabel(4,"Signal");
         SetIndexStyle(5,DRAW_LINE);    SetIndexLabel(5,"MACD("+FastEMA+","+SlowEMA+","+SignalEMA+")");}
   else {SetIndexStyle(4,DRAW_NONE);    SetIndexLabel(4,NULL );
         SetIndexStyle(5,DRAW_NONE);    SetIndexLabel(5,NULL );}   
      
   IndicatorShortName("MACD_OsMA_v3.2 ("+FastEMA+","+SlowEMA+","+SignalEMA+")");

   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));   

return(0);
}

int deinit(){ return(0);}


int start()
{
   double Zero_level;
   double minuse;
   double Vol;
   int counted_bars=IndicatorCounted();
   int i,limit;

   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
   limit = MathMin(Bars-counted_bars,Bars-1);  //unusual
         

   for(i=limit; i>=0; i--) MACD_buffer6[i] = iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i);
   for(i=limit; i>=0; i--){ Signal_buffer5[i] = iMAOnArray(MACD_buffer6,Bars,SignalEMA,0,MODE_EMA,i);
                            OsMA_buffer4[i] = ((iOsMA(NULL,0,FastEMA,SlowEMA,SignalEMA,PRICE_CLOSE,i))*OsmaX);
                           }
   
   for(i=limit; i>=0; i--) 
     {

     if (MACD_buffer6[i]>MACD_buffer6[i+1])  //MACD goes up - Aqua
        {
        OsMA_Dn_buffer2[i]=Zero_level; //0.0
        Vol = OsMA_buffer4[i];
        minuse = Vol - OsMA_buffer4[i+1];
     
        if(minuse>0)  // OsMAW increasing
           {
           OsMA_Up_buffer3[i]=Vol; // Aqua
           OsMA_Dn_buffer2[i]=0; 
           OsMA_un_buffer1[i]=0;
           } 
        
        else 
           {
           if(minuse<=0)  // OsMAW decreasing
              {
              OsMA_Up_buffer3[i]=0; 
              OsMA_Dn_buffer2[i]=0; 
              OsMA_un_buffer1[i]=Vol; // Yellow
              }
           } 
        } 
     else                            //MACD goes down - Magenta
        {
        OsMA_Up_buffer3[i]=Zero_level; //0.0
        Vol = OsMA_buffer4[i];
        minuse = Vol - OsMA_buffer4[i+1];
     
        if(minuse>=0)  // OsMAW increasing
           {
           OsMA_Up_buffer3[i]=0; 
           OsMA_Dn_buffer2[i]=0; 
           OsMA_un_buffer1[i]=Vol; //Yellow
           } 
        
        else 
           {
           if(minuse<0)  // OsMAW decreasing
             {
             OsMA_Up_buffer3[i]=0;
             OsMA_Dn_buffer2[i]=Vol; //Magenta
             OsMA_un_buffer1[i]=0;
             }
           }     
        }
     }
return(0);
} 

Recommend