//+------------------------------------------------------------------+ //| 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;i1 && 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); }