FDM Hours Channel
Download scriptThis script is designed as a visual technical analysis tool for the MetaTrader trading platform. Its primary purpose is to calculate and display trend-based projection lines on a price chart based on historical data.
Core Functionality
The script operates by analyzing a specific historical window of market data (defined by the "Hours" setting) to determine the direction and momentum of the price action. It then projects this information forward onto the current chart to help traders visualize potential price targets or trend continuations.
How the Logic Works
1. Time and Data Validation The script first checks the current system time against a hardcoded expiration date. If the current date is past this limit, the script will trigger an alert and cease to function until authorized. It then calculates how many price bars correspond to the user-defined hourly window based on the current chart timeframe.
2. Trend Analysis (Linear Regression) The tool performs a mathematical calculation known as linear regression. It looks at the closing prices over the designated period to calculate a "line of best fit." This identifies the general slope of the market—determining whether the overall momentum is bullish, bearish, or neutral.
3. Pivot Point Identification Once the general trend is established, the script divides the historical window into two halves (the past and the most recent data). It searches for significant "peaks" (highest highs) and "valleys" (lowest lows) within these sections.
4. Projection Calculation Based on which peak or valley is more prominent relative to the calculated trend, the script chooses a specific geometry to project forward. It calculates three distinct price levels at the current time:
- Primary Level: The direct continuation of the established trend line.
- Median Level: A midpoint between the trend continuation and the historical volatility (the distance between the highs and lows).
- Extreme Level: The maximum projection based on the full extent of recent price fluctuations.
5. Visual Output Finally, the script draws three trend lines on your chart:
- A solid line representing the primary trend projection.
- A dotted line representing the median target.
- A third solid line representing the extreme potential reach.
All lines are drawn in the user-selected color and originate from the start of the calculated historical window, extending to the current price candle.
/*
*/
#property copyright "Copyright © 2008, Forex Day Monster "
#property link "http://www.forexprofitmonster.com/"
#property indicator_chart_window
extern int Hours = 1080;
extern color col = LimeGreen;
double gd_84;
double gd_unused_92;
double gd_100;
double gd_108;
double gd_116;
double gd_124;
double gd_132;
double gd_140;
double gd_148;
int gi_156;
int gi_160;
int gi_168;
int gi_unused_176;
double gd_180;
double gd_188;
double gd_196;
double gd_204;
double gd_212;
double gd_220;
int gi_232;
int gi_236;
int gi_240;
int gi_244;
double gd_248;
double gd_256;
double gd_264;
double gd_272;
double gd_280;
double gd_288;
double gd_296;
double gd_304;
double gd_312;
double gd_320;
double g_price_328;
double g_price_336;
double g_price_344;
double g_price_352;
double g_price_360;
double g_price_368;
int g_shift_376;
int g_shift_380;
int g_shift_384;
bool gi_388;
void ObjDel() {
ObjectDelete("1" + gi_160);
ObjectDelete("0" + gi_160);
ObjectDelete("2" + gi_160);
}
int init() {
return (0);
}
int deinit() {
ObjDel();
Comment("");
return (0);
}
int start() {
string ls_0 = "2015.11.01";
int l_str2time_8 = StrToTime(ls_0);
if (TimeCurrent() >= l_str2time_8) {
Alert(" Trial version has expired! Email support@forexprofitmonster.com with broker account number for rights to full version!");
return (0);
}
gi_156 = 60 * Hours / Period();
gi_160 = Hours;
if (gi_168 == 1) {
g_shift_376 = iBarShift(Symbol(), Period(), ObjectGet("1" + gi_160, OBJPROP_TIME1));
g_shift_380 = iBarShift(Symbol(), Period(), ObjectGet("0" + gi_160, OBJPROP_TIME1));
g_shift_384 = iBarShift(Symbol(), Period(), ObjectGet("2" + gi_160, OBJPROP_TIME1));
if (gi_388 == FALSE && gi_156 != g_shift_376) {
gi_156 = g_shift_376;
gi_388 = TRUE;
}
if (gi_388 == FALSE && gi_156 != g_shift_380) {
gi_156 = g_shift_380;
gi_388 = TRUE;
}
if (gi_388 == FALSE && gi_156 != g_shift_384) {
gi_156 = g_shift_384;
gi_388 = TRUE;
}
}
gd_108 = 0;
gd_116 = 0;
gd_124 = 0;
gd_132 = 0;
for (int li_16 = 0; li_16 <= gi_156; li_16++) {
gd_108 += li_16;
gd_116 += Close[li_16];
gd_124 += li_16 * Close[li_16];
gd_132 += MathPow(li_16, 2);
}
gd_140 = (gd_108 * gd_116 - (gi_156 + 1) * gd_124) / (MathPow(gd_108, 2) - (gi_156 + 1) * gd_132);
gd_148 = (gd_116 - gd_140 * gd_108) / (gi_156 + 1);
for (int l_index_12 = 0; l_index_12 <= gi_156; l_index_12++) {
gd_84 = gd_148 + gd_140 * l_index_12;
gd_180 = High[l_index_12] - gd_84;
gd_188 = Low[l_index_12] - gd_84;
if (l_index_12 < gi_156 / 2) {
if (l_index_12 == 0) {
gd_196 = 0.0;
gd_204 = 0.0;
gi_232 = l_index_12;
gi_240 = l_index_12;
}
if (gd_180 >= gd_196) {
gd_196 = gd_180;
gi_232 = l_index_12;
}
if (gd_188 <= gd_204) {
gd_204 = gd_188;
gi_240 = l_index_12;
}
}
if (l_index_12 >= gi_156 / 2) {
if (l_index_12 == gi_156 / 2) {
gd_212 = 0.0;
gd_220 = 0.0;
gi_236 = l_index_12;
gi_244 = l_index_12;
}
if (gd_180 >= gd_212) {
gd_212 = gd_180;
gi_236 = l_index_12;
}
if (gd_188 <= gd_220) {
gd_220 = gd_188;
gi_244 = l_index_12;
}
}
}
gd_unused_92 = gd_148;
gd_100 = gd_148 + gd_140 * (l_index_12 + gi_156);
if (MathAbs(gi_232 - gi_236) > MathAbs(gi_240 - gi_244)) gi_168 = 1;
if (MathAbs(gi_232 - gi_236) < MathAbs(gi_240 - gi_244)) gi_168 = 2;
if (MathAbs(gi_232 - gi_236) == MathAbs(gi_240 - gi_244)) {
if (MathAbs(gd_196 - gd_212) < MathAbs(gd_204 - gd_220)) gi_168 = 1;
if (MathAbs(gd_196 - gd_212) >= MathAbs(gd_204 - gd_220)) gi_168 = 2;
}
if (gi_168 == 1) {
for (li_16 = 0; li_16 <= 20; li_16++) {
gi_unused_176 = 0;
for (l_index_12 = 0; l_index_12 <= gi_156; l_index_12++) {
gd_248 = High[gi_232] * (l_index_12 - gi_236) / (gi_232 - gi_236) + High[gi_236] * (l_index_12 - gi_232) / (gi_236 - gi_232);
if (l_index_12 == 0 || l_index_12 == gi_156 / 2) gd_280 = 0.0;
if (High[l_index_12] - gd_248 > gd_280 && l_index_12 < gi_156 / 2) {
gi_232 = l_index_12;
gi_unused_176 = 1;
}
if (High[l_index_12] - gd_248 > gd_280 && l_index_12 >= gi_156 / 2) {
gi_236 = l_index_12;
gi_unused_176 = 1;
}
}
if (gi_168 == 0) break;
}
for (l_index_12 = 0; l_index_12 <= gi_156; l_index_12++) {
gd_248 = High[gi_232] * (l_index_12 - gi_236) / (gi_232 - gi_236) + High[gi_236] * (l_index_12 - gi_232) / (gi_236 - gi_232);
gd_272 = Low[l_index_12] - gd_248;
if (l_index_12 == 0) gd_288 = 0.0;
if (gd_272 < gd_288) gd_288 = gd_272;
}
gd_296 = High[gi_232] * (0 - gi_236) / (gi_232 - gi_236) + High[gi_236] * (0 - gi_232) / (gi_236 - gi_232);
gd_304 = High[gi_232] * (gi_156 - gi_236) / (gi_232 - gi_236) + High[gi_236] * (gi_156 - gi_232) / (gi_236 - gi_232);
g_price_328 = gd_304;
g_price_336 = gd_304 + gd_288 / 2.0;
g_price_344 = gd_304 + gd_288;
g_price_352 = gd_296;
g_price_360 = gd_296 + gd_288 / 2.0;
g_price_368 = gd_296 + gd_288;
}
if (gi_168 == 2) {
for (li_16 = 0; li_16 <= 20; li_16++) {
gi_unused_176 = 0;
for (l_index_12 = 0; l_index_12 <= gi_156; l_index_12++) {
gd_256 = Low[gi_240] * (l_index_12 - gi_244) / (gi_240 - gi_244) + Low[gi_244] * (l_index_12 - gi_240) / (gi_244 - gi_240);
if (l_index_12 == 0 || l_index_12 == gi_156 / 2) gd_288 = 0.0;
if (Low[l_index_12] - gd_256 < gd_288 && l_index_12 < gi_156 / 2) {
gi_240 = l_index_12;
gi_unused_176 = 1;
}
if (Low[l_index_12] - gd_256 < gd_288 && l_index_12 >= gi_156 / 2) {
gi_244 = l_index_12;
gi_unused_176 = 1;
}
}
if (gi_168 == 0) break;
}
for (l_index_12 = 0; l_index_12 <= gi_156; l_index_12++) {
gd_256 = Low[gi_240] * (l_index_12 - gi_244) / (gi_240 - gi_244) + Low[gi_244] * (l_index_12 - gi_240) / (gi_244 - gi_240);
gd_264 = High[l_index_12] - gd_256;
if (l_index_12 == 0) gd_280 = 0.0;
if (gd_264 > gd_280) gd_280 = gd_264;
}
gd_312 = Low[gi_240] * (0 - gi_244) / (gi_240 - gi_244) + Low[gi_244] * (0 - gi_240) / (gi_244 - gi_240);
gd_320 = Low[gi_240] * (gi_156 - gi_244) / (gi_240 - gi_244) + Low[gi_244] * (gi_156 - gi_240) / (gi_244 - gi_240);
g_price_328 = gd_320;
g_price_336 = gd_320 + gd_280 / 2.0;
g_price_344 = gd_320 + gd_280;
g_price_352 = gd_312;
g_price_360 = gd_312 + gd_280 / 2.0;
g_price_368 = gd_312 + gd_280;
}
ObjectCreate("1" + gi_160, OBJ_TREND, 0, Time[gi_156], g_price_328, Time[0], g_price_352);
ObjectCreate("0" + gi_160, OBJ_TREND, 0, Time[gi_156], g_price_336, Time[0], g_price_360);
ObjectCreate("2" + gi_160, OBJ_TREND, 0, Time[gi_156], g_price_344, Time[0], g_price_368);
ObjectSet("1" + gi_160, OBJPROP_COLOR, col);
ObjectSet("0" + gi_160, OBJPROP_COLOR, col);
ObjectSet("0" + gi_160, OBJPROP_STYLE, STYLE_DOT);
ObjectSet("2" + gi_160, OBJPROP_COLOR, col);
return (0);
}
Comments