Author: Copyright � 2006, Rosh

This script functions as a technical analysis tool designed to smooth out market price fluctuations and identify underlying trends. It operates by creating two distinct visual elements on your trading chart: a continuous line and a series of directional signals.

Core Logic and Mechanism

The indicator works through a multi-stage calculation process that filters "noise" from the raw price data to reveal smoother movements.

1. Data Input and Smoothing Selection The script allows you to choose which type of price data it should follow (such as the Closing price, Opening price, High/Low extremes, or a variety of other weighted averages). It then applies a sophisticated smoothing method—chosen from various mathematical models—to determine how much "lag" versus "smoothness" is desired. This ensures that the resulting line doesn't react too wildly to tiny, insignificant price ticks.

2. Trend Detection and Dynamic Tracking The script maintains an internal memory of the current market trend (Upward or Downward).

  • It compares the current live price against a dynamically calculated "buffer."
  • If the price moves in opposition to the established trend beyond a certain threshold, the script registers a shift in direction.
  • This helps the indicator "anchor" itself to the strongest part of a move while ignoring minor retracements.

3. Oscillation and Momentum Analysis To determine the strength of the trend, the script calculates an "Oscillator" value. This represents the distance between the current price and its smoothed tracking point.

  • The script then applies a secondary smoothing filter to this oscillation.
  • By squaring or weighting this result (based on your settings), it emphasizes significant momentum shifts while suppressing low-intensity fluctuations.

4. Final Output Generation Finally, the script produces two visual outputs:

  • The Primary Line (NRMA): This is a refined trend line that uses the smoothed momentum data to predict and follow the price flow. It aims to provide a "clean" path of where the market is heading.
  • The Signal Markers (NRTR): These appear as specific marks on the chart. They represent the points where the script's internal logic identifies a significant change in trend direction, acting as visual cues for potential shifts in market sentiment.

Summary of User Experience

For the user, this script transforms jagged, chaotic price movements into a more legible flow. By balancing smoothing parameters, you can customize whether the indicator reacts quickly to new information or stays steady to highlight long-term trends. It essentially acts as a "filter" that tries to separate the permanent trend from temporary market vibrations.

7 Views
1 Downloads
0 Favorites
nrma_v1
//+---------------------------------------------------------------------+
//|                                                            NRMA.mq5 | 
//|                                              Copyright © 2006, Rosh | 
//|                                     http://konkop.narod.ru/nrma.htm | 
//+---------------------------------------------------------------------+ 
//| Äëÿ ðàáîòû  èíäèêàòîðà  ñëåäóåò  ïîëîæèòü ôàéë SmoothAlgorithms.mqh |
//| â ïàïêó (äèðåêòîðèþ): êàòàëîã_äàííûõ_òåðìèíàëà\\MQL5\Include        |
//+---------------------------------------------------------------------+
#property copyright "Copyright © 2006, Rosh"
#property link "http://konkop.narod.ru/nrma.htm"
//--- íîìåð âåðñèè èíäèêàòîðà
#property version   "1.01"
//--- îòðèñîâêà èíäèêàòîðà â ãëàâíîì îêíå
#property indicator_chart_window 
//--- êîëè÷åñòâî èíäèêàòîðíûõ áóôåðîâ 2
#property indicator_buffers 2 
//--- èñïîëüçîâàíî âñåãî äâà ãðàôè÷åñêèõ ïîñòðîåíèÿ
#property indicator_plots   2
//+-----------------------------------+
//| Ïàðàìåòðû îòðèñîâêè èíäèêàòîðà    |
//+-----------------------------------+
//--- îòðèñîâêà èíäèêàòîðà â âèäå ëèíèè
#property indicator_type1   DRAW_LINE
//--- â êà÷åñòâå öâåòà ëèíèè èíäèêàòîðà èñïîëüçîâàí DodgerBlue öâåò
#property indicator_color1 clrDodgerBlue
//--- ëèíèÿ èíäèêàòîðà - íåïðåðûâíàÿ êðèâàÿ
#property indicator_style1  STYLE_SOLID
//--- òîëùèíà ëèíèè èíäèêàòîðà ðàâíà 3
#property indicator_width1  3
//--- îòîáðàæåíèå ìåòêè èíäèêàòîðà
#property indicator_label1  "NRMA"
//+----------------------------------------------+
//| Ïàðàìåòðû îòðèñîâêè èíäèêàòîðà 2             |
//+----------------------------------------------+
//--- îòðèñîâêà èíäèêàòîðà â âèäå çíà÷êîâ
#property indicator_type2 DRAW_ARROW
//--- â êà÷åñòâå öâåòîâ ïÿòèöâåòíîé ãèñòîãðàììû èñïîëüçîâàíû
#property indicator_color2 clrMagenta
//--- ëèíèÿ èíäèêàòîðà - ñïëîøíàÿ
#property indicator_style2 STYLE_SOLID
//--- òîëùèíà ëèíèè èíäèêàòîðà ðàâíà 5
#property indicator_width2 2
//--- îòîáðàæåíèå ìåòêè èíäèêàòîðà
#property indicator_label2  "NRTR"
//+-----------------------------------+
//| Îïèñàíèå êëàññà CXMA              |
//+-----------------------------------+
#include <SmoothAlgorithms.mqh> 
//+-----------------------------------+
//--- îáúÿâëåíèå ïåðåìåííûõ êëàññà CXMA èç ôàéëà SmoothAlgorithms.mqh
CXMA XMA1;
//+-----------------------------------+
//| îáúÿâëåíèå ïåðå÷èñëåíèé           |
//+-----------------------------------+
enum Applied_price_ //Òèï êîíñòàíòû
  {
   PRICE_CLOSE_ = 1,     //close
   PRICE_OPEN_,          //Open
   PRICE_HIGH_,          //High
   PRICE_LOW_,           //Low
   PRICE_MEDIAN_,        //Median Price (HL/2)
   PRICE_TYPICAL_,       //Typical Price (HLC/3)
   PRICE_WEIGHTED_,      //Weighted Close (HLCC/4)
   PRICE_SIMPL_,         //Simple Price (OC/2)
   PRICE_QUARTER_,       //Quarted Price (HLOC/4) 
   PRICE_TRENDFOLLOW0_,  //TrendFollow_1 Price 
   PRICE_TRENDFOLLOW1_,  //TrendFollow_2 Price
   PRICE_DEMARK_         //Demark Price
  };
//+-----------------------------------+
//| îáúÿâëåíèå ïåðå÷èñëåíèé           |
//+-----------------------------------+
/*enum Smooth_Method - ïåðå÷èñëåíèå îáúÿâëåíî â ôàéëå SmoothAlgorithms.mqh
  {
   MODE_SMA_,  //SMA
   MODE_EMA_,  //EMA
   MODE_SMMA_, //SMMA
   MODE_LWMA_, //LWMA
   MODE_JJMA,  //JJMA
   MODE_JurX,  //JurX
   MODE_ParMA, //ParMA
   MODE_T3,    //T3
   MODE_VIDYA, //VIDYA
   MODE_AMA,   //AMA
  }; */
//+-----------------------------------+
//| Âõîäíûå ïàðàìåòðû èíäèêàòîðà      |
//+-----------------------------------+
input Smooth_Method XMA_Method=MODE_SMA; // Ìåòîä óñðåäíåíèÿ
input int XLength=3;                     // Ãëóáèíà ñãëàæèâàíèÿ                    
input int XPhase=15;                     // Ïàðàìåòð ñãëàæèâàíèÿ
//--- XPhase: äëÿ JJMA èçìåíÿåòñÿ â ïðåäåëàõ -100..+100, âëèÿåò íà êà÷åñòâî ïåðåõîäíîãî ïðîöåññà;
//--- XPhase: äëÿ VIDIA ýòî ïåðèîä CMO, äëÿ AMA ýòî ïåðèîä ìåäëåííîé ñêîëüçÿùåé
input Applied_price_ IPC=PRICE_CLOSE;    // Öåíîâàÿ êîíñòàíòà
input double Kf=1;
input double Fast=2;
input double Sharp=2;
input int    Shift=0; // ñäâèã èíäèêàòîðà ïî ãîðèçîíòàëè â áàðàõ
input int    PriceShift=0; // cäâèã èíäèêàòîðà ïî âåðòèêàëè â ïóíêòàõ
//+-----------------------------------+
//--- îáúÿâëåíèå äèíàìè÷åñêîãî ìàññèâà, êîòîðûé â äàëüíåéøåì
//--- áóäåò èñïîëüçîâàí â êà÷åñòâå èíäèêàòîðíîãî áóôåðà
double IndBuffer1[],IndBuffer2[];
//--- îáúÿâëåíèå ïåðåìåííîé çíà÷åíèÿ âåðòèêàëüíîãî ñäâèãà ìóâèíãà
double dPriceShift,dF;
//--- îáúÿâëåíèå öåëî÷èñëåííûõ ïåðåìåííûõ íà÷àëà îòñ÷¸òà äàííûõ
int min_rates_total;
//+------------------------------------------------------------------+   
//| Custom indicator initialization function                         | 
//+------------------------------------------------------------------+ 
void OnInit()
  {
//--- èíèöèàëèçàöèÿ ïåðåìåííûõ íà÷àëà îòñ÷¸òà äàííûõ
   min_rates_total=XMA1.GetStartBars(XMA_Method,XLength,XPhase)+1;
//--- óñòàíîâêà àëåðòîâ íà íåäîïóñòèìûå çíà÷åíèÿ âíåøíèõ ïåðåìåííûõ
   XMA1.XMALengthCheck("XLength",XLength);
   XMA1.XMAPhaseCheck("XPhase",XPhase,XMA_Method);
//--- èíèöèàëèçàöèÿ ñäâèãà ïî âåðòèêàëè
   dPriceShift=_Point*PriceShift;
   dF=2.0/(1.0+Fast);
//--- ïðåâðàùåíèå äèíàìè÷åñêîãî ìàññèâà â èíäèêàòîðíûé áóôåð
   SetIndexBuffer(0,IndBuffer1,INDICATOR_DATA);
//--- îñóùåñòâëåíèå ñäâèãà èíäèêàòîðà 1 ïî ãîðèçîíòàëè
   PlotIndexSetInteger(0,PLOT_SHIFT,Shift);
//--- îñóùåñòâëåíèå ñäâèãà íà÷àëà îòñ÷¸òà îòðèñîâêè èíäèêàòîðà
   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,min_rates_total);
//--- óñòàíîâêà çíà÷åíèé èíäèêàòîðà, êîòîðûå íå áóäóò âèäèìû íà ãðàôèêå
   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0);
//--- ïðåâðàùåíèå äèíàìè÷åñêîãî ìàññèâà â èíäèêàòîðíûé áóôåð
   SetIndexBuffer(1,IndBuffer2,INDICATOR_DATA);
//--- îñóùåñòâëåíèå ñäâèãà èíäèêàòîðà 2 ïî ãîðèçîíòàëè
   PlotIndexSetInteger(1,PLOT_SHIFT,Shift);
//--- îñóùåñòâëåíèå ñäâèãà íà÷àëà îòñ÷¸òà îòðèñîâêè èíäèêàòîðà
   PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,min_rates_total);
//--- óñòàíîâêà çíà÷åíèé èíäèêàòîðà, êîòîðûå íå áóäóò âèäèìû íà ãðàôèêå
   PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0);
//--- èíèöèàëèçàöèè ïåðåìåííîé äëÿ êîðîòêîãî èìåíè èíäèêàòîðà
   string shortname;
   string Smooth1=XMA1.GetString_MA_Method(XMA_Method);
   StringConcatenate(shortname,"NRMA(",XLength,", ",Smooth1,")");
//--- ñîçäàíèå èìåíè äëÿ îòîáðàæåíèÿ â îòäåëüíîì ïîäîêíå è âî âñïëûâàþùåé ïîäñêàçêå
   IndicatorSetString(INDICATOR_SHORTNAME,shortname);
//--- îïðåäåëåíèå òî÷íîñòè îòîáðàæåíèÿ çíà÷åíèé èíäèêàòîðà
   IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
//--- çàâåðøåíèå èíèöèàëèçàöèè
  }
//+------------------------------------------------------------------+ 
//| 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<min_rates_total) return(0);
//--- îáúÿâëåíèå ïåðåìåííûõ ñ ïëàâàþùåé òî÷êîé  
   double price,LPrice,HPrice,Oscil,NRatio,xOscil;
//--- îáúÿâëåíèå öåëî÷èñëåííûõ ïåðåìåííûõ è ïîëó÷åíèå óæå ïîñ÷èòàííûõ áàðîâ
   int first,bar,Trend0;
   static int Trend1;
//--- ðàñ÷¸ò ñòàðòîâîãî íîìåðà first äëÿ öèêëà ïåðåñ÷¸òà áàðîâ
   if(prev_calculated>rates_total || prev_calculated<=0) // ïðîâåðêà íà ïåðâûé ñòàðò ðàñ÷¸òà èíäèêàòîðà
     {
      first=1; // ñòàðòîâûé íîìåð äëÿ ðàñ÷¸òà âñåõ áàðîâ
      bar=first-1;
      price=PriceSeries(IPC,bar,open,low,high,close);
      IndBuffer1[bar]=price;
      if(close[first]>open[first])
        {
         Trend1=+1;
         IndBuffer2[bar]=NormalizeDouble(price*(1.0-Kf*0.01),_Digits);
        }
      else
        {
         Trend1=-1;
         IndBuffer2[bar]=NormalizeDouble(price*(1.0+Kf*0.01),_Digits);
        }
     }
   else first=prev_calculated-1; // ñòàðòîâûé íîìåð äëÿ ðàñ÷¸òà íîâûõ áàðîâ
//--- îñíîâíîé öèêë ðàñ÷¸òà èíäèêàòîðà
   for(bar=first; bar<rates_total && !IsStopped(); bar++)
     {
      //--- âûçîâ ôóíêöèè PriceSeries äëÿ ïîëó÷åíèÿ âõîäíîé öåíû price
      price=PriceSeries(IPC,bar,open,low,high,close);
      IndBuffer2[bar]=IndBuffer2[bar-1];
      Trend0=Trend1;

      if(Trend1>=0)
        {
         if(price<IndBuffer2[bar-1])
           {
            Trend0=-1;
            IndBuffer2[bar]=NormalizeDouble(price*(1.0+Kf*0.01),_Digits);
           }
         else
           {
            Trend0=+1;
            LPrice=NormalizeDouble(price*(1.0-Kf*0.01),_Digits);
            if(LPrice>IndBuffer2[bar-1]) IndBuffer2[bar]=LPrice;
            else IndBuffer2[bar]=IndBuffer2[bar-1];
           }
        }

      if(Trend1<=0)
        {
         if(price>IndBuffer2[bar-1])
           {
            Trend0=+1;
            IndBuffer2[bar]=NormalizeDouble(price*(1.0-Kf*0.01),_Digits);
           }
         else
           {
            Trend0=-1;
            HPrice=NormalizeDouble(price*(1.0+Kf*0.01),_Digits);
            if(HPrice<IndBuffer2[bar-1]) IndBuffer2[bar]=HPrice;
            else IndBuffer2[bar]=IndBuffer2[bar-1];
           }
        }

      Oscil=(100.0*MathAbs(price-IndBuffer2[bar])/price)/Kf;
      xOscil=XMA1.XMASeries(1,prev_calculated,rates_total,XMA_Method,XPhase,XLength,Oscil,bar,false);
      if(bar<min_rates_total-1)
        {
         IndBuffer1[bar]=price;
         continue;
        }
      NRatio=MathPow(xOscil,Sharp);
      IndBuffer1[bar]=IndBuffer1[bar-1]+NRatio*dF*(price-IndBuffer1[bar-1])+dPriceShift;
      if(bar<rates_total-1)
        {
         Trend1=Trend0;
        }
     }
//---
   return(rates_total);
  }
//+------------------------------------------------------------------+

Comments