Ind-NRTR_v1

Author: Copyright � 2006, LeonSi
Ind-NRTR_v1

This indicator is designed to provide traders with a visual representation of market trends and potential reversal points by utilizing volatility-based calculations. Rather than relying on simple moving averages, it focuses on the price's relationship with its own historical volatility (measured via the ATR or Average True Range).

Core Logic Overview

The script functions by identifying the current market direction—whether it is trending upward or downward—and projecting "boundaries" based on how much the price typically fluctuates. It essentially creates a dynamic corridor that follows the price action.

How the Trend is Determined

The indicator classifies the market into two primary states:

  • Uptrend: When the price shows strength moving higher, the system establishes an "upper boundary" (Ceiling).
  • Downtrend: When the price shows weakness moving lower, the system establishes a "lower boundary" (Floor).

Dynamic Boundary Updates

The logic constantly monitors the live price against these boundaries to determine when the trend is shifting:

  1. Volatility Offsets: The tool calculates a specific distance from the current price. This distance is multiplied by a volatility factor, ensuring that in high-volatility markets, the "boundaries" are wider, and in low-volatility markets, they are tighter.
  2. Breakout Detection:
    • If the price moves significantly enough to break through the established ceiling or floor in its current direction, the indicator updates that specific boundary to a new level. This represents a "continuation" of the trend with a new price base.
    • If the price breaks through the boundary in the opposite direction (a breakdown or breakout against the current trend), the script triggers a Trend Reversal.

Visual Signals

The script translates these calculations into clear visual markers on your chart:

  • Arrows: These act as signals for potential entries. They appear when the logic detects specific price actions, such as a move breaking through a boundary or a confirmed shift in trend direction.
  • Trend Tracking: By constantly checking if the current candle's high or low exceeds the calculated volatility limits, the indicator ensures that the trend lines stay relevant to real-time market movements rather than becoming outdated.

Summary for Traders

Essentially, this script filters out "market noise." Instead of reacting to every small price wiggle, it waits for the price to move a significant distance (based on historical volatility) before confirming a trend shift or a new boundary. It helps traders stay on the right side of the momentum while identifying the specific points where a trend may be losing steam or starting a new phase.

Indicators Used
Indicator of the average true range
Miscellaneous
Implements a curve of type %1
13 Views
0 Downloads
0 Favorites
Ind-NRTR_v1
/*-----------------------------+
|			       |
| Shared by www.Aptrafx.com    |
|			       |
+------------------------------*/

//+------------------------------------------------------------------+
//|                                                     Ind-NRTR.mq4 |
//|                                         Copyright © 2006, LeonSi |
//|                                      http://www.expert-mt4.nm.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, LeonSi"
#property link      "http://www.expert-mt4.nm.ru"

#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Tomato
#property indicator_color2 DeepSkyBlue
#property indicator_color3 DeepSkyBlue
#property indicator_color4 Tomato
//---- input parameters
extern int       PerATR=40;
extern double    kATR=2.0;
//---- buffers
double SellBuffer[];
double BuyBuffer[];
double Ceil[];
double Floor[];
double Trend[];
int sm_Bars;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   IndicatorBuffers(5);

   SetIndexStyle(0,DRAW_ARROW);
   SetIndexArrow(0,251);
   SetIndexBuffer(0,SellBuffer);
   SetIndexEmptyValue(0,0.0);

   SetIndexStyle(1,DRAW_ARROW);
   SetIndexArrow(1,251);
   SetIndexBuffer(1,BuyBuffer);
   SetIndexEmptyValue(1,0.0);

   SetIndexStyle(2,DRAW_ARROW);
   SetIndexArrow(2,159);
   SetIndexBuffer(2,Ceil);
   SetIndexEmptyValue(2,0.0);

   SetIndexStyle(3,DRAW_ARROW);
   SetIndexArrow(3,159);
   SetIndexBuffer(3,Floor);
   SetIndexEmptyValue(3,0.0);

   SetIndexBuffer(4,Trend);   
   SetIndexEmptyValue(4,0);
   //----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
//----
   return(0);
  }
//+------------------------------------------------------------------+
bool BreakDown(int shift)
  {
   bool result=false;
   if (Close[shift]>SellBuffer[shift+1]) result=true;
   return(result);
  }
//+------------------------------------------------------------------+
bool BreakUp(int shift)
  {
   bool result=false;
   if (Close[shift]<BuyBuffer[shift+1]) result=true;
   return(result);
  }
//+------------------------------------------------------------------+
bool BreakFloor(int shift)
  {
   bool result=false;
   if (High[shift]<Floor[shift+1]) result=true;
   return(result);
  }
//+------------------------------------------------------------------+
bool BreakCeil(int shift)
  {
   bool result=false;
   if (Low[shift]>Ceil[shift+1]) result=true;
   return(result);
  }
//+------------------------------------------------------------------+
bool Uptrend(int shift)
  {
   bool result=false;
   if (Trend[shift+1]==1) result=true;
   if (Trend[shift+1]==-1) result=false;
   if ((Trend[shift+1]!=1)&&(Trend[shift+1]!=-1)) Print("Warning=",(Bars-shift));
   return(result);
  }
//+------------------------------------------------------------------+
double ATR(int iPer,int shift)
  {
   double result;
   result=iATR(NULL,0,iPer,shift);
   return(result);
  }
//+------------------------------------------------------------------+
void NewCeil(int shift)
  {
   Ceil[shift]=Close[shift];
   Floor[shift]=0.0;
  }
//+------------------------------------------------------------------+
void NewFloor(int shift)
  {
   Floor[shift]=Close[shift];
   Ceil[shift]=0.0;
  }
//+------------------------------------------------------------------+
void SetBuyBuffer(int shift)
  {
   BuyBuffer[shift]=Close[shift]-kATR*ATR(PerATR,shift);
   SellBuffer[shift]=0.0;
  }
//+------------------------------------------------------------------+
void SetSellBuffer(int shift)
  {
   SellBuffer[shift]=Close[shift]+kATR*ATR(PerATR,shift);
   BuyBuffer[shift]=0.0;
  }
//+------------------------------------------------------------------+
void NewTrend(int shift)
  {
   if (Trend[shift+1]==1) 
      {
      Trend[shift]=-1;
      NewFloor(shift);
      SetSellBuffer(shift);
      }
   else 
      {
      Trend[shift]=1;
      NewCeil(shift);
      SetBuyBuffer(shift);
      }
   if ((Trend[shift+1]!=1)&&(Trend[shift+1]!=-1)) Print("Warning",(Bars-shift));
  }
//+------------------------------------------------------------------+
void CopyLastValues(int shift)
  {
   SellBuffer[shift]=SellBuffer[shift+1];
   BuyBuffer[shift]=BuyBuffer[shift+1];
   Ceil[shift]=Ceil[shift+1];
   Floor[shift]=Floor[shift+1];
   Trend[shift]=Trend[shift+1];
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
   int limit;
   if (counted_bars>0) limit=Bars-counted_bars;
   if (counted_bars<0) return(0);
   if (counted_bars==0) 
      {
      limit=Bars-PerATR-1;
      if (Close[limit+1]>Open[limit+1]) {Trend[limit+1]=1;Ceil[limit+1]=Close[limit+1];BuyBuffer[limit+1]=Close[limit+1]-kATR*ATR(PerATR,limit+1);}
      if (Close[limit+1]<Open[limit+1]) {Trend[limit+1]=-1;Floor[limit+1]=Close[limit+1];SellBuffer[limit+1]=Close[limit+1]+kATR*ATR(PerATR,limit+1);}
      if (Close[limit+1]==Open[limit+1]) {Trend[limit+1]=1;Ceil[limit+1]=Close[limit+1];BuyBuffer[limit+1]=Close[limit+1]-kATR*ATR(PerATR,limit+1);}
      }
//----
   for (int cnt=limit;cnt>=0;cnt--)
      {
      if (Uptrend(cnt))
         {
         if (BreakCeil(cnt))
            {
            NewCeil(cnt);
            SetBuyBuffer(cnt);
            Trend[cnt]=1;
            continue;
            }
         if (BreakUp(cnt))
            {
            NewTrend(cnt);
            continue;
            }   
         CopyLastValues(cnt);
         }
      else
         {
         if (BreakFloor(cnt))
            {
            NewFloor(cnt);
            SetSellBuffer(cnt);
            Trend[cnt]=-1;
            continue;
            }
         if (BreakDown(cnt))
            {
            NewTrend(cnt);
            continue;
            }   
         CopyLastValues(cnt);
         }
      } 

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

Comments