HMA_Russian_Color_02_mod





//+------------------------------------------------------------------+ 
//| HMA.mq4 
//| Copyright © 2006 WizardSerg <wizardserg@mail.ru>, ?? ??????? ForexMagazine #104 
//| wizardserg@mail.ru 
//|                         Revised by IgorAD,igorad2003@yahoo.co.uk |   
//|                                        http://www.forex-tsd.com/ |                                      
//+------------------------------------------------------------------+
/*
WRR modifications:
changed period to 20
changed method to 3 (Linear weighted moving average)
added notes describing settings for method, price, SetIndexStyle and iMA
added UpColour, DownColour and LineWidth settings

*/
#property copyright "MT4 release WizardSerg <wizardserg@mail.ru>, ?? ??????? ForexMagazine #104" 
#property link      "wizardserg@mail.ru" 

#property indicator_chart_window 
#property indicator_buffers 5 
#property indicator_color1 LimeGreen   //Uptrend Colour
#property indicator_color2 Red         //Downtrend Colour
//---- input parameters 
extern bool       alert=true; 
extern int       period=18;            //period 21 old, period 18 new 

extern int       method=3;             // MODE_SMA old default, MODE_LWMA new default

/*
method settings
MODE_SMA  0 Simple moving average, 
MODE_EMA  1 Exponential moving average, 
MODE_SMMA 2 Smoothed moving average, 
MODE_LWMA 3 Linear weighted moving average. 
*/
extern int       price=0;                          // PRICE_CLOSE
/*
price settings
PRICE_CLOSE    0 Close price. 
PRICE_OPEN     1 Open price. 
PRICE_HIGH     2 High price. 
PRICE_LOW      3 Low price. 
PRICE_MEDIAN   4 Median price, (high+low)/2. 
PRICE_TYPICAL  5 Typical price, (high+low+close)/3. 
PRICE_WEIGHTED 6 Weighted close price, (high+low+close+close)/4. 
*/
extern color    UpColour   = LimeGreen;//indicator_color1 
extern color    DownColour = Red;//indicator_color2
extern int      LineWidth  = 2; //Valid values are: 1,2,3,4,5.
extern color    arrow_up   = DeepSkyBlue;
extern color    arrow_dn   = Orange;
extern int      arrow_size  = 0;
extern int pip_distance=10;
//---- buffers 
double Uptrend[];
double Dntrend[];
double ar_up[];
double ar_dn[];
double ExtMapBuffer[]; 
bool sound;
static datetime soundTag = D'1980.01.01';
//+------------------------------------------------------------------+ 
//| Custom indicator initialization function                         | 
//+------------------------------------------------------------------+ 
int init() 
{ 
    IndicatorBuffers(5);  
    SetIndexBuffer(0, Uptrend); 
    //ArraySetAsSeries(Uptrend, true); 
    SetIndexBuffer(1, Dntrend); 
    //ArraySetAsSeries(Dntrend, true); 
    SetIndexBuffer(2, ExtMapBuffer); 
    ArraySetAsSeries(ExtMapBuffer, true); 
    
    SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,LineWidth,UpColour);
    SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,LineWidth,DownColour);
    
        SetIndexStyle(3, DRAW_ARROW, EMPTY,arrow_size, arrow_up);
    //SetIndexArrow(3, 159);
    SetIndexArrow(3, 233);
    SetIndexBuffer(3, ar_up);
    
    SetIndexStyle(4, DRAW_ARROW, EMPTY,arrow_size, arrow_dn);
    //SetIndexArrow(4, 159);
    SetIndexArrow(4, 234);
    SetIndexBuffer(4, ar_dn); 
    
/*
SetIndexStyle sample and settings descriptions
void SetIndexStyle( int index, int type, int style=EMPTY, int width=EMPTY, color clr=CLR_NONE) 
Sets the new type, style, width and color for a given indicator line. 
Parameters:
index - Line index. Must lie between 0 and 7. 
type  - Shape style. Can be one of Drawing shape styles listed. 
style - Drawing style. It is used for one-pixel thick lines. It can be one of the Drawing shape styles
        listed. EMPTY value means that the style will not be changed. 
width - Line width. Valid values are: 1,2,3,4,5. EMPTY value means that width will not be changed. 
clr   - Line color. Absence of this parameter means that the color will not be changed. 
*/
    
    IndicatorShortName("Hull Moving Average("+period+")"); 
    return(0); 
} 

//+------------------------------------------------------------------+ 
//| Custor indicator deinitialization function                       | 
//+------------------------------------------------------------------+ 
int deinit() 
{ 
    // ???? ????? ?????? ?????? 
    return(0); 
} 

//+------------------------------------------------------------------+ 
//| ?????????? ???????                                               | 
//+------------------------------------------------------------------+ 
double WMA(int x, int p) 
{ 
    return(iMA(NULL, 0, p, 0, method, price, x));    
}
/*
iMA example and settings descriptions
double iMA( string symbol, int timeframe, int period, int ma_shift, int ma_method, int applied_price, int shift) 
Calculates the Moving average indicator and returns its value. 
Parameters:
symbol        - Symbol the data of which should be used to calculate indicator. NULL means the current symbol. 
timeframe     - Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe. 
period        - Averaging period for calculation. 
ma_shift      - MA shift. Indicators line offset relate to the chart by timeframe. 
ma_method     - MA method. It can be any of the Moving Average method enumeration value. 
applied_price - Applied price. It can be any of Applied price enumeration values. 
shift         - Index of the value taken from the indicator buffer (shift relative to the current bar the given
                amount of periods ago).
*/


//+------------------------------------------------------------------+ 
//| Custom indicator iteration function                              | 
//+------------------------------------------------------------------+ 
int start() 
{ 
    int counted_bars = IndicatorCounted(); 
    
    if(counted_bars < 0) 
        return(-1); 
                  
    int x = 0; 
    int p = MathSqrt(period);              
    int e = Bars - counted_bars + period + 1; 
    
    double vect[], trend[]; 
    
    if(e > Bars) 
        e = Bars;    

    ArrayResize(vect, e); 
    ArraySetAsSeries(vect, true);
    ArrayResize(trend, e); 
    ArraySetAsSeries(trend, true); 
    
    for(x = 0; x < e; x++) 
    { 
        vect[x] = 2*WMA(x, period/2) - WMA(x, period);        
 //       Print("Bar date/time: ", TimeToStr(Time[x]), " close: ", Close[x], " vect[", x, "] = ", vect[x], " 2*WMA(p/2) = ", 2*WMA(x, period/2), " WMA(p) = ",  WMA(x, period)); 
    } 

    for(x = 0; x < e-period; x++)
     
        ExtMapBuffer[x] = iMAOnArray(vect, 0, p, 0, method, x);        
    
    for(x = e-period; x >= 0; x--)
    {     
        trend[x] = trend[x+1];
        if (ExtMapBuffer[x]> ExtMapBuffer[x+1]) trend[x] =1;
        if (ExtMapBuffer[x]< ExtMapBuffer[x+1]) trend[x] =-1;
                if (ExtMapBuffer[x+2]< ExtMapBuffer[x+3]&&ExtMapBuffer[x+1]> ExtMapBuffer[x+2]) {sound=true;ar_up[x] =ExtMapBuffer[x+1]-pip_distance*Point;GlobalVariableSet("hma_signal",2);}
        if (ExtMapBuffer[x+2]> ExtMapBuffer[x+3]&&ExtMapBuffer[x+1]< ExtMapBuffer[x+2]) {sound=true;ar_dn[x] =ExtMapBuffer[x+1]+pip_distance*Point;GlobalVariableSet("hma_signal",3);}
     if (alert&&sound&&ExtMapBuffer[x+2]< ExtMapBuffer[x+3]&&ExtMapBuffer[x+1]> ExtMapBuffer[x+2]&&x==0&& soundTag!=Time[0]){PlaySound ("alert.wav");sound=false;soundTag = Time[0];}
      if (alert&&sound&&ExtMapBuffer[x+2]> ExtMapBuffer[x+3]&&ExtMapBuffer[x+1]< ExtMapBuffer[x+2]&&x==0&& soundTag!=Time[0]){PlaySound ("alert.wav");sound=false;soundTag = Time[0];}
      sound=false;
    if (trend[x]>0)
    { Uptrend[x] = ExtMapBuffer[x]; 
      if (trend[x+1]<0) Uptrend[x+1]=ExtMapBuffer[x+1];
      
      Dntrend[x] = EMPTY_VALUE;
    }
    else              
    if (trend[x]<0)
    { 
      Dntrend[x] = ExtMapBuffer[x]; 
      
      if (trend[x+1]>0) Dntrend[x+1]=ExtMapBuffer[x+1];
      
      Uptrend[x] = EMPTY_VALUE;
    }              
     
    //Print( " trend=",trend[x]);
    }
    
    return(0); 
} 
//+------------------------------------------------------------------+ 



Sample





Analysis



Market Information Used:

Series array that contains open time of each bar


Indicator Curves created:


Implements a curve of type DRAW_LINE
Implements a curve of type DRAW_ARROW
Implements a curve of type int type

Indicators Used:

Moving average indicator


Custom Indicators Used:

Order Management characteristics:

Other Features: