Author: © Alexey Viktorov 2021
Indicators Used
Indicator of the average true rangeMoving average indicator
Miscellaneous
Implements a curve of type %1It issuies visual alerts to the screen
0 Views
0 Downloads
0 Favorites
MA on ATR
ÿþ/********************************************************************\

|                                                      MA on ATR.mq4 |

|                                             © Alexey Viktorov 2021 |

|                       https://www.mql5.com/ru/users/alexeyvik/news |

\********************************************************************/

#property copyright "© Alexey Viktorov 2021"

#property link      "https://www.mql5.com/ru/users/alexeyvik/news"

#property version   "1.00"

#property strict

#property indicator_separate_window

#property indicator_buffers      2

#property indicator_color1       clrBlueViolet

#property indicator_color2       clrRed

#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

sinput	bool						showAlert				=	false;			//	Alert ?> ?5@5A5G5=8N

double ATR[]; //225@E=OO ;8=8O

double MA_ATR[]; //=86=OO ;8=8O

/*********************************************************************\

|               Custom indicator initialization function              |

\*********************************************************************/

int OnInit()

 {

//--- indicator buffers mapping

  SetIndexBuffer(0, ATR);

  SetIndexStyle(0, DRAW_LINE);

  SetIndexEmptyValue(0, 0.0);

  SetIndexLabel(0, "ATR");

  SetIndexBuffer(1, MA_ATR);

  SetIndexStyle(1, DRAW_LINE);

  SetIndexEmptyValue(1, 0.0);

  SetIndexLabel(1, "MA");

  IndicatorSetInteger(INDICATOR_DIGITS, _Digits);

  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 i, j = 0, limit = prev_calculated == 0 ? rates_total-period_ATR : rates_total-prev_calculated;

  for(i = limit; i >= 0; i--)

   {

    ATR[i] = iATR(_Symbol, PERIOD_CURRENT, period_ATR, i);

    MA_ATR[i] = iMAOnArray(ATR, 0, period_MA_ATR, 0, MODE_SMA, i);

   }

  if(showAlert && prev_calculated > 0 && rates_total-prev_calculated > 0)

   {

    if(MA_ATR[2] < ATR[2] && MA_ATR[1] > ATR[1])

      Alert("5@5A5G5=85 2=87 ", _Symbol);

    if(MA_ATR[2] > ATR[2] && MA_ATR[1] < ATR[1])

      Alert("5@5A5G5=85 225@E ", _Symbol);

   }

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