Super_Trend2_v1
Download scriptThis technical indicator is designed to help traders identify the prevailing market direction by visualizing trend shifts and price averages directly on a trading chart. It simplifies complex price movements into clear visual signals, making it easier to distinguish between "bullish" (upward) and "bearish" (downward) momentum.
Core Functional Logic
1. Multi-Period Trend Detection The script functions by comparing two distinct snapshots of historical price data. It calculates an average price for a specific number of past candles and compares it against the average price of the preceding period. By looking at these two "blocks" of time, the tool determines whether the current momentum is accelerating upward or downward.
2. Dynamic Timeframe Adaptation One of the key features of this script is its ability to be "intelligent" regarding different chart scales. It includes a configuration that allows it to automatically adjust its sensitivity based on the timeframe you are viewing (e.g., switching its internal logic automatically when moving from a 1-minute chart to a Daily or Weekly chart). This ensures that the trend signals remain relevant regardless of whether you are day trading or swing trading.
3. Visual Trend Tracking (SuperTrend) The tool provides clear visual lines on the chart:
- Upward Trends: When the logic identifies bullish momentum, it plots a line based on the price action relative to market volatility.
- Downward Trends: Conversely, when bearish momentum is detected, it plots a corresponding line. The script uses a "memory" function to ensure these lines remain smooth; they won't jump erratically but will hold their position until a definitive trend reversal is confirmed by the price action.
4. Volatility-Based Buffering To prevent the trend lines from being too "tight" to the candles (which can lead to false signals), the script incorporates an Average True Range (ATR) calculation. This adds a layer of breathing room to the trend lines, effectively acting as a buffer that accounts for market volatility.
5. Optional Price Averaging For traders who prefer a more conservative view of the market, the script includes an optional feature to display an "Average Price Line." This provides a steady middle-ground reference point, helping traders see where the "fair value" lies between the two calculated price periods.
Summary for the User
In short, this tool acts as a filter for market noise. It looks at recent history, calculates whether the current trend is stronger than the previous one, and draws a visual boundary on your chart. When the line shifts, it signals a potential change in market sentiment, allowing you to stay aligned with the dominant price movement.
/*-----------------------------+
| |
| Shared by www.Aptrafx.com |
| |
+------------------------------*/
//+------------------------------------------------------------------+
//| strend.mq4 |
//| Copyright © 2005, Jason Robinson (jnrtrading). |
//| http://www.jnrtrading.co.uk |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, Jason Robinson (jnrtrading)."
#property link "http://www.jnrtrading.co.uk"
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Lime
#property indicator_color2 Red
#property indicator_color3 Orange
double TrendUp[], TrendDown[], Price1[], Price2[], AvgPrice[], Trend[];
int UpDownShift;
double price1, price2;
extern int NbPeriods = 10;
extern bool Display_SuperTrend = true;
extern bool Display_Average_Price_Line = false;
extern bool Automatic_Timeframe_Settings = false;
extern int M1_NbPeriods = 10;
extern int M5_NbPeriods = 10;
extern int M15_NbPeriods = 10;
extern int M30_NbPeriods = 10;
extern int H1_NbPeriods = 10;
extern int H4_NbPeriods = 10;
extern int D1_NbPeriods = 10;
extern int W1_NbPeriods = 10;
extern int MN_NbPeriods = 10;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
IndicatorBuffers(6);
SetIndexBuffer(0, TrendUp);
SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, 2);
SetIndexBuffer(1, TrendDown);
SetIndexStyle(1, DRAW_LINE, STYLE_SOLID, 2);
SetIndexBuffer(2, AvgPrice);
SetIndexStyle(2, DRAW_LINE, STYLE_SOLID, 2);
SetIndexBuffer(3, Price1);
SetIndexBuffer(4, Price2);
SetIndexBuffer(5, Trend);
/*switch(Period()) {
case 1: UpDownShift = 5; break;
case 5: UpDownShift = 9; break;
case 15: UpDownShift = 10; break;
case 30: UpDownShift = 11; break;
case 60: UpDownShift = 30; break;
case 240: UpDownShift = 45; break;
case 1440: UpDownShift = 55; break;
case 10080: UpDownShift = 150; break;
case 43200: UpDownShift = 350; break;
}*/
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int limit, i, j, shift;
double Price3;
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;
if (Automatic_Timeframe_Settings == true) {
switch(Period()) {
case 1: NbPeriods = M1_NbPeriods; break;
case 5: NbPeriods = M5_NbPeriods; break;
case 15: NbPeriods = M15_NbPeriods; break;
case 30: NbPeriods = M30_NbPeriods; break;
case 60: NbPeriods = H1_NbPeriods; break;
case 240: NbPeriods = H4_NbPeriods; break;
case 1440: NbPeriods = D1_NbPeriods; break;
case 10080: NbPeriods = W1_NbPeriods; break;
case 43200: NbPeriods = MN_NbPeriods; break;
}
}
for (i = limit; i >= 0; i--) {
Price1[i] = 0;
Price2[i] = 0;
for(j = 0; j < NbPeriods; j++) {
Price1[i] = Price1[i] + ((High[i+j] + Low[i+j] + Close[i+j])/3);
}
Price1[i] = Price1[i] / NbPeriods;
for(j = NbPeriods; j < (NbPeriods*2); j++) {
Price2[i] = Price2[i] + ((High[i+j] + Low[i+j] + Close[i+j])/3);
}
Price2[i] = Price2[i] / NbPeriods;
}
for (i = limit; i >= 0; i--) {
if (Price1[i] > Price2[i]) Trend[i] = 90;
if (Price1[i] < Price2[i]) Trend[i] = 10;
if (Trend[i+1] > Trend[i] && Trend[i+1] > Trend[i+2]) Trend[i+1] = 10;
if (Trend[i+1] < Trend[i] && Trend[i+1] < Trend[i+2]) Trend[i+1] = 90;
}
for (i = limit; i >= 0; i--) {
price1 = (High[i] + Low[i] + Close[i])/3;
price2 = (High[i+1] + Low[i+1] + Close[i+1])/3;
if (Display_Average_Price_Line == true) AvgPrice[i] = (Price1[i] + Price2[i])/2;
if (Display_SuperTrend == true) {
if(Trend[i] == 90) {
TrendDown[i] = EMPTY_VALUE;
if(TrendDown[i+1] != EMPTY_VALUE) TrendUp[i+1] = TrendDown[i+1];
TrendUp[i] = Low[i] - iATR(NULL,0,10,i);// Point*UpDownShift;
if (price1 < price2 && TrendDown[i+1] != TrendUp[i+1]) TrendUp[i] = TrendUp[i+1];
if (Close[i] < Close[i+1] && TrendDown[i+1] != TrendUp[i+1]) TrendUp[i] = TrendUp[i+1];
if (High[i] < High[i+1] && TrendDown[i+1] != TrendUp[i+1]) TrendUp[i] = TrendUp[i+1];
if (TrendUp[i] < TrendUp[i+1] && TrendUp[i+1] != TrendDown[i+1]) TrendUp[i] = TrendUp[i+1];
}
if(Trend[i] == 10) {
TrendUp[i] = EMPTY_VALUE;
if(TrendUp[i+1] != EMPTY_VALUE) TrendDown[i+1] = TrendUp[i+1];
TrendDown[i] = High[i] + iATR(NULL,0,10,i);// Point*UpDownShift;
if (price1 > price2 && TrendDown[i+1] != TrendUp[i+1]) TrendUp[i] = TrendUp[i+1];
if (Close[i] > Close[i+1] && TrendDown[i+1] != TrendUp[i+1]) TrendUp[i] = TrendUp[i+1];
if (Low[i] > Low[i+1] && TrendUp[i+1] != TrendDown[i+1]) TrendDown[i] = TrendDown[i+1];
if (TrendDown[i] > TrendDown[i+1] && TrendUp[i+1] != TrendDown[i+1]) TrendDown[i] = TrendDown[i+1];
}
}
}
//----
//----
return(0);
}
//+------------------------------------------------------------------+
Comments