#MTF_dmi~
Download scriptThis tool is designed as a visual momentum indicator for the MetaTrader platform, providing traders with a clear, binary signal of market direction. Instead of showing complex fluctuating lines, it simplifies market data into a distinct "Up" or "Down" visualization, making it easier to identify prevailing trends at a glance.
How It Works
The core logic of this script revolves around analyzing market movement through a specialized calculation called the DMI (Directional Movement Index). The indicator performs the following steps to generate its signals:
- Multi-Timeframe Flexibility: You can choose which specific timeframe you want the tool to analyze (ranging from 1-minute charts up to monthly charts). This allows you to see "the big picture" regardless of which smaller chart you are currently viewing.
- Momentum Comparison: The script looks at two different components of market movement: one that tracks upward pressure and another that tracks downward pressure.
- Smoothing: To ensure the signals aren't jumping around due to minor price "noise," the tool uses a smoothing setting. This helps stabilize the data so that only significant shifts in momentum are captured.
- The Binary Output: The script compares these two pressure components.
- If the upward momentum is stronger than the downward momentum, it registers an "Up" signal (visualized in Blue).
- If the downward momentum is stronger, it registers a "Down" signal (visualized in Red).
User Experience
When you apply this to your chart, it appears in a separate window below your price action. Rather than showing you a number or a messy graph, it provides a clear histogram:
- A full bar indicates the current dominant direction.
- The switch between colors allows you to quickly identify when the trend has flipped from bullish to bearish (or vice versa).
Essentially, this tool acts as a filter, stripping away the complexity of market volatility to provide a simplified "compass" showing which way the momentum is currently flowing.
/*
www.mtcoding.com
*/
#property indicator_separate_window
#property indicator_minimum 0.0
#property indicator_maximum 1.0
#property indicator_buffers 2
#property indicator_color1 DodgerBlue
#property indicator_color2 Red
extern int TimeFrame = 0;
extern string dmi_smooth_str = "DMI Setting";
extern int dmi_smooth = 3;
double g_ibuf_92[];
double g_ibuf_96[];
int init() {
string ls_4;
SetIndexStyle(0, DRAW_HISTOGRAM);
SetIndexStyle(1, DRAW_HISTOGRAM);
SetIndexBuffer(0, g_ibuf_92);
SetIndexBuffer(1, g_ibuf_96);
switch (TimeFrame) {
case 1:
ls_4 = "Period_M1";
break;
case 5:
ls_4 = "Period_M5";
break;
case 15:
ls_4 = "Period_M15";
break;
case 30:
ls_4 = "Period_M30";
break;
case 60:
ls_4 = "Period_H1";
break;
case 240:
ls_4 = "Period_H4";
break;
case 1440:
ls_4 = "Period_D1";
break;
case 10080:
ls_4 = "Period_W1";
break;
case 43200:
ls_4 = "Period_MN1";
break;
default:
ls_4 = "Current Timeframe";
}
SetIndexLabel(0, "Up");
SetIndexLabel(1, "Down");
IndicatorShortName("DMI bar v.j.1 (" + ls_4 + ") -- by SapiMAS --");
return (0);
}
int start() {
int lia_0[];
double l_icustom_20;
double l_icustom_28;
int l_index_12 = 0;
int l_ind_counted_16 = IndicatorCounted();
ArrayCopySeries(lia_0, 5, Symbol(), TimeFrame);
int li_8 = Bars - l_ind_counted_16;
int l_index_4 = 0;
l_index_12 = 0;
while (l_index_4 < li_8) {
if (Time[l_index_4] < lia_0[l_index_12]) l_index_12++;
l_icustom_20 = iCustom(Symbol(), TimeFrame, "dmi", dmi_smooth, 0, 0, 1, 1, 1, 0, l_index_12);
l_icustom_28 = iCustom(Symbol(), TimeFrame, "dmi", dmi_smooth, 0, 0, 1, 1, 1, 1, l_index_12);
if (l_icustom_20 > l_icustom_28) {
g_ibuf_92[l_index_4] = 1;
g_ibuf_96[l_index_4] = 0;
} else {
g_ibuf_92[l_index_4] = 0;
g_ibuf_96[l_index_4] = 1;
}
l_index_4++;
}
return (0);
}
Comments