Stochastic_Filter_mtf

Download script
Author: Copyright � 2006, Indoforex Groups
Stochastic_Filter_mtf

This tool is designed as a multi-timeframe technical indicator that analyzes price momentum to help traders identify market trends and potential reversal zones. By utilizing the Stochastic Oscillator logic, it filters out market "noise" to provide a clearer picture of whether the current price action is overextended or moving with strength in a specific direction.

Core Logic and Functionality

1. Multi-Timeframe Analysis One of the primary features of this script is its ability to look at higher timeframes while you are viewing a lower one. It allows the user to calculate momentum based on larger periods (like daily or weekly) and project that data onto the current chart. This helps in ensuring that a trade aligns with the "big picture" of the market rather than just short-term fluctuations.

2. Momentum Filtering (Overbought vs. Oversold) The tool monitors two main components of the Stochastic Oscillator: the main line (representing current momentum) and the signal line (a smoothed average). It evaluates these based on pre-set intensity levels:

  • Strong Bullish/Overbought: When the momentum exceeds a high threshold, it signals strong upward pressure or an overextended bullish state.
  • Strong Bearish/Oversold: When the momentum falls below a low threshold, it signals strong downward pressure or an overextended bearish state.

3. Trend and Potential Detection The script categorizes the market into four distinct states based on the relationship between the two momentum lines:

  • Strong Bullish: Indicates the market is showing significant upward strength.
  • Strong Bearish: Indicates the market is showing significant downward strength.
  • Potential Bullish (Upside Momentum): Occurs when the price is not yet overbought but the momentum line is crossing above the signal line, suggesting a potential move toward the upside.
  • Potential Bearish (Downside Momentum): Occurs when the price is not yet oversold but the momentum line is crossing below the signal line, suggesting a potential move toward the downside.

4. Visual Representation The logic translates these mathematical calculations into four distinct visual bars or histograms on your chart:

  • Blue/Steel Blue: Represent bullish conditions (Strength or Potential Upside).
  • Red/Orange: Represent bearish conditions (Strength or Potential Downside).

Summary for the User

Essentially, this script acts as a "filter" for your trading decisions. Instead of just seeing raw price movement, it tells you if the current momentum is consistent with a larger trend. It highlights when the market is "exhausted" (overbought/oversold) versus when it is beginning to build momentum in a specific direction, helping you stay on the right side of the market flow across different timeframes simultaneously.

Indicators Used
Stochastic oscillator
Miscellaneous
Implements a curve of type %1
12 Views
0 Downloads
0 Favorites
Stochastic_Filter_mtf
//+------------------------------------------------------------------+
//|Stochastic_Filter_mtf                         Filter over WPR.mq4 |
//|                   Copyright © 2006, Indoforex Groups - Primajaya |
//| MTF:ForexTSD.com   ki             http://primaforex.blogspot.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, Indoforex Groups"
#property link      "http://primaforex.blogspot.com"

#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 1
#property indicator_buffers 4

#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_color3 SteelBlue
#property indicator_color4 Orange

#property indicator_width1  2   
#property indicator_width2  2
#property indicator_width3  2
#property indicator_width4  2

//---- input parameters
extern int TimeFrame=0;

extern int    KPeriod        = 14;
extern int    DPeriod        = 5;
extern int    Smooth         = 3;

extern int MAMethod=0;
extern int PriceField=0;// PriceField:  0=Hi/Low   1=Close/Close

extern double OverboughtLevel     = 76.4;// 61.80;
extern double OversoldLevel       = 23.6;// 38.20;

extern bool   use_pK_Only         = false;
extern int    MaxBarsToCount      = 1500;

extern string __MA_Method = "SMA0 EMA1 SMMA2 LWMA3";
extern string __PriceField = "0=Hi/Low   1=Close/Close";

extern string _TimeFrames = "M1;5,15,30,60H1;240H4;1440D1;10080W1;43200MN|0-CurrentTF";

//---- indicator buffers

double UpBuffer1[];
double UpBuffer2[];
double DnBuffer1[];
double DnBuffer2[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
  int init()
  {
   string short_name;
//---- indicator line
   SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexStyle(1,DRAW_HISTOGRAM);
   SetIndexStyle(2,DRAW_HISTOGRAM);
   SetIndexStyle(3,DRAW_HISTOGRAM);
   
   SetIndexBuffer(0,UpBuffer1);
   SetIndexBuffer(1,UpBuffer2);
   SetIndexBuffer(2,DnBuffer1);
   SetIndexBuffer(3,DnBuffer2);
 
   if (TimeFrame < Period()) TimeFrame = Period();
   
    //---- 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";
    }
//---- name for DataWindow and indicator subwindow label
   short_name="Stoch_Filter("+KPeriod+","+DPeriod+","+Smooth+") "+TimeFrameStr;
   IndicatorShortName(short_name);


   SetIndexLabel(0,"Overbought or Strong Bulls");
   SetIndexLabel(1,"Oversold or Strong Bears");
   SetIndexLabel(2,"Potential to Bulls");
   SetIndexLabel(3,"Potential to Bears");

   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));


   return(0);
  }

//+------------------------------------------------------------------+
//| ProSol Confirmation                                              |
//+------------------------------------------------------------------+

int start()
  {
   int trend;
   double PK;
   double PD;
   
   datetime TimeArray[];
   int    shift,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;
limit=MathMax(limit,TimeFrame/Period());
limit=MathMin(limit,MaxBarsToCount);
   
   for(shift=0,y=0;shift<limit;shift++)
   {
   if (Time[shift]<TimeArray[y]) y++;
   
   PK = iStochastic(NULL,TimeFrame,KPeriod,DPeriod,Smooth,MAMethod,PriceField,0,y);
   PD = iStochastic(NULL,TimeFrame,KPeriod,DPeriod,Smooth,MAMethod,PriceField,1,y);

 if (use_pK_Only)
     {
  if (PK>=OverboughtLevel)  trend=1;   
  if (PK<=OversoldLevel)    trend=2;	  
  if (PK<OverboughtLevel && PK>PD &&PK>OversoldLevel ) trend=3;
  if (PK<OverboughtLevel && PK<PD && PK>OversoldLevel) trend=4;
     }
 
 else
     
  if (PD>=OverboughtLevel)   trend=1;   
  if (PD<=OversoldLevel)     trend=2;	  
  if (PD<OverboughtLevel && PK>PD && PD>OversoldLevel) trend=3;
  if (PD<OverboughtLevel && PK<PD && PD>OversoldLevel) trend=4;
     
	  
	  if (trend==1) 
	  {
	  
	  UpBuffer1[shift]=1;
	  UpBuffer2[shift]=0;
	  DnBuffer1[shift]=0;
	  DnBuffer2[shift]=0;
	  
	  }
	  if (trend==2) 
	  {
	  
	  UpBuffer1[shift]=0;
	  UpBuffer2[shift]=1;
	  DnBuffer1[shift]=0;
	  DnBuffer2[shift]=0;
	  
	  }
	  if (trend==3) 
	  {
	   
	  UpBuffer1[shift]=0;
	  UpBuffer2[shift]=0;
	  DnBuffer1[shift]=1;
	  DnBuffer2[shift]=0;
	  }
	  
	  if (trend==4) 
	  {
	  
	  UpBuffer1[shift]=0;
	  UpBuffer2[shift]=0;
	  DnBuffer1[shift]=0;
	  DnBuffer2[shift]=1; 
	  
	  }
	}
//----  
     int TimeFrame;   if (TimeFrame>Period()) {
     int PerINT=TimeFrame/Period()+1;
     datetime TimeArr[]; ArrayResize(TimeArr,PerINT);
     ArrayCopySeries(TimeArr,MODE_TIME,Symbol(),Period()); 
     for(shift=0;shift<PerINT+1;shift++) {if (TimeArr[shift]>=TimeArray[0]) {

	  UpBuffer1[shift]=UpBuffer1[0];
	  UpBuffer2[shift]=UpBuffer2[0];
	  DnBuffer1[shift]=DnBuffer1[0];
	  DnBuffer2[shift]=DnBuffer2[0]; 
 
     } }
  }
	return(0);	
 }

Comments