Author: Copyright 2019, Nikolay Semko
Indicators Used
Moving average indicator
0 Views
0 Downloads
0 Favorites
MaFromMa
ÿþ//+------------------------------------------------------------------+

//|                                                     MaFromMa.mq5 |

//|                                    Copyright 2019, Nikolay Semko |

//|                         https://www.mql5.com/ru/users/nikolay7ko |

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

#property copyright "Copyright 2019, Nikolay Semko"

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

#property link      "SemkoNV@bk.ru"  

#property version   "1.00"

#property indicator_chart_window

#property indicator_buffers 1

#property indicator_plots   1

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

#property indicator_label1  "MaFromMa"

#property indicator_type1   DRAW_LINE

#property indicator_color1  clrDarkOrchid

#property indicator_style1  STYLE_SOLID

#property indicator_width1  3

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

input int per=5;   // initial MA period

input int per2=10; // MA period, which is taken from the initial MA

input int N=5;     // how many times to apply?

input ENUM_APPLIED_PRICE Price=PRICE_CLOSE;

input ENUM_MA_METHOD MaMethod=MODE_SMA;

input int InpShift=0;  // Indicator's shift

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

double         MaBuffer[]; 

int n;

int handle;

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

int OnInit()

  {

   SetIndexBuffer(0,MaBuffer,INDICATOR_DATA);

   PlotIndexSetInteger(0,PLOT_SHIFT,InpShift);

   n=per+(per2-1)*N-1;

   IndicatorSetString(INDICATOR_SHORTNAME,"MaFromMa("+string(per)+","+string(per2)+","+string(N)+" times,real period-"+string(n)+")");

   handle=iMA(_Symbol,_Period,per,0,MaMethod,Price);

   for(int i=0;i<N;i++)

     {

      handle=iMA(_Symbol,_Period,per2,0,MaMethod,handle);

     }

   return(INIT_SUCCEEDED);

  }



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



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 to_copy=rates_total-prev_calculated;

   if(to_copy>1 && rates_total>n) // if we make the first entry or there was a delay more than the time of one bar, we initialize all the bars

     {

      ArrayInitialize(MaBuffer,EMPTY_VALUE); 

      CopyBuffer(handle,0,0,rates_total-1-per,MaBuffer);

      return(rates_total);

     }

   else CopyBuffer(handle,0,0,1,MaBuffer);   // if new bar or new tick

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