SAR_ADX_sBar_mtf
Download scriptThis technical script is designed to serve as a multi-layered visual aid for Forex and commodity traders. It combines two primary market analysis tools—the Parabolic Stop and Reverse (SAR) and the Average Directional Index (ADX)—into a single, consolidated display window. Its primary purpose is to identify trend direction, momentum strength, and potential price reversals by analyzing data from various timeframes simultaneously.
Core Logic Overview
The script functions by scanning historical and real-time price data to calculate specific market conditions. Instead of looking at just the current chart timeframe, it can pull data from higher timeframes (such as Daily or Weekly) and project that information onto your current view. This allows traders to see "the big picture" without constantly switching between different charts.
Key Analytical Components
1. Trend Direction (SAR Logic) The script monitors the Parabolic Stop and Reverse (SAR) values. It identifies whether the current price action is trending upwards or downwards:
- Bullish Signal: When the price moves above the SAR value, the indicator marks a potential upward trend.
- Bearish Signal: When the price falls below the SAR value, it signals a downward trend. The script visualizes these states using distinct colors and markers, helping the user immediately recognize the prevailing direction of the market.
2. Momentum Strength (ADX Logic) To complement the trend direction, the script incorporates the Average Directional Index (ADX). This is used to measure how "strong" a trend actually is:
- Trend Intensity: It checks if the ADX value is above or below a specific threshold. If the momentum is too weak, it helps the trader avoid entering a "choppy" or sideways market.
- Directional Flow: It compares previous and current momentum values (Positive and Negative ADX) to determine which side of the market has more aggressive pressure.
3. Multi-Timeframe Synchronization A significant feature of this logic is its ability to handle "TimeFrame Scaling." If you are looking at a small timeframe (like a 1-minute chart), the script can automatically calculate and display data from much larger periods (like the 4-hour or Daily charts). It ensures that these higher-level trends remain visible and synchronized with your current view, providing a continuous stream of context for your trading decisions.
Visual Presentation
The logic is designed to be highly readable. Rather than cluttering the main price chart, it outputs its findings into a separate window. It uses a variety of visual styles—including lines, dots, and arrows—to represent different types of data (Upward trends, Downward trends, and Momentum levels), allowing for a clean, professional dashboard that summarizes complex calculations into simple visual cues.
//+------------------------------------------------------------------+
//| SAR_ADX SideBar ForexTSD.com ki based on SAR Color Bar.mq4|
//+------------------------------------------------------------------+
#property copyright "Kalenzo Code adapted by cja"
#property link "http://www.foreksik.prv.pl"
#property indicator_color1 Red
#property indicator_color2 Green
#property indicator_color3 Yellow
#property indicator_color4 Lime
#property indicator_color5 Orchid
#property indicator_width1 3
#property indicator_width2 3
#property indicator_width3 3
#property indicator_width4 4
#property indicator_width5 4
#property indicator_separate_window
#property indicator_buffers 5
#property indicator_maximum 77
#property indicator_minimum 1
double PADX_buff[],NADX_buff[],ADX_buff[],sarUp[],sarDn[];//buffers
extern int TimeFrame = 0;
extern double SAR_Step = 0.013;
extern double SAR_Maximum = 0.2;
extern int SAR_Precision = 5;
extern int ADX_Period = 14;
extern int ADX_Level = 20;
extern int sBarLevel = 5;
extern bool _ADXstyleLine = false;
extern bool pADXstyleLine = false;
extern bool nADXstyleLine = true;
//extern bool History = 500;
extern string note_sBarLevel = "sBarLevel:1-77(bar position)";
extern string note_SAR_Precision = "digits after decimal point(0-8)";
extern string note_ADXstyle = " ADXstyle: Line/Dot";
extern string note_TimeFrames = "M1;5,15,30,60H1;240H4;1440D1;10080W1;43200MN";
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexBuffer(0,sarUp);
SetIndexStyle (0,DRAW_ARROW);
SetIndexArrow (0,167);//110
SetIndexBuffer(1,sarDn);
SetIndexStyle (1,DRAW_ARROW);
SetIndexArrow (1,167);
if (_ADXstyleLine) SetIndexStyle(2,DRAW_LINE);
else {SetIndexStyle (2,DRAW_ARROW);
SetIndexArrow (2,158);}
SetIndexBuffer(2,ADX_buff);
if (pADXstyleLine) SetIndexStyle(3,DRAW_LINE);
else { SetIndexStyle (3,DRAW_ARROW);
SetIndexArrow (3,158);}
SetIndexBuffer(3,PADX_buff);
if (nADXstyleLine) SetIndexStyle(4,DRAW_LINE);
else {SetIndexStyle (4,DRAW_ARROW);
SetIndexArrow (4,158);}
SetIndexBuffer(4,NADX_buff);
switch(TimeFrame)
{
case 1 : string TimeFrameStr="Period_M1"; break;
case 5 : TimeFrameStr="Period_M5"; break;
case 15 : TimeFrameStr="Period_M15"; break;
case 30 : TimeFrameStr="Period_M30"; break;
case 60 : TimeFrameStr="Period_H1"; break;
case 240 : TimeFrameStr="Period_H4"; break;
case 1440 : TimeFrameStr="Period_D1"; break;
case 10080 : TimeFrameStr="Period_W1"; break;
case 43200 : TimeFrameStr="Period_MN1"; break;
default : TimeFrameStr="Current Timeframe";
}
IndicatorShortName("SAR("+SAR_Step+","+SAR_Maximum+")_ADX("+ADX_Period+")_sBar["+TimeFrameStr+"]");
SetIndexLabel(0,"SAR ["+TimeFrame+"] Down");
SetIndexLabel(1,"SAR ["+TimeFrame+"] Up");
SetIndexLabel(2,"ADX ["+TimeFrame+"] Level < "+ADX_Level+"");
SetIndexLabel(3,"ADX ["+TimeFrame+"]Up");
SetIndexLabel(4,"ADX ["+TimeFrame+"]Down");
SetIndexDrawBegin(0,2);
SetIndexDrawBegin(1,2);
SetIndexDrawBegin(2,2);
SetIndexDrawBegin(3,2);
SetIndexDrawBegin(4,2);
if(TimeFrame <Period()) TimeFrame = Period();
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int i,y=0,limit;
datetime TimeArray[];
ArrayCopySeries(TimeArray,MODE_TIME,Symbol(),TimeFrame);
int counted_bars=IndicatorCounted();
if(counted_bars<0) counted_bars=0;
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars+TimeFrame/Period();
//----
for(i =0, y=0; i<limit; i++)
{
if (Time[i]<TimeArray[y]) y++;
double sar = NormalizeDouble(iSAR(Symbol(),TimeFrame,SAR_Step,SAR_Maximum,y),SAR_Precision);
double ADX=iADX(NULL,TimeFrame,ADX_Period,0,0,y);
double PADX=iADX(NULL,TimeFrame,ADX_Period,0,1,y);
double NADX=iADX(NULL,TimeFrame,ADX_Period,0,2,y);
if(sar >= iHigh(Symbol(),0,i))
{
sarUp[i] = sBarLevel;
sarDn[i] = EMPTY_VALUE;
}
else
{
sarUp[i] = EMPTY_VALUE;
sarDn[i] = sBarLevel;
}
if(ADX < ADX_Level) ADX_buff[i]=sBarLevel+2;
if(PADX > NADX) PADX_buff[i]=sBarLevel-2;
if(PADX < NADX) NADX_buff[i]=sBarLevel-2;
}
// Refresh buffers
//++++++++++++++++++++++++++++++++++++++ upgrade by Raff
if (TimeFrame>Period()) {
int PerINT=TimeFrame/Period()+1;
datetime TimeArr[]; ArrayResize(TimeArr,PerINT);
ArrayCopySeries(TimeArr,MODE_TIME,Symbol(),Period());
for(i=0;i<PerINT+1;i++) {if (TimeArr[i]>=TimeArray[0]) {
//----
/********************************************************
Refresh buffers: buffer[i] = buffer[0];
********************************************************/
sarUp[i]=sarUp[0];
sarDn[i]=sarDn[0];
ADX_buff [i]=ADX_buff[0];
PADX_buff[i]=ADX_buff[0];
NADX_buff[i]=ADX_buff[0];
//----
} } }
//+++++++++++++++++++++++++++++++++++++++++++++++ Raff
//----
return(0);
}
//+------------------------------------------------------------------+//+------------------------------------------------------------------+
Comments