sa_2523MTEI_Supertrend

Download script
Author:
sa_2523MTEI_Supertrend

This technical indicator is designed to provide traders with a visual representation of market trends by identifying the current direction of price movement and establishing specific "boundary" lines on the chart. By smoothing out market noise, it helps users distinguish between temporary fluctuations and sustained upward or downward momentum.

Core Operational Logic

The script functions by analyzing three primary components of market data to determine trend behavior:

1. Momentum Tracking The tool utilizes a momentum-based calculation to sense the "strength" of the current price action. It compares the current momentum against the previous period's momentum. When the momentum crosses a specific threshold, the script recognizes a potential shift in the market's direction, triggering a change in the trend status.

2. Volatility Measurement To ensure the trend lines remain relevant to the current market conditions, the indicator calculates the average price range over a set period of time. This allows the tool to understand how much the price typically moves (volatility), ensuring that the calculated boundaries are neither too tight nor too loose for the specific asset being traded.

3. Dynamic Trend Boundaries Based on the signals gathered from momentum and volatility, the script generates two distinct visual lines:

  • The Bullish Boundary: When the momentum indicates an upward trend, the tool plots a line below the current price. This line acts as a "floor," moving dynamically with the price but staying locked in place unless the price moves significantly enough to break it.
  • The Bearish Boundary: Conversely, during a downward trend, the tool plots a line above the price, acting as a "ceiling."

Visual Behavior and User Experience

Instead of simply reacting to every small tick in price, the logic includes a "memory" feature. This ensures that the trend lines do not move backward against the current flow; they only advance in the direction of the trend or remain stable. For the user, this translates to a clean visual experience where:

  • Green Lines represent an active upward trend (support).
  • Red Lines represent an active downward trend (resistance).

By combining momentum shifts with volatility-adjusted pricing, the script provides a clear, real-time map of whether the market is currently biased toward growth or decline.

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

//+------------------------------------------------------------------------+
//|                                                 sa#MTEI_Supertrend.mq4 |
//|http://finance.groups.yahoo.com/group/MetaTrader_Experts_and_Indicators/|
//+------------------------------------------------------------------------+
#property copyright ""
#property link      "http://finance.groups.yahoo.com/group/MetaTrader_Experts_and_Indicators/"

#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Lime
#property indicator_color2 Red


double TrendUp[];
double TrendDown[];
int st = 0;
//extern int SlowerEMA = 6;



//+------------------------------------------------------------------+
//| Custom indicator initialization function|
//+------------------------------------------------------------------+
int init()
 {
//---- indicators

  SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, 2);
  SetIndexBuffer(0, TrendUp);
  SetIndexStyle(1, DRAW_LINE, STYLE_SOLID, 2);
  SetIndexBuffer(1, TrendDown);

  /*SetIndexStyle(0, DRAW_ARROW, EMPTY);
  SetIndexArrow(0, 159);
  SetIndexBuffer(0, TrendUp);
  SetIndexStyle(1, DRAW_ARROW, EMPTY);
  SetIndexArrow(1, 159);
  SetIndexBuffer(1, TrendDown);*/

  /*for(int i = 0; i < Bars; i++) {
     TrendUp[i] = NULL;
     TrendDown[i] = NULL;
  }*/
//----
  return(0);
 }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function|
//+------------------------------------------------------------------+
int deinit()
 {
//----
  /*for(int i = 0; i < Bars; i++) {
     TrendUp[i] = NULL;
     TrendDown[i] = NULL;
  }*/
//----
  return(0);
 }
//+------------------------------------------------------------------+
//| Custom indicator iteration function|
//+------------------------------------------------------------------+
int start()
 {

  int limit, i, counter;
  double Range, AvgRange, cciTrendNow, cciTrendPrevious, var;

  int counted_bars = IndicatorCounted();
//---- check for possible errors
  if(counted_bars < 0) return(-1);
//---- last counted bar will be recounted
  if(counted_bars > 0) counted_bars--;

  limit=Bars-counted_bars;

  for(i = limit; i >= 0; i--) {
     cciTrendNow = iCCI(NULL, 0, 50, PRICE_TYPICAL, i);
     cciTrendPrevious = iCCI(NULL, 0, 50, PRICE_TYPICAL, i+1);

     //st = st * 100;


     counter = i;
     Range = 0;
     AvgRange = 0;
     for (counter = i; counter >= i-9; counter--) {
        AvgRange = AvgRange + MathAbs(High[counter]-Low[counter]);
     }
     Range = AvgRange/10;
     if (cciTrendNow >= st && cciTrendPrevious < st) {
        TrendUp[i+1] = TrendDown[i+1];
     }

     if (cciTrendNow <= st && cciTrendPrevious > st) {
        TrendDown[i+1] = TrendUp[i+1];
     }

     if (cciTrendNow >= st) {
        TrendUp[i] = Low[i] - iATR(NULL, 0, 5, i);
        if (TrendUp[i] < TrendUp[i+1]) {
           TrendUp[i] = TrendUp[i+1];
        }
     }
     else if (cciTrendNow <= st) {
        TrendDown[i] = High[i] + iATR(NULL, 0, 5, i);
        if (TrendDown[i] > TrendDown[i+1]) {
           TrendDown[i] = TrendDown[i+1];
        }
     }
  }

//----

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

//+------------------------------------------------------------------+

Comments