//+------------------------------------------------------------------+ //| FrAMA.mq5 | //| Copyright 2000-2025, MetaQuotes Ltd. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2000-2025, MetaQuotes Ltd." #property link "https://www.mql5.com" #property description "Fractal Adaptive Moving Average" //--- indicator settings #property indicator_chart_window #property indicator_buffers 1 #property indicator_plots 1 #property indicator_type1 DRAW_LINE #property indicator_color1 clrDarkBlue #property indicator_width1 1 #property indicator_label1 "FrAMA" #property indicator_applied_price PRICE_CLOSE //--- input parameters input int InpPeriodFrAMA=14; // FrAMA period input int InpShift=0; // Indicator's shift //--- indicator buffer double FrAmaBuffer[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ void OnInit() { //--- indicator buffers mapping SetIndexBuffer(0,FrAmaBuffer,INDICATOR_DATA); //--- sets first bar from what index will be drawn PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,2*InpPeriodFrAMA-1); //--- sets indicator shift PlotIndexSetInteger(0,PLOT_SHIFT,InpShift); //--- name for labels string short_name=StringFormat("FrAMA(%d)",InpPeriodFrAMA); IndicatorSetString(INDICATOR_SHORTNAME,short_name); PlotIndexSetString(0,PLOT_LABEL,short_name); } //+------------------------------------------------------------------+ //| Fractal Adaptive Moving Average | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const int begin, const double &price[]) { if(rates_total<2*InpPeriodFrAMA) return(0); int start; //--- start calculations if(prev_calculated==0) { start=2*InpPeriodFrAMA-1; for(int i=0; i<=start; i++) FrAmaBuffer[i]=price[i]; } else start=prev_calculated-1; //--- main cycle double math_log_2=MathLog(2.0); for(int i=start; i