MTF_AbsoluteStrength_v1.1_DHS
Download scriptThis script is designed as a multi-timeframe market momentum indicator. Its primary purpose is to measure the relative strength between "Bulls" (buyers) and "Bears" (sellers) and provide visual signals on your chart based on how these forces are interacting.
Core Logic Overview
The tool operates by calculating the underlying strength of the market using a variety of mathematical methods (such as RSI or Stochastic oscillators). It then processes this data to show you whether the upward pressure is currently stronger than the downward pressure, or vice versa.
The script provides two main types of visual information:
- The Histogram and Signal Line: These represent the raw "delta" or difference between bullish and bearish strength. A higher histogram typically indicates bullish dominance, while a lower one indicates bearish dominance.
- Dynamic Trading Signals: The script identifies specific market conditions and marks them with distinct colors/shapes to help you quickly interpret the market state.
How the Signals Work
The logic categorizes the market into several distinct states:
- Strong Up (Blue): This appears when bullish strength is significantly higher than bearish strength, and the current momentum is moving in a strong upward trajectory.
- Up Correction (DodgerBlue): This suggests that while the overall trend is still technically "up," there is a slight cooling off or correction occurring within that move.
- Strong Down (Red): This indicates that bearish pressure has taken over and is dominant, with a strong downward trajectory.
- Down Correction (IndianRed): This suggests that while the overall trend is "down," there may be a temporary slight recovery or "bounce" occurring.
- Two Forces On (Gold): This acts as a caution signal. It appears when both bulls and bears are showing significant strength simultaneously, suggesting a state of indecision or a potential reversal point.
- No Trade Zone (White): This identifies periods where neither side has enough momentum to create a clear direction, signaling that there is little interest or opportunity for a trade at that moment.
Multi-Timeframe Capability
One of the key professional features of this script is its "Multi-Timeframe" (MTF) logic. It allows you to look at these strength calculations from a higher timeframe (e.g., looking at Hourly trends while staying on a 5-minute chart). This helps traders stay aligned with the "big picture" trend while making entries on smaller, more precise timeframes.
//+-------------------------------------------------------------------------------+
//| MTF_ASv1.1DHS: Diff_Hist (JercyDevil) +Sig MTF_AbsoluteStrength_v1.1DHS.mq4 |
//| AbsoluteStrength_v1.1 & MTF Copyright © 2006, TrendLaboratory Ltd. |
//| http://finance.groups.yahoo.com/group/TrendLaboratory |
//| www.ForexTSD.com E-mail: igorad2004@list.ru |
//| MTF_ASv1.1DHS: added Signals according to Igorad & Newdigital Rules [cattus]|
//+-------------------------------------------------------------------------------+
#property copyright "Copyright © 2006, TrendLaboratory Ltd."
#property link "http://finance.groups.yahoo.com/group/TrendLaboratory"
#property indicator_separate_window
#property indicator_buffers 8
#property indicator_color1 CadetBlue //Histogram
#property indicator_width1 2
#property indicator_color2 LightSeaGreen //Line
#property indicator_width2 1
#property indicator_style2 0
#property indicator_color3 Blue //Signal StrongUp
#property indicator_width3 1
#property indicator_color4 DodgerBlue //Signal Up
#property indicator_width4 1
#property indicator_color5 Red //Signal StrongDown
#property indicator_width5 1
#property indicator_color6 IndianRed //Signal Down
#property indicator_width6 1
#property indicator_color7 Gold //Two forces strong
#property indicator_width7 1
#property indicator_color8 White //Signal No Interest
#property indicator_width8 1
//---- input parameters
extern int TimeFrame=0;
extern int Mode = 0; // 0-RSI method; 1-Stoch method
extern string note1 = "Mode:RSI-0;Stoch1;ADX2";
extern int Length = 10; // Period
extern int Smooth = 5; // Period of smoothing
extern int Signal = 5; // Period of Signal Line
extern int Price = 0; // Price mode : 0-Close,1-Open,2-High,3-Low,4-Median,5-Typical,6-Weighted
extern int ModeMA = 3; // Mode of Moving Average: SMA0,EMA1,SmdMA2,LWMA3
extern string note2 = "Price(OCHLMTF)ModeMa(SMA0,EMA1,SmmMA2,LWMA3)Levels(OverBought,OverSold)";
extern double OverBought = 0; // OverBought Level
extern double OverSold = 0; // OverSold Level
extern string Signals_Up = "StrongUp,UpCorrection: Blue,DogerBlue";
extern string Signals_Down = "StrongDn,DnCorrection: Red,IndianRed";
extern string Sinal_TwoForcesOn = "Caution,DirChangePosbl:TwoForcesOn; Yellow";
extern string Sinal_NoInterest = "NoTradeZone-NoInterest:Bulls&BearsDown; White";
/*************************************************************************
PERIOD_M1 1
PERIOD_M5 5
PERIOD_M15 15
PERIOD_M30 30
PERIOD_H1 60
PERIOD_H4 240
PERIOD_D1 1440
PERIOD_W1 10080
PERIOD_MN1 43200
You must use the numeric value of the timeframe that you want to use
when you set the TimeFrame' value with the indicator inputs.
---------------------------------------
MODE_SMA 0 Simple moving average,
MODE_EMA 1 Exponential moving average,
MODE_SMMA 2 Smoothed moving average,
MODE_LWMA 3 Linear weighted moving average.
You must use the numeric value of the MA Method that you want to use
when you set the 'ma_method' value with the indicator inputs.
**********************************************************/
//---- buffers
double Bulls[];
double Bears[];
double AvgBulls[];
double AvgBears[];
double SmthBulls[];
double SmthBears[];
double SigBulls[];
double SigBears[];
double SmthBears1[];
double SigBears1[];
double SmthBulls1[];
double SigBulls1[];
double SigStrongUp[];
double SigUpCorrection[];
double SigStrongDown[];
double SigDownCorrection[];
double SigTwoForcesOn[];
double SigNoTrade[];
double delta[];
double deltaSig[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
// IndicatorBuffers(8);
SetIndexBuffer(0,delta);
SetIndexStyle(0,DRAW_HISTOGRAM);
SetIndexBuffer(1,deltaSig);
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(2,SigStrongUp);
SetIndexStyle(2,DRAW_ARROW);
SetIndexArrow(2,159);
SetIndexBuffer(3,SigUpCorrection);
SetIndexStyle(3,DRAW_ARROW);
SetIndexArrow(3,159);
SetIndexBuffer(4,SigStrongDown);
SetIndexStyle(4,DRAW_ARROW);
SetIndexArrow(4,159);
SetIndexBuffer(5,SigDownCorrection);
SetIndexStyle(5,DRAW_ARROW);
SetIndexArrow(5,159);
SetIndexBuffer(6,SigTwoForcesOn);
SetIndexStyle(6,DRAW_ARROW);
SetIndexArrow(6,159);
SetIndexBuffer(7,SigNoTrade);
SetIndexStyle(7,DRAW_ARROW);
SetIndexArrow(7,159);
// SetIndexEmptyValue(4,EMPTY_VALUE);
//---- name for DataWindow and indicator subwindow label
string short_name="MTF_AbsStrDHS["+TimeFrame+"]"+Mode+","+Length+","+Smooth+","+Signal+","+ModeMA+")";
IndicatorShortName(short_name);
SetIndexLabel(0,"Bulls/Bears; tf["+TimeFrame+"]");
SetIndexLabel(1,"Bulls/BearsSigL; tf["+TimeFrame+"]");
SetIndexLabel(2,"StrongUp,tf["+TimeFrame+"]");
SetIndexLabel(3,"UpCorrection,tf["+TimeFrame+"]");
SetIndexLabel(4,"StrongDown["+TimeFrame+"]");
SetIndexLabel(5,"DownCorrection["+TimeFrame+"]");
SetIndexLabel(6,"TwoForcesOn["+TimeFrame+"]");
SetIndexLabel(7,"NoTrade["+TimeFrame+"]");
//----
SetIndexDrawBegin(0,Length+Smooth+Signal);
SetIndexDrawBegin(1,Length+Smooth+Signal);
SetIndexDrawBegin(2,Length+Smooth+Signal);
SetIndexDrawBegin(3,Length+Smooth+Signal);
SetIndexDrawBegin(4,Length+Smooth+Signal);
SetIndexDrawBegin(5,Length+Smooth+Signal);
SetIndexDrawBegin(6,Length+Smooth+Signal);
SetIndexDrawBegin(7,Length+Smooth+Signal);
//---- name for DataWindow and indicator subwindow label
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";
}
return(0);
}
//+------------------------------------------------------------------+
//| MTF |
//+------------------------------------------------------------------+
int start()
{
datetime TimeArray[];
int i,limit,y=0,counted_bars=IndicatorCounted();
// Plot defined time frame on to current time frame
ArrayCopySeries(TimeArray,MODE_TIME,Symbol(),TimeFrame);
limit=Bars-counted_bars+TimeFrame/Period();
for(i=0,y=0;i<limit;i++)
{
if (Time[i]<TimeArray[y]) y++;
/***********************************************************
Add your main indicator loop below. You can reference an existing
indicator with its iName or iCustom.
Rule 1: Add extern inputs above for all neccesary values
Rule 2: Use 'TimeFrame' for the indicator time frame
Rule 3: Use 'y' for your indicator's shift value
**********************************************************/
double SmthBulls1 =iCustom(NULL,TimeFrame,"AbsoluteStrength_v1.1", Mode, Length,Smooth, Signal, Price, ModeMA,0,0,0,y);
double SmthBears1 =iCustom(NULL,TimeFrame,"AbsoluteStrength_v1.1", Mode, Length,Smooth, Signal, Price, ModeMA,0,0,1,y);
double SigBulls1 =iCustom(NULL,TimeFrame,"AbsoluteStrength_v1.1", Mode, Length,Smooth, Signal, Price, ModeMA,0,0,2,y);
double SigBears1 =iCustom(NULL,TimeFrame,"AbsoluteStrength_v1.1", Mode, Length,Smooth, Signal, Price, ModeMA,0,0,3,y);
delta[i]=(SmthBulls1-SmthBears1);
deltaSig[i]=(SigBulls1-SigBears1);
SigStrongUp[i] = EMPTY_VALUE;
SigUpCorrection[i] = EMPTY_VALUE;
SigStrongDown[i] = EMPTY_VALUE;
SigDownCorrection[i] = EMPTY_VALUE;
SigTwoForcesOn[i] = EMPTY_VALUE;
SigNoTrade[i] = EMPTY_VALUE;
if(SmthBulls1>=SmthBears1 && SmthBulls1>=SigBulls1 && SmthBears1<SigBears1) SigStrongUp[i] = 0;//Blue
if(SmthBulls1>=SmthBears1 && SmthBulls1<SigBulls1 && SmthBears1>=SigBears1) SigUpCorrection[i] = 0;//DodgerBlue UpCorrection
if(SmthBulls1<SmthBears1 && SmthBulls1<SigBulls1 && SmthBears1>=SigBears1) SigStrongDown[i] = 0;//Red
if(SmthBulls1<SmthBears1 && SmthBulls1>=SigBulls1 && SmthBears1<SigBears1) SigDownCorrection[i] = 0;//IndianRed DnCorrection
if(SmthBears1>SigBears1 && SmthBulls1>SigBulls1) SigTwoForcesOn[i] = 0;//Gold
if(SmthBulls1<SigBulls1 && SmthBears1<SigBears1) SigNoTrade[i] = 0;//White
}
//
//---- Refresh buffers ++++++++++++++++++++ upgrade by Raff
int TimeFrame; 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];
********************************************************/
SmthBulls[i] = SmthBulls[0];
SmthBears[i] = SmthBears[0];
SigBulls[i] = SigBulls[0];
SigBears[i] = SigBears[0];
SigStrongUp[i] = SigStrongUp[0];
SigUpCorrection[i] = SigUpCorrection[0];
SigStrongDown[i] = SigStrongDown[0];
SigDownCorrection[i] = SigDownCorrection[0];
SigTwoForcesOn[i] = SigTwoForcesOn[0];
SigNoTrade[i]= SigNoTrade[0];
delta[i]= delta[0];
deltaSig[i]=deltaSig[0];
//--
} } }
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Raff
return(0);
}
//+-----------
Comments