Author: Copyright 2018, MetaQuotes Software Corp.
Indicators Used
Moving average indicatorStandard Deviation indicator
Miscellaneous
Implements a curve of type %1
0 Views
0 Downloads
0 Favorites
DMI Index
//+------------------------------------------------------------------+
//|                                                    DMI Index.mq4 |
//|                        Copyright 2018, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_separate_window
#property indicator_buffers 1

#property indicator_color1 clrMediumTurquoise

extern int                MA_Fast               = 8;           // Fast MA Period
extern int                MA_Slow               = 13;          // Slow MA Period
extern ENUM_MA_METHOD     Fast_MA_Type          = MODE_EMA;    // Fast MA Type
extern ENUM_MA_METHOD     Slow_MA_Type          = MODE_EMA;    // Slow MA Type
extern ENUM_APPLIED_PRICE Fast_MA_Applied_Price = PRICE_CLOSE; // Fast MA Applied Price
extern ENUM_APPLIED_PRICE Slow_MA_Applied_Price = PRICE_CLOSE; // Slow MA Applied Price

double DMI_Buffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   IndicatorBuffers(1);
//--- indicator buffers mapping
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,DMI_Buffer);
   
   if(MA_Fast <= 0 || MA_Slow <= 0)
    {
     Print("MA Period should be above zero");
     return(INIT_FAILED);
    }
    
   if(MA_Slow <= MA_Fast) 
    {
     Print("Slow MA Period should be more than Fast MA Period.");
     return(INIT_FAILED);
    } 
   
   IndicatorShortName("DMI Index");  
   IndicatorDigits(_Digits);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
//----
   return(0);
  }  
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int i, counted_bars=IndicatorCounted();
   if(Bars <= MA_Slow) return(0);
   
   //---- initial zero
   if(counted_bars<1) ArrayInitialize(DMI_Buffer,EMPTY_VALUE);

   //----
   i=Bars-MA_Slow-1;
   if(counted_bars >= MA_Slow) i=Bars-counted_bars-1;
   
   while(i >= 0)
    {
     double ma_fast = iMA(NULL,Period(),MA_Fast,0,Fast_MA_Type,Fast_MA_Applied_Price,i);
     double ma_slow = iMA(NULL,Period(),MA_Slow,0,Slow_MA_Type,Slow_MA_Applied_Price,i);
     double StdDev  = iStdDev(NULL,Period(),MA_Fast,0,Fast_MA_Type,Fast_MA_Applied_Price,i);
     
     if(StdDev != 0) DMI_Buffer[i] = (ma_fast - ma_slow)/StdDev;
     i--;
    }
     
   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 ---