Author: Rosh
NRTR Rosh

This technical indicator is designed to analyze market trends by identifying dynamic "ceiling" and "floor" levels. It aims to help traders visualize the direction of price movement and identify specific points where the trend might be shifting or exhausting.

Core Logic Overview

The script operates by monitoring the relationship between current price action and historical volatility. Instead of using static numbers, it calculates these boundaries based on the Average True Range (ATR), which measures how much the market typically moves over a specific period.

How the Indicator Works

1. Trend Identification The tool constantly evaluates whether the market is in an "Uptrend" or a "Downtrend."

  • If the price breaks through certain established boundaries, the script flips the trend status.
  • When a trend is active, the indicator establishes a corresponding support or resistance level based on the current volatility.

2. Dynamic Ceilings and Floors The primary goal of this script is to project visual markers (Ceilings and Floors):

  • In an Uptrend: The tool identifies a "Ceiling" (the upper boundary). If the price reaches or exceeds this ceiling, the indicator updates the level to reflect the new height.
  • In a Downtrend: The tool identifies a "Floor" (the lower boundary). If the price drops below this floor, the indicator resets the level to the new lower point.

3. Signal Generation The script monitors for two specific types of price behavior:

  • Breakouts: When the price moves aggressively past a buffer zone, it signals that the current trend is potentially continuing or gaining strength.
  • Trend Reversals: If the price penetrates the opposite side of the buffer (e.g., breaking downward while in an uptrend), the logic triggers a "New Trend" event. This automatically flips the market status, switches from showing a ceiling to showing a floor (or vice versa), and recalculates the volatility buffers accordingly.

Visual Behavior

For the user, this translates into a chart that updates dynamically. Rather than staying still, the support and resistance lines "track" the price. They expand or contract based on how volatile the market is—widening during choppy periods and tightening during stable movements—providing a more reactive view of market structure than standard fixed-line indicators.

Indicators Used
Indicator of the average true range
Miscellaneous
Implements a curve of type %1
15 Views
0 Downloads
0 Favorites
NRTR Rosh
//+------------------------------------------------------------------+
//|                                                 NRTR Rosh v2.mq4 |
//|                                                             Rosh |
//|                           http://forexsystems.ru/phpBB/index.php |
//+------------------------------------------------------------------+
#property copyright "Rosh"
#property link      "http://forum.alpari-idc.ru/viewtopic.php?t=48186"

#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;
extern bool      useSendMail=true;
//---- 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);
  }
//+------------------------------------------------------------------+
//| ïðîáèòèå âåðõà ÄÀÓÍòðåíäà                              |
//+------------------------------------------------------------------+
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("Âíèìàíèå! Òðåíä íå îïðåäåëåí, òàêîãî áûòü íå ìîæåò. Áàð îò êîíöà ",(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("Âíèìàíèå! Òðåíä íå îïðåäåëåí, òàêîãî áûòü íå ìîæåò");
  }

//+------------------------------------------------------------------+
//| ïðîäîëæåíèå òðåíäà                                               |
//+------------------------------------------------------------------+
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];
  }

//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| 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