SlopeDirection_MTF_v1
Download scriptThis tool is designed to help traders visualize the broader market trend by identifying and displaying the direction of price "slopes" across different timeframes. Rather than just looking at what price is doing right now on your current screen, it pulls data from larger charts to provide a clearer picture of where the market is heading.
Core Functionality
The primary purpose of this script is Multi-Timeframe (MTF) analysis. It allows you to see information from higher timeframes (like a Daily or 4-hour chart) directly on your current smaller timeframe (like a 15-minute or 1-hour chart). This helps traders stay aligned with the "big picture" while executing trades on smaller price movements.
How it Works
The logic follows a three-step process to determine what information to show you:
- Trend Identification: The script looks at historical price data based on specific settings (period, smoothing method, and price type). It calculates two distinct paths: an upward trend line and a downward trend line.
- Timeframe Synchronization: When you choose a higher timeframe, the script automatically "matches" the current time on your chart to the corresponding data point on the larger timeframe. This ensures that the trend line stays synchronized with the actual market history.
- Visual Output: The script translates these calculations into two distinct lines on your screen:
- Lime Green: Represents the upward slope/trend.
- Red: Represents the downward slope/trend.
Key Benefits for Traders
- Contextual Awareness: It prevents "trading against the grain" by showing you if a small price move is just noise or part of a larger, dominant trend.
- Simplified Navigation: Instead of constantly switching back and forth between different windows to check higher timeframe trends, this script overlays that information onto your primary workspace.
- Customizable Accuracy: You can adjust the sensitivity (period) and the calculation method to suit different trading styles—whether you prefer a fast-reacting indicator or one that filters out minor price fluctuations for a smoother view.
//+------------------------------------------------------------------+
//| SlopeDirection_MTF.mq4 |
//| Copyright © 2007, ASystem Group |
//| asystem2000@rambler.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, Asystem2000"
#property link "asystem2000@rambler.ru"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 LimeGreen
#property indicator_color2 Red
//---- input parameters
extern int TimeFrame=0;
extern int period=80;
extern int method=3; // MODE_SMA
extern int price=0; // PRICE_CLOSE
extern string Note="Ìîæåòå ïîìåíÿòü èìÿ èíèäèêàòîðà, åñëè íå ñîâïàäàåò";
extern string Indicator="Slope Direction Line";
//---- buffers
double B_Up[];
double B_Dn[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
if (TimeFrame!=0)
{
if (TimeFrame<Period())
{
Alert("Íàñòðàèâàåìûé òàéìôðåéì äîëæåí áûòü áîëüøå òåêóùåãî èëè ðàâåí 0");
deinit();
return(0);
}
}
bool OK_Period=false;
switch (TimeFrame)
{
case 0:OK_Period=true;break;
case 1:OK_Period=true;break;
case 5:OK_Period=true;break;
case 15:OK_Period=true;break;
case 30:OK_Period=true;break;
case 60:OK_Period=true;break;
case 240:OK_Period=true;break;
case 1440:OK_Period=true;break;
case 10080:OK_Period=true;break;
case 43200:OK_Period=true;break;
}
if (OK_Period==false)
{
Alert("Âû ââåëè íåêîððåêòíóþ öèôðó òàéìôðåéìà");
deinit();
return(0);
}
//---- indicators
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2);
SetIndexBuffer(0,B_Up);
SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,2);
SetIndexBuffer(1,B_Dn);
IndicatorShortName("Slope Direction Line - MTF ("+period+")");
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
int limit;
if (TimeFrame>0) limit=Bars-counted_bars-(TimeFrame/Period());
else limit=Bars-counted_bars-1;
int C_time;
int Bar_Shift;
if (limit==0) return(0);
//----
int i=limit;
while(i>=0)
{
C_time=Time[i];
Bar_Shift=iBarShift(NULL,TimeFrame,C_time,false);
B_Up[i]=iCustom(NULL,TimeFrame,Indicator,period,method,price,0,Bar_Shift);
B_Dn[i]=iCustom(NULL,TimeFrame,Indicator,period,method,price,1,Bar_Shift);
i--;
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments