OsHMA
Indicators Used
Moving average indicatorMoving average indicator
Miscellaneous
Implements a curve of type %1
0 Views
0 Downloads
0 Favorites
OsHMA
//+------------------------------------------------------------------+
//|                                                        OsHMA.mq4 |
//|                           Copyright © 2009, Meta Quotes & sealdo |
//|                                         sealdo@yandex.ru         |
//+------------------------------------------------------------------+
#property  copyright "Copyright © 2009, Meta Quotes & sealdo"
#property  link      "http://www.metaquotes.net/"
//---- indicator settings
#property  indicator_separate_window
//#property  indicator_chart_window
#property  indicator_buffers 1
#property  indicator_color1  DarkOrchid
#property  indicator_width1  2
//---- indicator parameters
extern int FastHMA = 12; 
extern int SlowHMA = 26; 
//---- indicator buffers
double	OsmaBuffer[];
double	PreHMA1[]; 
double	PreHMA2[]; 

//+------------------------------------------------------------------+
int pF, pS; 

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- 4 additional buffers are used for counting.
   IndicatorBuffers(3);
   
//---- drawing settings
   SetIndexStyle(0,DRAW_HISTOGRAM);
   //SetIndexDrawBegin(0,SignalSMA);
   IndicatorDigits(Digits+2);
   
//---- 5 indicator buffers mapping
   SetIndexBuffer(0,OsmaBuffer);
   SetIndexBuffer(1,PreHMA1);
   SetIndexBuffer(2,PreHMA2);
   
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("OsHMA("+FastHMA+","+SlowHMA+")");
   
	pF = MathSqrt(FastHMA); 
	pS = MathSqrt(SlowHMA); 
	
//---- initialization done
   return(0);
  }

  
//+------------------------------------------------------------------+
double WMA(int x, int p) { 
	return(iMA(NULL, 0, p, 0, MODE_LWMA, PRICE_CLOSE, x)); 
} 


//+------------------------------------------------------------------+
//| Moving Average of Oscillator                                     |
//+------------------------------------------------------------------+
int start()
  {
   int limit;
   int counted_bars=IndicatorCounted();
   
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
   
//---- preparing the HMA
   for(int i=0; i<limit; i++) {
   	PreHMA1[i] = 2*WMA(i, FastHMA/2) - WMA(i, FastHMA); 
   	PreHMA2[i] = 2*WMA(i, SlowHMA/2) - WMA(i, SlowHMA); 
   }

//---- macd counted in the 1-st additional buffer
   for(i=0; i<limit; i++)
   	OsmaBuffer[i]= iMAOnArray(PreHMA1, 0, pF, 0, MODE_LWMA, i) - iMAOnArray(PreHMA2, 0, pS, 0, MODE_LWMA, i);
      
//---- done
   return(0);
  }
//+------------------------------------------------------------------+

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---