//+------------------------------------------------------------------+ //| Harmonic Moving Average.mq5 | //| Copyright 2024, Rosh Jardine | //| https://www.mql5.com/en/users/roshjardine | //+------------------------------------------------------------------+ #property copyright "Copyright 2024, Rosh Jardine" #property link "https://www.mql5.com/en/users/roshjardine" #property version "1.00" #property indicator_chart_window #property indicator_buffers 1 #property indicator_plots 1 //--- plot HMALine #property indicator_label1 "HMALine" #property indicator_type1 DRAW_LINE #property indicator_color1 clrRed #property indicator_style1 STYLE_SOLID #property indicator_width1 1 input int InputHMAPeriod = 7; input int InputHMAShift = 0; input ENUM_APPLIED_PRICE InputAppliedPriceEnum = PRICE_CLOSE; //--- indicator buffers double HMALineBuffer[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping SetIndexBuffer(0,HMALineBuffer,INDICATOR_DATA); IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1); /*** setting values of the indicator that won't be visible on a chart ***/ PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,EMPTY_VALUE); PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InputHMAShift); //--- line shifts when drawing PlotIndexSetInteger(0,PLOT_SHIFT,InputHMAShift); string short_name = "HMA-"+EnumToString(InputAppliedPriceEnum)+"("+IntegerToString(InputHMAPeriod)+")"; IndicatorSetString(INDICATOR_SHORTNAME,short_name); return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ 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[]) { if (rates_total<=0) { return(0); } if (prev_calculated<=0) { double rsd = 0.0; for (int i=0; i