Author: Copyright � 2010, LeMan.
Indicators Used
Moving average indicatorMoving average indicator
Miscellaneous
Implements a curve of type %1
0 Views
0 Downloads
0 Favorites
variation
//+------------------------------------------------------------------+
//|                                                    variation.mq4 |
//|                                         Copyright © 2010, LeMan. |
//|                                                 b-market@mail.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2010, LeMan."
#property link      "b-market@mail.ru"

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Red
//---- input parameters
extern int       N=20;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
  string short_name;
  IndicatorDigits(Digits+2);
  IndicatorBuffers(2);
//---- indicators
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexBuffer(1,ExtMapBuffer2);
//----
   if (N <= 0) N = 20;   
//----
   SetIndexDrawBegin(0, N*2); 
//----
   short_name = "Variation (" + N + ")";
   IndicatorShortName(short_name);
   SetIndexLabel(0, short_name);     
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
//----
   int limit = Bars-N-1;
   for (int i = limit; i >= 0; i--) {
      double ma = iMA(NULL,0,N,0,MODE_SMA,PRICE_CLOSE,i);
      ExtMapBuffer2[i] = Close[i]-ma;
   }  
//----
   i = Bars-N*2-1;
   while (i >= 0) {
      double vr = iMAOnArray(ExtMapBuffer2,Bars,N,0,MODE_SMA,i);
      double mov = iMA(NULL,0,N,0,MODE_SMA,PRICE_CLOSE,i);
      ExtMapBuffer1[i] = Close[i] - (mov + vr);
      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 ---