DDFX 6 Medium Trend v3
Download scriptThis script is designed as a technical analysis tool for the MetaTrader platform, specifically engineered to identify and visualize market trends. It functions by monitoring price action relative to volatility bands to provide traders with clear visual cues regarding potential entry points and trend reversals.
Core Logic Overview
The tool operates on a "Medium Trend" detection logic. Rather than just looking at simple price movement, it calculates dynamic boundaries (based on Bollinger Band principles) to determine the strength and direction of the market. It essentially creates a "safety zone" for the price; when the price breaks these boundaries in a specific way, the script recognizes a shift in momentum.
Key Functionalities
- Trend Detection: The script continuously scans historical and real-time price data to establish whether the current trend is bullish (upward) or bearish (downward). It looks for specific "breakout" conditions where the price closes outside of its established volatility limits.
- Dynamic Price Leveling:
- UpTrend Logic: When an upward move is detected, the script tracks a specific level that acts as a trailing indicator. If the market moves higher, this level adjusts to stay in sync with the momentum.
- DownTrend Logic: Conversely, when a downward move is detected, it tracks a corresponding lower level that adapts to the descending price action.
- Visual Signaling: The script translates these complex calculations into easy-to-read visual elements on your chart:
- Histograms and Lines: It draws specific lines and histogram bars to represent the "Stop" levels and "Signal" points for both upward and downward trends. This allows traders to see exactly where a trend might be losing steam or where it is firmly established.
- Trend Filtering: It uses a filtering mechanism to ensure that signals aren't "noisy." It essentially checks if a trend has officially switched before displaying a new signal, helping to filter out minor price fluctuations that don't represent a true change in direction.
- User Alerts: The script includes an integrated notification system. When the logic detects a confirmed shift—specifically when the market breaks out into a new trend—it can trigger an audible and visual alert on the screen. This allows traders to react quickly without having to stare at the charts constantly.
Customization Parameters
The script provides several adjustable inputs to tailor the behavior to different trading styles:
- Timeframe & Length: Allows you to choose the speed of the calculation (e.g., looking at short-term "fast" moves vs. long-term "slow" trends).
- Money Risk: A multiplier used to adjust the sensitivity and positioning of the trend lines based on the user's desired risk profile.
- Signal & Line Toggles: These allow the user to choose which specific visual elements (like histograms or solid lines) they want visible on their workspace, keeping the chart clean and focused on the information they find most useful.
/*
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 = 12;
extern int Deviation = 2;
extern double MoneyRisk = 1.0;
extern int Signal = 1;
extern int Line = 1;
extern int Nbars = 9900;
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 = "MEDIUM 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