SuperTrend nrp new

Author: mladen
SuperTrend nrp new

This script functions as a technical analysis tool designed to identify and visualize the prevailing market trend on a trading chart. By analyzing price action in real-time, it helps traders distinguish between upward and downward movements, providing a clear visual cue for potential entry or exit points based on momentum.

How the Logic Works

The indicator operates by processing three main components of market data: volatility, average price, and momentum. Here is the step-by-step breakdown of how it interprets the market:

1. Measuring Volatility and Price Range The script first calculates the "Average True Range" (ATR), which measures how much an asset typically moves over a specific number of periods. It then combines this with the midpoint of the current price range (the average of the high and low prices). By multiplying these figures, the tool establishes a "buffer zone" above and below the current price.

2. Determining Trend Direction The logic constantly compares the closing price against the calculated buffer zones:

  • Bullish Signal: If the price closes significantly above the upper threshold, the script identifies an upward trend.
  • Bearish Signal: If the price closes significantly below the lower threshold, the script identifies a downward trend.

3. Smoothing and Continuity (The "SuperTrend" Effect) To prevent the indicator from reacting to minor, insignificant price flickers, the script employs a smoothing logic. It ensures that the trend line remains consistent:

  • In an uptrend, it captures the highest point of the lower boundary to ensure the line doesn't drop prematurely.
  • In a downtrend, it captures the lowest point of the upper boundary to ensure the line doesn't rise until the trend has officially shifted.

4. Visual Output The final result is a dynamic line on your chart that acts as a trailing support or resistance level.

  • When the line stays below the price, it signifies an active uptrend, often displayed in a color representing growth (Lime).
  • When the line stays above the price, it signifies an active downtrend, often displayed in a color representing decline (Red).

Summary for Traders

Essentially, this tool acts as a "smart" trailing stop. It follows the trend closely but maintains enough distance to ignore market noise. When the line flips from one side of the price to the other, it signals a potential shift in market sentiment, allowing you to stay on the right side of the prevailing move.

Indicators Used
Indicator of the average true rangeMoving average indicator
9 Views
0 Downloads
0 Favorites
SuperTrend nrp new
//+------------------------------------------------------------------+
//|                                               SuperTrend nrp.mq4 |
//|                                                           Mladen |
//+------------------------------------------------------------------+
#property copyright "mladen"
#property link      "mladenfx@gmail.com"

#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Lime
#property indicator_color2 Red
#property indicator_color3 Red

extern int    period       = 10;
extern int    appliedPrice = PRICE_CLOSE;
extern double multiplier   = 3.0;

//
//
//
//
//

double Trend[];
double TrendDoA[];
double TrendDoB[];
double Direction[];
double Up[];
double Dn[];

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
//
//
//
//
//

int init()
{
   IndicatorBuffers(6);
      SetIndexBuffer(0, Trend);
      SetIndexBuffer(1, TrendDoA);
      SetIndexBuffer(2, TrendDoB);
      SetIndexBuffer(3, Direction);
      SetIndexBuffer(4, Up);
      SetIndexBuffer(5, Dn);
      
      SetIndexLabel(0,"SuperTrend");
      SetIndexLabel(1,"SuperTrend");
      SetIndexLabel(2,"SuperTrend");
   IndicatorShortName("SuperTrend");
   period = MathMax(1,period);
}
int deinit()
{
   return(0);
}




//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
//
//
//
//
//

int start()
{
   int counted_bars = IndicatorCounted();
   int limit,i;

   if(counted_bars < 0) return(-1);
   if(counted_bars > 0) counted_bars--;
           limit = Bars-counted_bars;

   //
   //
   //
   //
   //
      
   if (Direction[limit] <= 0) CleanPoint(limit,TrendDoA,TrendDoB);
   for(i = limit; i >= 0; i--)
   {
         double atr    = iATR(NULL,0,period,i);
         double cprice = iMA(NULL,0,1,0,MODE_SMA,appliedPrice,i);
         double mprice = (High[i]+Low[i])/2;
                Up[i]  = mprice+multiplier*atr;
                Dn[i]  = mprice-multiplier*atr;
         
         //
         //
         //
         //
         //
         
         Direction[i] = Direction[i+1];
            if (cprice > Up[i+1]) Direction[i] =  1;
            if (cprice < Dn[i+1]) Direction[i] = -1;
         TrendDoA[i] = EMPTY_VALUE;
         TrendDoB[i] = EMPTY_VALUE;
            if (Direction[i] > 0) { Dn[i] = MathMax(Dn[i],Dn[i+1]); Trend[i] = Dn[i]; }
            else                  { Up[i] = MathMin(Up[i],Up[i+1]); Trend[i] = Up[i]; PlotPoint(i,TrendDoA,TrendDoB,Trend); }
   }
   return(0);
}


//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
//
//
//
//
//

void CleanPoint(int i,double& first[],double& second[])
{
   if ((second[i]  != EMPTY_VALUE) && (second[i+1] != EMPTY_VALUE))
        second[i+1] = EMPTY_VALUE;
   else
      if ((first[i] != EMPTY_VALUE) && (first[i+1] != EMPTY_VALUE) && (first[i+2] == EMPTY_VALUE))
          first[i+1] = EMPTY_VALUE;
}

//
//
//
//
//

void PlotPoint(int i,double& first[],double& second[],double& from[])
{
   if (first[i+1] == EMPTY_VALUE)
      {
      if (first[i+2] == EMPTY_VALUE) {
          first[i]    = from[i];
          first[i+1]  = from[i+1];
          second[i]   = EMPTY_VALUE;
         }
      else {
          second[i]   = from[i];
          second[i+1] = from[i+1];
          first[i]    = EMPTY_VALUE;
         }
      }
   else
      {
         first[i]   = from[i];
         second[i]  = EMPTY_VALUE;
      }
}

Comments