📅 财经日历 📊 实时波动 📈 大盘云图 📶 行情走势 🆚 投机情绪 🚀 今日热点

    Moving Average-RMA 相对移动平均线 - MetaTrader 5脚本

    韩延 LV1
    2025-03-10 · 842 阅读
    Relative Moving Average.mq5Relative Moving Average.mq5
    //+------------------------------------------------------------------+
    //|                                          Mage Moving Average-RMA |
    //|                                  Copyright 2023, MetaQuotes Ltd. |
    //|                                             https://www.mql5.com |
    //+------------------------------------------------------------------+
    #property copyright "Copyright 2023, Mage"
    #property link      "https://www.mql5.com"
    #property version   "1.00"
    #property indicator_chart_window
    #property indicator_buffers 1
    #property indicator_plots   1
    //--- plot Slow Speed Line
    #property indicator_label1  "RMA"
    #property indicator_type1   DRAW_LINE
    #property indicator_color1  clrRed
    #property indicator_style1  STYLE_SOLID
    #property indicator_width1  1
    //--- input parameters
    input int InpPeriod   =12;   //RMA Period

    //--- indicator buffers
    double    buffer_m[];

    //+------------------------------------------------------------------+
    //| Custom indicator initialization function                         |
    //+------------------------------------------------------------------+
    int OnInit()
      {
    //--- indicator buffers mapping
       SetIndexBuffer(0,buffer_m,INDICATOR_DATA);
    //--- set Digits
       IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1);
    //---name
       IndicatorSetString(INDICATOR_SHORTNAME,"Mage_RMA"+string(InpPeriod));
    //--- set first bar from what index will be drawn
       PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InpPeriod);
    //---
       return(INIT_SUCCEEDED);
      }

    //+------------------------------------------------------------------+
    //| Custom indicator iteration function                              |
    //+------------------------------------------------------------------+
    int OnCalculate(const int rates_total,
                    const int prev_calculated,
                    const int begin,
                    const double& price[])
      {
       ExponentialMAOnBuffer(rates_total,prev_calculated,0,InpPeriod,price,buffer_m);
       return(rates_total);
      }
    //+------------------------------------------------------------------+
    //| Calculation Buffer                                               |
    //+------------------------------------------------------------------+
    int ExponentialMAOnBuffer(const int rates_total,const int prev_calculated,const int begin,const int period,const double& price[],double& buffer[])
      {
    //--- check period
       if(period<=1 || period>(rates_total-begin))
          return(0);
    //--- save and clear 'as_series' flags
       bool as_series_price=ArrayGetAsSeries(price);
       bool as_series_buffer=ArrayGetAsSeries(buffer);

       ArraySetAsSeries(price,false);
       ArraySetAsSeries(buffer,false);
    //--- calculate start position
       int    start_position;
       double smooth_factor=1.0/period;

       if(prev_calculated==0)  // first calculation or number of bars was changed
         {
          //--- set empty value for first bars
          for(int i=0; i<begin; i++)
             buffer=0.0;
          //--- calculate first visible value
          start_position=period+begin;
          buffer[begin] =price[begin];

          for(int i=begin+1; i<start_position; i++)
             buffer=price*smooth_factor+buffer[i-1]*(1.0-smooth_factor);
         }
       else
          start_position=prev_calculated-1;
    //--- main loop
       for(int i=start_position; i<rates_total; i++)
          buffer=price*smooth_factor+buffer[i-1]*(1.0-smooth_factor);
    //--- restore as_series flags
       ArraySetAsSeries(price,as_series_price);
       ArraySetAsSeries(buffer,as_series_buffer);
    //---
       return(rates_total);
      }
    //+------------------------------------------------------------------+


    ""
    还没有人打赏,支持一下
    回复

    举报

     

    回答|共 4 个

    玩主王 LV3

    发表于 2026-4-18 15:12:14 | 显示全部楼层

    支持下

    freeman002 LV0

    发表于 2026-4-20 13:38:34 | 显示全部楼层


    支持下

    赵云_8548 LV0

    发表于 2026-5-4 13:07:55 | 显示全部楼层



    支持下
    您需要登录后才可以回帖 登录 | 注册

    提醒: 禁止引战、谩骂、灌水内容

    微信二维码

    有问题联系客服