Author: Alex_Shmatko
Indicators Used
Indicator of the average true rangeMoving average indicator
Miscellaneous
Implements a curve of type %1
0 Views
0 Downloads
0 Favorites
iMA_ATR
ÿþ//+------------------------------------------------------------------+

//|                                                      iMA_ATR.mq4 |

//|                                                     Alex_Shmatko |

//+------------------------------------------------------------------+

#property copyright "Alex_Shmatko"

#property version   "1.20"

#property strict

#property indicator_separate_window

#property indicator_buffers 2

#property indicator_color1 clrBrown

#property indicator_color2 clrDodgerBlue

//+------------------------------------------------------------------+

//| input parameters                                                 |

//+------------------------------------------------------------------+

input int   ATR_period = 14;            // ATR period

input int   MA_period  = 10;            // MA period

input color ATR_color  = clrBrown;      // ATR color

input color MA_color   = clrDodgerBlue; // MA color

//---

//+------------------------------------------------------------------+

//| variables                                                        |

//+------------------------------------------------------------------+

double ExtMapBuffer1[];

double ExtMapBuffer2[];

double ATR[];

int i;

int i2;

//---

//+------------------------------------------------------------------+

//| Custom indicator initialization function                         |

//+------------------------------------------------------------------+

int OnInit()

  {

//--- indicator buffers mapping

   SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, 2, ATR_color); // ATR

   SetIndexBuffer(0, ExtMapBuffer1);                       // ATR

   

   SetIndexStyle(1, DRAW_LINE, STYLE_SOLID, 2, MA_color);  // ATR -> MA

   SetIndexBuffer(1, ExtMapBuffer2);                       // ATR -> MA

//---

   return(INIT_SUCCEEDED);

  }

//+------------------------------------------------------------------+

//| Custom indicator iteration function                              |

//+------------------------------------------------------------------+

int OnCalculate(const int rates_total,

                const int prev_calculated,

                const datetime &time[],

                const double &open[],

                const double &high[],

                const double &low[],

                const double &close[],

                const long &tick_volume[],

                const long &volume[],

                const int &spread[])

  {

//---

   ArrayResize(ATR, rates_total, rates_total); // resizing the data array to the current number of bars

   ArraySetAsSeries(ATR, true);                // indexing of the array elements as in timeseries

   

   i2 = i = rates_total - prev_calculated - 1;

   

   if(i < 0) i2 = i = 0;

   

   while(i2 > 0)

      {

       ATR[i2] = iATR(NULL, 0, ATR_period, i2);

       ExtMapBuffer1[i2] = iATR(NULL, 0, ATR_period, i2);

       

       i2--;

      }

   if(i2 == 0)

      {

       ATR[i2] = iATR(NULL, 0, ATR_period, i2);

       ExtMapBuffer1[i2] = iATR(NULL, 0, ATR_period, i2);

      }

   while(i2 <= i)

      {

       ExtMapBuffer2[i2] = iMAOnArray(ATR, 0, MA_period, 0, MODE_EMA, i2);

       

       i2++;

      }

//--- return value of prev_calculated for next call

   return(rates_total);

  }

//+------------------------------------------------------------------+

//---

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 ---