NRTR WATR-hist

Download script
NRTR WATR-hist

The NRTR WATR script is a technical analysis tool designed to help traders visualize market trends and identify potential price reversals based on volatility and momentum. Unlike standard indicators that only follow the price, this script calculates a dynamic "range" value to determine how far the price can realistically move before a trend might be considered exhausted.

Core Logic and Functionality

1. Volatility Calculation (WATR) The core of the script revolves around a value called "WATR." To calculate this, the script looks back at a specific number of past candles (determined by the AveragePeriod setting). It analyzes the difference between the highest and lowest prices reached during that time. Instead of treating every candle equally, it applies a weighting system where more recent price action has a greater influence on the calculation than older data. This ensures the indicator reacts quickly to current market conditions.

2. Trend Tracking and Reversal Detection The script continuously monitors whether the market is in an "Upward" or "Downward" trend.

  • In an Upward Trend: It looks for new high prices. If the price starts to drop significantly below a calculated threshold (based on that dynamic volatility range), the script detects a potential shift and flips the trend status.
  • In a Downward Trend: It tracks new low prices. If the price climbs above the calculated threshold, it signals a potential reversal to an upward move.

3. Visual Representation The indicator displays these trends directly on your chart using colored histograms (specifically Tomato and DeepSkyBlue). These visual markers represent the high and low boundaries of the current price action relative to the identified trend direction. When the trend flips, the visualization updates to reflect the new dominant direction.

Customizable Settings

The logic is made flexible through three primary user inputs:

  • AveragePeriod: Determines how many candles back the script looks to calculate its volatility measurements.
  • Variant: This allows you to toggle between different calculation methods (e.g., looking at a fixed amount of bars versus a rolling window) and specific adjustments for different currency pairs like USDJPY or EURJPY.
  • CountBars: Controls the historical depth of the data displayed on the chart, ensuring the visual output is clean and relevant to the current timeframe.

Summary for the Trader

Essentially, this script acts as a "smart" trend follower. It measures how much the market typically "swings" over a period of time and uses that measurement to set boundaries. When the price breaks through those boundaries in the opposite direction of the current trend, the indicator signals that the market's momentum may be shifting, providing a visual guide for potential entry or exit points.

Miscellaneous
Implements a curve of type %1
13 Views
0 Downloads
0 Favorites
NRTR WATR-hist
//+------------------------------------------------------------------+
//|                                                    NRTR WATR.mq4 |
//|                                                                  |
//|                                        Ramdass - Conversion only |
//+------------------------------------------------------------------+

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Tomato
#property indicator_color2 DeepSkyBlue
//---- input parameters
extern int AveragePeriod=10;
extern int Variant=2;
extern int CountBars=300;

//---- buffers
double value1[];
double value2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {

//---- indicator line
   IndicatorBuffers(4);
   SetIndexStyle(0,DRAW_HISTOGRAM,0,2);//SetIndexStyle(0,DRAW_ARROW);
   //SetIndexArrow(0,167);
   SetIndexStyle(1,DRAW_HISTOGRAM,0,2);//SetIndexStyle(1,DRAW_ARROW);
   //SetIndexArrow(1,167);
   SetIndexStyle(2,DRAW_HISTOGRAM,0,2);
   SetIndexStyle(3,DRAW_HISTOGRAM,0,2);
   SetIndexBuffer(0,value1);
   SetIndexBuffer(1,value2);
//----
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| NRTR WATR                                                        |
//+------------------------------------------------------------------+
int start()
  {
   if (CountBars>=Bars) CountBars=Bars - AveragePeriod - 2;
//   CountBars = CountBars - AveragePeriod - 3;
   SetIndexDrawBegin(0,Bars-CountBars+1);
   SetIndexDrawBegin(1,Bars-CountBars+1);
   int i,i2,bar,counted_bars=IndicatorCounted();
   double value,WATR;
   double trend=1,dK,AvgRange,price,AveragePeriod_D;
   AveragePeriod_D=AveragePeriod;
//----
   if(Bars<=AveragePeriod) return(0);
//---- initial zero
   if(counted_bars<1)
   {
      for(i=1;i<=AveragePeriod;i++) value1[Bars-i]=0.0;
      for(i=1;i<=AveragePeriod;i++) value2[Bars-i]=0.0;
   }
AvgRange=0;

if ((Variant == 2) || (Variant == 3))
   {
   for (i=AveragePeriod; i>=1; i--)
       {
       dK = 1+(AveragePeriod_D-i)/AveragePeriod_D;
       AvgRange=AvgRange + dK*MathAbs(High[i]-Low[i]);
       }
   if (Symbol()=="USDJPY" || Symbol()=="GBPJPY" || Symbol()=="EURJPY")
   {WATR = AvgRange/AveragePeriod_D/100;}
   else    
   {WATR = AvgRange/AveragePeriod_D;}
   }
   
   
if (Variant == 1)  
   {
   for (i=1; i<=AveragePeriod; i++)
       {
       dK = 1+(AveragePeriod_D-i)/AveragePeriod_D;
       AvgRange=AvgRange + dK*MathAbs(High[CountBars + i]-Low[CountBars + i]);
       }
   WATR = AvgRange/AveragePeriod_D;
   }

if (Close[CountBars-1] > Open[CountBars-1])
   {
   value1[CountBars - 1] = Close[CountBars - 1] * (1 - WATR);
   trend = 1; value2[CountBars - 1] = 0.0;
   }

if (Close[CountBars-1] < Open[CountBars-1])
   {
   value2[CountBars - 1] = Close[CountBars - 1] * (1 + WATR);
   trend = -1; value1[CountBars - 1] = 0.0;
   }

//----
   bar=CountBars;
   while(bar>=0)
     {
value1[bar]=0.0; value2[bar]=0.0;

    if (Variant == 3)
    {
        AvgRange=0;
        for (i=1; i<=AveragePeriod; i++)
            {
            dK = 1+(AveragePeriod_D-i)/AveragePeriod_D;
            AvgRange=AvgRange+ dK*MathAbs(High[bar + i]-Low[bar + i]);
            }
        WATR = AvgRange/AveragePeriod_D;
    }
    if (trend == 1)
      {
       if (Close[bar] > price) price = Close[bar];
       value = price * (1 - WATR);
       if (Close[bar] < value) 
         {
          price = Close[bar];
          value = price * (1 + WATR);
          trend = -1;
          }
       }
    if (trend == -1) 
      {
       if (Close[bar] < price) price = Close[bar];
       value = price * (1 + WATR);
       if (Close[bar] > value)
          {
          price = Close[bar];
          value = price * (1 - WATR);
          trend = 1;
          }
       }
    
if (trend == 1)  {value1[bar]=Low[bar]; value2[bar]=High[bar];}//if (trend == 1)  {value1[bar]=value; value2[bar]=0.0;}
if (trend == -1)  {value2[bar]=Low[bar]; value1[bar]=High[bar];}//if (trend == -1)  {value2[bar]=value; value1[bar]=0.0;}

      bar--;
     }
   return(0);
  }
//+------------------------------------------------------------------+

Comments