Indicators Used
0
Views
0
Downloads
0
Favorites
MA on ATR
ÿþ/********************************************************************\
| MA on ATR.mq5 |
| © 2021, Alexey Viktorov |
| https://www.mql5.com/ru/users/alexeyvik/news |
\********************************************************************/
#property copyright "© 2021, Alexey Viktorov"
#property link "https://www.mql5.com/ru/users/alexeyvik/news"
#property version "1.00"
#property indicator_separate_window
//---
#include <MovingAverages.mqh>
//---
#property indicator_buffers 2
#property indicator_plots 2
#property indicator_type1 DRAW_LINE
#property indicator_type2 DRAW_LINE
#property indicator_color1 clrBlueViolet
#property indicator_color2 clrRed
#property indicator_label1 "ATR"
#property indicator_label2 "MA"
#property indicator_width1 2
#property indicator_width2 1
input int period_ATR = 7; // 5@8>4 8=48:0B>@0 Average True Range
input int period_MA_ATR = 30; // 5@8>4 A@54=59 ?> 8=48:0B>@C Average True Range
input ENUM_MA_METHOD metod_MA = MODE_SMA; // <5B>4 A3;06820=8O MA
int handleATR,
handleMA;
double ATR[];
double MA_ATR[];
//---
/*********************************************************************\
| Custom indicator initialization function |
\*********************************************************************/
int OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0, ATR);
SetIndexBuffer(1, MA_ATR);
IndicatorSetInteger(INDICATOR_DIGITS, _Digits);
handleATR = iATR(_Symbol, PERIOD_CURRENT, period_ATR);
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[])
{
//---
int copyBuffer = CopyBuffer(handleATR, 0, 0, rates_total, ATR);
switch(metod_MA)
{
case MODE_SMA :
SimpleMAOnBuffer(rates_total, prev_calculated, period_ATR, period_MA_ATR, ATR, MA_ATR);
break;
case MODE_EMA :
ExponentialMAOnBuffer(rates_total, prev_calculated, period_ATR, period_MA_ATR, ATR, MA_ATR);
break;
case MODE_SMMA :
SmoothedMAOnBuffer(rates_total, prev_calculated, period_MA_ATR, period_MA_ATR, ATR, MA_ATR);
break;
case MODE_LWMA :
LinearWeightedMAOnBuffer(rates_total, prev_calculated, period_ATR, period_MA_ATR, ATR, MA_ATR);
break;
default:
break;
}
//--- return value of prev_calculated for next call
return(rates_total);
}/********************************************************************/
Comments
Markdown Formatting Guide
# H1
## H2
### H3
**bold text**
*italicized text*
[title](https://www.example.com)

`code`
```
code block
```
> blockquote
- Item 1
- Item 2
1. First item
2. Second item
---