Moving Speed

Author: Copyright 2021, Roman Kiverin
Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
0 Views
0 Downloads
0 Favorites
Moving Speed
ÿþ#property version     "1.0"

#property copyright   "Copyright 2021, Roman Kiverin"

#property link        "https://www.mql5.com/ru/users/romankiverin/publications"

#property description "Moving Averages Speed"

#property strict



#include <MovingAverages.mqh>



//--- indicator settings

#property  indicator_separate_window

#property  indicator_buffers 1

#property  indicator_color1  Blue

#property  indicator_width1  2



//--- indicator parameters

input int MaPeriod = 10;                     // Moving Average Period

input int MaxBarDraw = 1000;                 // Maximum Bar Calculate



input ENUM_MA_METHOD Method = MODE_SMA;      // Moving Average Method

input ENUM_APPLIED_PRICE App = PRICE_CLOSE;  // Applied to



#define iMa(index) iMA(NULL,PERIOD_CURRENT,MaPeriod,index,Method,App,0)



double    Map[];

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

//| Custom indicator initialization function                         |

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

int OnInit(void)

  {

   IndicatorDigits(Digits+1);

//--- drawing settings

   SetIndexStyle(0, DRAW_LINE);

//--- indicator buffers mapping

   SetIndexBuffer(0, Map);

   IndicatorShortName("MA Speed");

   return(INIT_SUCCEEDED);

  }

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

//| Ma Speed Main Draw                                               |

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

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[])

  {

   if(prev_calculated > 0)

      Map[0] = iMa(0) - iMa(1);

   else

     {

      int limit = rates_total - prev_calculated - 2;

      double prev = iMa(1 + (limit = limit > MaxBarDraw? MaxBarDraw: limit));

      for(int i = limit; i >= 1; i--, Map[i] = - prev, Map[i] += prev = iMa(i));

     }

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