PSAR_2B_Line
Download scriptThis custom indicator for MetaTrader 4 is designed to provide traders with a multi-layered perspective on market volatility and trend direction by utilizing the Parabolic Sar (Stop and Reverse) logic across different timeframes simultaneously.
How it Works
The core functionality of this script revolves around identifying "flip" points where price action moves from one direction to another. It accomplishes this by calculating two distinct sets of data:
1. Current Timeframe Analysis The indicator first calculates the standard Parabolic Sar based on your current chart's timeframe. It looks for instances where the calculated value sits below the recent low prices (indicating an upward trend) or above the recent high prices (indicating a downward trend). These are plotted as the primary visual signals for immediate price movement.
2. Higher Timeframe Integration What makes this tool unique is its "smart" multi-timeframe logic. The script automatically identifies the next logical higher timeframe based on what you are currently viewing (for example, if you are on a 5-minute chart, it looks at the 15-minute data; if you are on a 1-hour chart, it shifts to the 4-hour data). It then calculates a second Parabolic Sar for that larger timeframe and projects it onto your current screen.
Visual Representation
The indicator populates four distinct visual lines on your chart:
- Primary Trend Signals: These represent the immediate momentum of the current timeframe. They help you see quick shifts in price action.
- Secondary Contextual Signals: These represent the trend of the larger timeframe. By viewing these alongside the primary signals, you can identify whether a short-term move is aligned with the broader market direction.
Practical Application
By combining these two layers of data, the script allows you to see "the big picture" without having to switch back and forth between different charts manually. It highlights where the immediate price action is interacting with the heavier momentum of the higher timeframe, providing a clearer visual map of support and resistance dynamics.
/*------------------------------------------------------------------+
| PSAR_2B_Line.mq4 |
| Copyright © 2011 |
| basisforex@gmail.com |
+------------------------------------------------------------------*/
#property copyright "Copyright © 2011, basisforex@gmail.com"
#property link "basisforex@gmail.com"
//-----
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 White
#property indicator_color2 Yellow
#property indicator_color3 Aqua
#property indicator_color4 Orange
//-----
extern int VisualBars = 500;
//-----
extern double Step = 0.02;
extern double Maximum = 0.2;
//-----
double s0[];
double s1[];
double s2[];
double s3[];
//-----
double s01[];
double s23[];
//+------------------------------------------------------------------+
int init()
{
IndicatorBuffers(6);
SetIndexBuffer(0, s0);
SetIndexBuffer(1, s1);
SetIndexBuffer(2, s2);
SetIndexBuffer(3, s3);
//-----
SetIndexBuffer(4, s01);
SetIndexBuffer(5, s23);
//-----
SetIndexStyle(0, DRAW_LINE, EMPTY, 3);
SetIndexStyle(1, DRAW_LINE, EMPTY, 3);
SetIndexStyle(2, DRAW_LINE, EMPTY, 3);
SetIndexStyle(3, DRAW_LINE, EMPTY, 3);
//------
return(0);
}
//+------------------------------------------------------------------+
string GetNextTF(int curTF)
{
switch(curTF)
{
case 1:
return("5");
break;
case 5:
return("15=");
break;
case 15:
return("30=");
break;
case 30:
return("60=");
break;
case 60:
return("240=");
break;
case 240:
return("1440=");
break;
}
}
//+------------------------------------------------------------------+
int start()
{
int limit;
int counted_bars = IndicatorCounted();
if(counted_bars < 0) return(-1);
if(counted_bars > 0) counted_bars--;
limit = VisualBars;
//-----
string T = GetNextTF(Period());
int tf1 = StrToDouble(StringSubstr(T, 0, StringFind(T, "=", 0)));
//-----
for(int i = limit - 1; i >= 0; i--)
{
s01[i] = iSAR(NULL, 0, Step, Maximum, i);
s23[i] = iSAR(NULL, tf1, Step, Maximum, i / (tf1 / Period()));
if(s01[i] < iLow(NULL, 0, i)) s0[i] = s01[i];
if(s01[i] > iHigh(NULL, 0, i)) s1[i] = s01[i];
if(s23[i] < iLow(NULL, 0, i)) s2[i] = s23[i];
if(s23[i] > iHigh(NULL, 0, i)) s3[i] = s23[i];
}
return(0);
}
Comments