TrendEnvelopes_v5
Download scriptThis script is a technical analysis tool designed for the MetaTrader platform to help traders identify and visualize market trends. It works by tracking the relationship between current price action and moving averages, creating "envelopes" that signify the direction of the market.
Core Functionality
Trend Identification The logic calculates two specific types of moving averages: one based on the high prices and one based on the low prices of a set timeframe (defined by the user). By comparing the current closing price against these highs and lows, the script determines if the market is in an "Upward" or "Downward" state.
Dynamic Envelopes Instead of just showing a single line, the tool generates dynamic boundaries:
- In an Upward Trend: The script tracks the lower boundary of the price movement, providing a visual floor for the trend.
- In a Downward Trend: The script tracks the upper boundary of the price movement, providing a visual ceiling for the trend. The script is designed to "flatten" these boundaries if the price moves in a way that suggests a weakening of the current trend, ensuring the visual indicators remain relevant to the current market structure.
Signal Generation The tool includes an automated signaling system to notify traders of momentum shifts:
- Buy/Sell Signals: The script looks for specific "crossover" moments where the trend state flips (e.g., moving from a downward state to an upward state).
- Volume Validation: To filter out "noise," the tool checks if there is a minimum amount of trading volume present when these transitions occur.
- Alerts and Warnings: If enabled, the script can trigger visual alerts on your screen, audible sound warnings, or both, precisely when a trend reversal is detected.
User Experience Features
- Visual Cues: The tool uses different line styles and symbols (arrows) to clearly distinguish between upward signals, downward signals, and the overarching trend envelopes.
- Customizable Sensitivity: Users can adjust the period of the moving averages to make the indicator more sensitive to quick price changes or more stable for long-term trend following.
- Real-time Monitoring: The logic updates with every new price tick, ensuring that the "Envelopes" move in sync with live market activity.
/*
Generated by EX4-TO-MQ4 decompiler ONE FILE V4.0.217.1
EX4 ID : 758C6ED8A1FFEEE46780B6453C1F79CA
Website: http://purebeam.biz
E-mail : purebeam@gmail.com
*/
#property copyright "Copyright © 2007, TrendLaboratory Ltd."
#property link "http://finance.groups.yahoo.com/group/TrendLaboratory"
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Yellow
#property indicator_color2 Yellow
#property indicator_color3 Yellow
#property indicator_color4 Yellow
extern int MA_Period = 3;
extern int MA_Method = 1;
extern int UseSignal = 0;
extern int AlertMode = 0;
extern int WarningMode = 0;
double g_ibuf_96[];
double g_ibuf_100[];
double g_ibuf_104[];
double g_ibuf_108[];
double g_ibuf_112[];
double g_ibuf_116[];
double g_ibuf_120[];
int gi_124 = 0;
bool gi_128 = FALSE;
bool gi_132 = FALSE;
int init() {
string ls_unused_4;
IndicatorBuffers(7);
SetIndexStyle(0, DRAW_LINE);
SetIndexStyle(1, DRAW_LINE);
SetIndexStyle(2, DRAW_ARROW);
SetIndexArrow(2, 108);
SetIndexStyle(3, DRAW_ARROW);
SetIndexArrow(3, 108);
IndicatorDigits(MarketInfo(Symbol(), MODE_DIGITS));
if (MA_Period < 2) MA_Period = 10;
int li_0 = MA_Period - 1;
IndicatorShortName("TrendEnvelopes(" + MA_Period + ")");
SetIndexLabel(0, "UpTrendEnv");
SetIndexLabel(1, "DnTrendEnv");
SetIndexLabel(2, "UpSignal");
SetIndexLabel(3, "DnSignal");
SetIndexDrawBegin(0, li_0);
SetIndexDrawBegin(1, li_0);
SetIndexDrawBegin(2, li_0);
SetIndexDrawBegin(3, li_0);
SetIndexBuffer(0, g_ibuf_96);
SetIndexBuffer(1, g_ibuf_100);
SetIndexBuffer(2, g_ibuf_104);
SetIndexBuffer(3, g_ibuf_108);
SetIndexBuffer(4, g_ibuf_112);
SetIndexBuffer(5, g_ibuf_116);
SetIndexBuffer(6, g_ibuf_120);
return (0);
}
int start() {
string ls_8;
if (Bars <= MA_Period) return (0);
gi_124 = IndicatorCounted();
if (gi_124 < 0) return (-1);
if (gi_124 > 0) gi_124--;
int li_0 = Bars - gi_124;
for (int li_4 = li_0; li_4 >= 0; li_4--) {
g_ibuf_112[li_4] = iMA(NULL, 0, MA_Period, 0, MA_Method, PRICE_HIGH, li_4);
g_ibuf_116[li_4] = iMA(NULL, 0, MA_Period, 0, MA_Method, PRICE_LOW, li_4);
g_ibuf_120[li_4] = g_ibuf_120[li_4 + 1];
if (Close[li_4] > g_ibuf_112[li_4 + 1]) g_ibuf_120[li_4] = 1;
if (Close[li_4] < g_ibuf_116[li_4 + 1]) g_ibuf_120[li_4] = -1;
if (g_ibuf_120[li_4] > 0.0) {
if (g_ibuf_116[li_4] < g_ibuf_116[li_4 + 1]) g_ibuf_116[li_4] = g_ibuf_116[li_4 + 1];
g_ibuf_96[li_4] = g_ibuf_116[li_4];
if (UseSignal > 0) {
if (g_ibuf_120[li_4 + 1] < 0.0) {
g_ibuf_104[li_4] = g_ibuf_116[li_4];
if (WarningMode > 0 && li_4 == 0) PlaySound("alert2.wav");
} else g_ibuf_104[li_4] = EMPTY_VALUE;
}
g_ibuf_100[li_4] = EMPTY_VALUE;
g_ibuf_108[li_4] = EMPTY_VALUE;
} else {
if (g_ibuf_112[li_4] > g_ibuf_112[li_4 + 1]) g_ibuf_112[li_4] = g_ibuf_112[li_4 + 1];
g_ibuf_100[li_4] = g_ibuf_112[li_4];
if (UseSignal > 0) {
if (g_ibuf_120[li_4 + 1] > 0.0) {
g_ibuf_108[li_4] = g_ibuf_112[li_4];
if (WarningMode > 0 && li_4 == 0) PlaySound("alert2.wav");
} else g_ibuf_108[li_4] = EMPTY_VALUE;
}
g_ibuf_96[li_4] = EMPTY_VALUE;
g_ibuf_104[li_4] = EMPTY_VALUE;
}
}
if (g_ibuf_120[2] < 0.0 && g_ibuf_120[1] > 0.0 && Volume[0] > 1.0 && !gi_128) {
ls_8 = " " + Symbol() + " M" + Period() + ": Signal for BUY";
if (AlertMode > 0) Alert(ls_8);
gi_128 = TRUE;
gi_132 = FALSE;
}
if (g_ibuf_120[2] > 0.0 && g_ibuf_120[1] < 0.0 && Volume[0] > 1.0 && !gi_132) {
ls_8 = " " + Symbol() + " M" + Period() + ": Signal for SELL";
if (AlertMode > 0) Alert(ls_8);
gi_132 = TRUE;
gi_128 = FALSE;
}
return (0);
}
Comments