DDFX 7 Major Trend v3
Download scriptOverview
This script is a technical analysis indicator designed for the MetaTrader platform. Its primary purpose is to identify and visualize major trend directions—specifically "Up Trends" and "Down Trends"—by analyzing price movements in relation to volatility boundaries. It functions as a trend-following tool that helps traders determine when a market shift has occurred and where specific price levels (such as stop-loss or signal levels) might be established.
Core Logic and Functionality
The logic of the script can be broken down into three main stages:
1. Trend Detection
The indicator monitors price action to determine the current market sentiment. It uses a specific calculation to establish whether the price is currently in an ascending or descending phase. By observing whether the closing price exceeds certain upper boundaries or falls below lower boundaries, the script categorizes the market into two distinct states:
- Bullish State: When the price shows strength moving upward.
- Bearish State: When the price shows weakness moving downward.
2. Dynamic Level Calculation
Instead of using static numbers, the script calculates dynamic "Trend Lines" and "Signal Levels." These levels are adjusted based on:
- Market Volatility: The indicators widen or contract based on how much the market is currently fluctuating.
- Risk Preferences: A user-defined "Money Risk" factor allows the indicator to calculate specific price offsets. This ensures that the displayed lines are mathematically proportional to the user's desired risk profile.
3. Signal and Visual Output
Once a trend shift is detected, the script performs several actions simultaneously:
- Visual Mapping: It plots distinct lines and histograms on the chart. Red and Blue colors are used to differentiate between "UpTrend" and "DownTrend" components, allowing for immediate visual recognition of market direction.
- Trend Persistence: The script includes logic to ensure that trend lines remain consistent; they do not fluctuate erratically but rather stay "locked" or follow a specific path until a definitive reversal signal is confirmed.
- Alert System: The code contains an optional notification system. If the user enables sounds, the script will trigger an audible alert and a pop-up message the moment the trend switches from Up to Down (or vice versa), providing real-time awareness without needing to constantly watch the screen.
Summary for the User
In simple terms, this tool acts as an automated "trend scout." It looks at the volatility of the market and tells you where the trend is heading. It draws specific lines on your chart that act as markers for these trends, adjusts those markers based on your personal risk settings, and notifies you immediately when the market flips from one direction to another.
/*
Generated by EX4-TO-MQ4 decompiler V4.0.224.1 []
Website: http://purebeam.biz
E-mail : purebeam@gmail.com
*/
#property copyright "Copyright © 2006, TrendLaboratory Ltd."
#property link "http://finance.groups.yahoo.com/group/TrendLaboratory"
#property indicator_separate_window
#property indicator_minimum 0.0
#property indicator_maximum 1.0
#property indicator_buffers 6
#property indicator_color1 Black
#property indicator_color2 Black
#property indicator_color3 Black
#property indicator_color4 Red
#property indicator_color5 Blue
#property indicator_color6 Red
extern int TimeFrame = 0;
extern int Length = 21;
extern int Deviation = 1;
extern double MoneyRisk = 1.0;
extern int Signal = 1;
extern int Line = 1;
extern int Nbars = 9500;
double g_ibuf_108[];
double g_ibuf_112[];
double g_ibuf_116[];
double g_ibuf_120[];
double g_ibuf_124[];
double g_ibuf_128[];
extern bool SoundON = FALSE;
bool gi_136 = FALSE;
bool gi_140 = FALSE;
string gs_unused_144;
int init() {
SetIndexBuffer(0, g_ibuf_108);
SetIndexBuffer(1, g_ibuf_112);
SetIndexBuffer(2, g_ibuf_116);
SetIndexBuffer(3, g_ibuf_120);
SetIndexBuffer(4, g_ibuf_124);
SetIndexBuffer(5, g_ibuf_128);
SetIndexStyle(0, DRAW_NONE, STYLE_SOLID, 0);
SetIndexStyle(1, DRAW_NONE, STYLE_SOLID, 0);
SetIndexStyle(2, DRAW_NONE, STYLE_SOLID, 2);
SetIndexStyle(3, DRAW_NONE, STYLE_SOLID, 2);
SetIndexStyle(4, DRAW_HISTOGRAM);
SetIndexStyle(5, DRAW_HISTOGRAM);
SetIndexArrow(0, 164);
SetIndexArrow(1, 164);
SetIndexArrow(2, 174);
SetIndexArrow(3, 174);
IndicatorDigits(MarketInfo(Symbol(), MODE_DIGITS));
SetIndexLabel(0, "UpTrend Stop");
SetIndexLabel(1, "DownTrend Stop");
SetIndexLabel(2, "UpTrend Signal");
SetIndexLabel(3, "DownTrend Signal");
SetIndexLabel(4, "UpTrend Line");
SetIndexLabel(5, "DownTrend Line");
SetIndexDrawBegin(0, Length);
SetIndexDrawBegin(1, Length);
SetIndexDrawBegin(2, Length);
SetIndexDrawBegin(3, Length);
SetIndexDrawBegin(4, Length);
SetIndexDrawBegin(5, Length);
switch (TimeFrame) {
case 1:
gs_unused_144 = "Period M1";
break;
case 5:
gs_unused_144 = "Period M5";
break;
case 15:
gs_unused_144 = "Period M15";
break;
case 30:
gs_unused_144 = "Period M30";
break;
case 60:
gs_unused_144 = "Period H1";
break;
case 240:
gs_unused_144 = "Period H4";
break;
case 1440:
gs_unused_144 = "Period D1";
break;
case 10080:
gs_unused_144 = "Period W1";
break;
case 43200:
gs_unused_144 = "Period MN1";
break;
default:
gs_unused_144 = " Current Timeframe ";
TimeFrame = 0;
}
string ls_0 = "MAJOR TREND";
IndicatorShortName(ls_0);
return (0);
}
int start() {
int li_8;
double lda_12[25000];
double lda_16[25000];
double lda_20[25000];
double lda_24[25000];
for (int l_shift_4 = Nbars; l_shift_4 >= 0; l_shift_4--) {
g_ibuf_108[l_shift_4] = 0;
g_ibuf_112[l_shift_4] = 0;
g_ibuf_116[l_shift_4] = 0;
g_ibuf_120[l_shift_4] = 0;
g_ibuf_124[l_shift_4] = EMPTY_VALUE;
g_ibuf_128[l_shift_4] = EMPTY_VALUE;
}
for (l_shift_4 = Nbars - Length - 1; l_shift_4 >= 0; l_shift_4--) {
lda_12[l_shift_4] = iBands(NULL, TimeFrame, Length, Deviation, 0, PRICE_CLOSE, MODE_UPPER, l_shift_4);
lda_16[l_shift_4] = iBands(NULL, TimeFrame, Length, Deviation, 0, PRICE_CLOSE, MODE_LOWER, l_shift_4);
if (Close[l_shift_4] > lda_12[l_shift_4 + 1]) li_8 = 1;
if (Close[l_shift_4] < lda_16[l_shift_4 + 1]) li_8 = -1;
if (li_8 > 0 && lda_16[l_shift_4] < lda_16[l_shift_4 + 1]) lda_16[l_shift_4] = lda_16[l_shift_4 + 1];
if (li_8 < 0 && lda_12[l_shift_4] > lda_12[l_shift_4 + 1]) lda_12[l_shift_4] = lda_12[l_shift_4 + 1];
lda_20[l_shift_4] = lda_12[l_shift_4] + (MoneyRisk - 1.0) / 2.0 * (lda_12[l_shift_4] - lda_16[l_shift_4]);
lda_24[l_shift_4] = lda_16[l_shift_4] - (MoneyRisk - 1.0) / 2.0 * (lda_12[l_shift_4] - lda_16[l_shift_4]);
if (li_8 > 0 && lda_24[l_shift_4] < lda_24[l_shift_4 + 1]) lda_24[l_shift_4] = lda_24[l_shift_4 + 1];
if (li_8 < 0 && lda_20[l_shift_4] > lda_20[l_shift_4 + 1]) lda_20[l_shift_4] = lda_20[l_shift_4 + 1];
if (li_8 > 0) {
if (Signal > 0 && g_ibuf_108[l_shift_4 + 1] == -1.0) {
g_ibuf_116[l_shift_4] = lda_24[l_shift_4];
g_ibuf_108[l_shift_4] = lda_24[l_shift_4];
if (Line > 0) g_ibuf_124[l_shift_4] = lda_24[l_shift_4];
if (SoundON == TRUE && l_shift_4 == 0 && !gi_136) {
Alert("BBands go Up", Symbol(), "-", Period());
gi_136 = TRUE;
gi_140 = FALSE;
}
} else {
g_ibuf_108[l_shift_4] = lda_24[l_shift_4];
if (Line > 0) g_ibuf_124[l_shift_4] = lda_24[l_shift_4];
g_ibuf_116[l_shift_4] = -1;
}
if (Signal == 2) g_ibuf_108[l_shift_4] = 0;
g_ibuf_120[l_shift_4] = -1;
g_ibuf_112[l_shift_4] = -1.0;
g_ibuf_128[l_shift_4] = EMPTY_VALUE;
}
if (li_8 < 0) {
if (Signal > 0 && g_ibuf_112[l_shift_4 + 1] == -1.0) {
g_ibuf_120[l_shift_4] = lda_20[l_shift_4];
g_ibuf_112[l_shift_4] = lda_20[l_shift_4];
if (Line > 0) g_ibuf_128[l_shift_4] = lda_20[l_shift_4];
if (SoundON == TRUE && l_shift_4 == 0 && !gi_140) {
Alert("BBands go Down", Symbol(), "-", Period());
gi_140 = TRUE;
gi_136 = FALSE;
}
} else {
g_ibuf_112[l_shift_4] = lda_20[l_shift_4];
if (Line > 0) g_ibuf_128[l_shift_4] = lda_20[l_shift_4];
g_ibuf_120[l_shift_4] = -1;
}
if (Signal == 2) g_ibuf_112[l_shift_4] = 0;
g_ibuf_116[l_shift_4] = -1;
g_ibuf_108[l_shift_4] = -1.0;
g_ibuf_124[l_shift_4] = EMPTY_VALUE;
}
}
return (0);
}
Comments