Author: CRamdass - Conversion only
NRTR_NK

This script functions as a trend-tracking indicator designed to identify and visualize price momentum on a trading chart. Its primary purpose is to detect the prevailing direction of the market and project potential price levels based on recent volatility.

Core Logic and Mechanism

The indicator operates by analyzing a specific window of historical data, determined by the "AveragePeriod" setting. It calculates the relationship between price movement and market volatility to establish two distinct trends: upward and downward.

1. Volatility Assessment The script constantly monitors the range of price action (the difference between the highest and lowest points) over a set number of bars. It converts this range into a specific coefficient. This helps the indicator understand how "active" or "volatile" the market is at any given moment, ensuring that the trend signals are adjusted for current market conditions rather than just looking at raw price.

2. Trend Detection and State Management The logic is designed to be "stateful," meaning it remembers where the price was in the previous step to determine where it is going now.

  • Upward Trend: If the price is moving higher and maintaining momentum relative to its recent high, the script identifies an upward bias.
  • Downward Trend: If the price is moving lower and maintaining momentum relative to its recent low, the script identifies a downward bias.

3. Dynamic Price Projection Unlike standard indicators that simply follow the price, this logic calculates a "Result" value. This result represents a projected point based on the current trend:

  • In an Upward Trend, it calculates a level slightly below the current price (adjusting for volatility). It seeks to maintain the highest possible "peak" value as long as the price keeps climbing.
  • In a Downward Trend, it calculates a level slightly above the current price. It seeks to maintain the lowest possible "trough" value as long as the price continues to fall.

4. Trend Reversal Logic The script identifies a trend shift when the price breaks past these calculated result levels:

  • If the market is in an upward trend but the price drops significantly below the calculated support level, the logic flips the state to a downward trend.
  • Conversely, if the market is in a downward trend but the price surges above the calculated resistance level, the logic flips the state back to an upward trend.

Visual Representation

The final output is displayed on the chart as two separate sets of symbols (arrows):

  • Blue Arrows: These represent the active "Upward" trend markers.
  • Red Arrows: These represent the active "Downward" trend markers.

By filtering out noise and focusing on these calculated momentum levels, the indicator aims to provide a clear visual distinction between sustained price movements and minor fluctuations.

Miscellaneous
Implements a curve of type %1
8 Views
0 Downloads
0 Favorites
NRTR_NK
//+------------------------------------------------------------------+
//|                                          Version  July 20, 2006  |
//|   Editing   Nikolay Kositsin  15.06.2006  farria@mail.redcom.ru  |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//|                                                         NRTR.mq4 |
//|                                        Ramdass - Conversion only |
//+------------------------------------------------------------------+
#property copyright "CRamdass - Conversion only" 
#property link "" 
//---- îòðèñîâêà èíäèêàòîðà â ãëàâíîì îêíå
#property indicator_chart_window 
//---- êîëè÷åñòâî èíäèêàòîðíûõ áóôôåðîâ
#property indicator_buffers 2 
//---- öâåòà èíäèêàòîðà
#property indicator_color1 Blue
#property indicator_color2 Red
//---- òîëùèíà èíäèêàòîðíûõ ëèíèé
#property indicator_width1 1
#property indicator_width2 1
//---- ÂÕÎÄÍÛÅ ÏÀÐÀÌÅÒÐÛ ÈÍÄÈÊÀÒÎÐÀ
extern int AveragePeriod = 10;
//---- èíäèêàòîðíûå áóôôåðû
double Ind_Buffer1[];
double Ind_Buffer2[];
//+------------------------------------------------------------------+
//| NRTR initialization function                                     |
//+------------------------------------------------------------------+
int init()
  {
//---- 2 èíäèêàòîðíûõ áóôôåðà èñïîëüçîâàíû äëÿ ñ÷¸òà
   SetIndexBuffer(0, Ind_Buffer1);
   SetIndexBuffer(1, Ind_Buffer2);
//---- Ñòèëü èñïîëíåíèÿ ãðàôèêà  
   SetIndexStyle(0, DRAW_ARROW);
   SetIndexStyle(1, DRAW_ARROW);
   SetIndexArrow(0, 159);
   SetIndexArrow(1, 159);
//---- óñòàíîâêà çíà÷åíèé èíäèêàòîðà, êîòîðûå íå áóäóò âèäèìû íà ãðàôèêå
   SetIndexEmptyValue(0, 0.0);
   SetIndexEmptyValue(1, 0.0);
//---- èìÿ äëÿ îêîí äàííûõ è ëýéáà äëÿ ñóáúîêîí
   SetIndexLabel(0, "NRTRUp(" + AveragePeriod + ")");    
   SetIndexLabel(1, "NRTRDown(" + AveragePeriod + ")"); 
//---- óñòàíîâêà íîìåðà áàðà, íà÷èíàÿ ñ êîòîðîãî áóäåò îòðèñîâûâàòüñÿ èíäèêàòîð 
   SetIndexDrawBegin(0,AveragePeriod); 
   SetIndexDrawBegin(1,AveragePeriod); 
//---- Óñòàíîâêà ôîðìàòà òî÷íîñòè (êîëè÷åñòâî çíàêîâ ïîñëå äåñÿòè÷íîé òî÷êè) 
//     äëÿ âèçóàëèçàöèè çíà÷åíèé èíäèêàòîðà  
   IndicatorDigits(Digits);  
//---- çàâåðøåíèå èíèöèàëèçàöèè
   return(0);
  }
//+------------------------------------------------------------------+
//| NRTR                                                             |
//+------------------------------------------------------------------+
int start()
  {
   //---- ïðîâåðêà êîëè÷åñòâà áàðîâ íà äîñòàòî÷íîñòü äëÿ ðàñ÷¸òà
   if(Bars <= AveragePeriod)
       return(0);
   //---- ââåäåíèå ïåðåìåííûõ ïàìÿòè  
   static double PRICE,RESALT; 
   static bool TREND; 
   static int time2;
   //----+ Ââåäåíèå ïåðåìåííûõ ñ ïëàâàþùåé òî÷êîé
   double Resalt, close, open, dK, AvgRange, price, NewVel;
   //---- ââåäåíèå ëîãè÷åñêèõ ïåðåìåííûõ 
   bool   trend;
   //----+ Ââåäåíèå öåëûõ ïåðåìåííûõ è ïîëó÷åíèå óæå ïîäñ÷èòàííûõ áàðîâ
   int bar, MaxBar, limit, counted_bars = IndicatorCounted();
   //---- ïðîâåðêà íà âîçìîæíûå îøèáêè
   if(counted_bars < 0) 
       return(-1);
   //---- ïîñëåäíèé ïîäñ÷èòàííûé áàð äîëæåí áûòü ïåðåñ÷èòàí 
   if(counted_bars > 0) 
       counted_bars--;
   //---- îïðåäåëåíèå íîìåðà ñàìîãî ñòàðîãî áàðà, íà÷èíàÿ ñ êîòîðîãî áóäåò 
   //     ïðîèçâåä¸í ïîëíûé ïåðåñ÷¸ò âñåõ áàðîâ 
   MaxBar = Bars - 1 - AveragePeriod;
   //---- îïðåäåëåíèå íîìåðà ñàìîãî ñòàðîãî áàðà, íà÷èíàÿ ñ êîòîðîãî áóäåò 
   //     ïðîèçåä¸í ïåðåñ÷¸ò òîëüêî íîâûõ áàðîâ 
   limit = Bars - 1 - counted_bars;
   //+--- âîññòàíîâëåíèå çíà÷åíèé ïåðåìåííûõ
   int Tnew = Time[limit + 1];
   if(limit < MaxBar)
   if(Tnew == time2)
     {
       price = PRICE;   
       trend = TREND; 
       Resalt = RESALT;
     } 
   else 
     {
       if(Tnew > time2)
           Print("ERROR01");  
       else 
           Print("ERROR02");
       return(-1);  
     }
   //---- èíèöèàëèçàöèÿ íóëÿ
   if(limit >= MaxBar)
     {
       for(int iii = 0; iii < AveragePeriod; iii++) 
         {
           Ind_Buffer1[MaxBar-iii] = 0.0;
           Ind_Buffer2[MaxBar-iii] = 0.0;
           limit = MaxBar - AveragePeriod;
         }
       //----
       AvgRange = 0;
       for(int jjj = AveragePeriod - 1; jjj >= 0; jjj--)
           AvgRange += MathAbs(High[MaxBar+jjj] - Low[MaxBar+jjj]);
       dK = AvgRange / (AveragePeriod*10000*Point );
       close = Close[MaxBar];
       open = Open [MaxBar];
       price = close;
       //----
       if(close > open)
         {
           Resalt = close * (1 - dK);
           trend = true; 
         }
       //----
       if(close < open)  
         {
           Resalt = close * (1 + dK);
           trend = false; 
         }
       if(trend) 
           Ind_Buffer1[MaxBar] = Resalt; 
       if(!trend) 
           Ind_Buffer2[MaxBar] = Resalt; 
     }
   //----+ îñíîâíîé öèêë ðàñ÷¸òà èíäèàòîðà
   bar = limit;
   while(bar >= 0)
     {   
       //+--- Ñîõðàíåíèå çíà÷åíèé ïåðåìåííûõ
       if(bar == 1)
         if(((limit == 1) && (time2 == Time[2])) || (limit > 1))
           {
             time2 = Time[2];
             PRICE = price;
             TREND = trend;
             RESALT = Resalt;
           }
       //+---+==========================================+   
       AvgRange = 0; 
       for(int kkk = AveragePeriod-1; kkk >= 0; kkk--)
           AvgRange += MathAbs(High[bar+kkk] - Low[bar+kkk]);
       dK = AvgRange / (AveragePeriod*10000*Point );  
       close = Close[bar];
       Ind_Buffer1[bar] = 0; 
       Ind_Buffer2[bar] = 0;
       //----
       if(trend)
         {
           if(close > price)
             {
               price  = close;
               NewVel = close * (1 - dK);
               if(NewVel > Resalt) 
                   Resalt=NewVel;
             }
           else
               if(close < Resalt)
                 {
                   price  = close;
                   Resalt = close * (1 + dK);
                   trend  = false;
                 }
         } 
       //---- 
       if(!trend)
         {
           if(close < price)
             {  
               price  = close;
               NewVel = close * (1 + dK);
               if(NewVel < Resalt) 
                   Resalt=NewVel;
             } 
           else  
               if(close > Resalt) 
                 {
                   price  = close;
                   Resalt = close * (1 - dK);
                   trend  = true;
                 }
         }
       //----
       if(trend) 
           Ind_Buffer1[bar] = Resalt; 
       if(!trend) 
           Ind_Buffer2[bar] = Resalt; 
       bar--;
     }
    //----+ çàâåðøåíèå îñíîâíîãî öèêëà
    return(0);
  }
//+---------------------------------------------------------------------------------------------------------------------------+

Comments