Moving averages shown on chart as text values.

To add comments, please log in or register
betaTr5der
131
betaTr5der  

Did anyone create some MT5 indicator to show only text values of  moving averages on the chart?

Something like this... (look at the labels...)

nicholi shen
1895
nicholi shen  
//+------------------------------------------------------------------+
//|                                                MaTextOnChart.mq5 |
//|                                                      nicholishen |
//|                         https://www.forexfactory.com/nicholishen |
//+------------------------------------------------------------------+
#property copyright "nicholishen"
#property link      "https://www.forexfactory.com/nicholishen"
#property version   "1.00"
#property indicator_chart_window
//--- input parameters
input ENUM_MA_METHOD InpMaMethod = MODE_SMA;
input string InpMaPeriods = "20,50,100,200";

#include <Indicators\Indicators.mqh>

CIndicators ma_list;
//+------------------------------------------------------------------+
int OnInit()
{
   string periods[];
   int total = StringSplit(InpMaPeriods, ',', periods);
   for(int i=0; i<total; i++){
      CiMA *ma = new CiMA();
      bool create_ma = ma.Create(_Symbol, _Period, 
         (int)periods[i], 0, InpMaMethod, PRICE_CLOSE
      );
      if(!create_ma || !ma_list.Add(ma))
         return INIT_FAILED;
   }
   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const int begin,
                const double &price[])
{
   ma_list.Refresh();
   string res = "";
   CiMA *ma = ma_list.At(0);
   for(int i=0; CheckPointer(ma); ma=ma_list.At(++i)){
      res += StringFormat("MA%d %s\n",
         ma.MaPeriod(),
         DoubleToString(ma.Main(0), _Digits)
      );
   }
   Comment(res);
   return(rates_total);
}
betaTr5der
131
betaTr5der  
Thanks Nicholi, very kind.
To add comments, please log in or register