This tool is designed to provide traders with a sophisticated view of market momentum by analyzing the Stochastic Oscillator across different timeframes simultaneously. Instead of looking at just the immediate price action, this script helps identify broader trends and hidden price patterns that might not be visible on a single chart.
How the Logic Works
1. Multi-Timeframe Perspective The core strength of this script is its ability to "look ahead" into larger timeframes. While you may be trading on a small, fast-moving chart (like 1 minute or 5 minutes), the tool automatically calculates and displays data from a larger timeframe (such as 1 hour, 4 hours, or Daily charts). This allows you to see if the overall market direction supports your current trade.
2. Dynamic Timeframe Scaling The script includes an intelligent "nesting" logic. It ensures that the timeframe being analyzed is always equal to or larger than the one you are currently viewing. For example, if you choose a timeframe that doesn't exist in the standard settings, the script will automatically round it up to the next logical interval (e.g., 15 minutes, 1 hour, Day, Weekly, or Monthly).
3. Dual-Layer Data Processing The tool performs two distinct types of calculations to smooth out market "noise":
- Primary Stochastic Calculation: It first fetches the standard Stochastic data from the higher timeframe. This tells you the relative position of the current price compared to its recent past.
- Secondary Smoothing: The script then applies a moving average to that high-level data. This creates a secondary, even smoother line. By doing this, the indicator filters out minor price fluctuations, helping you focus on significant momentum shifts rather than every small tick of price movement.
4. Visual Representation The result is displayed as two distinct lines in a separate window at the bottom of your trading platform:
- One line represents the high-timeframe Stochastic value.
- The second line provides a smoothed version of that same data.
Summary for the Trader
By using this script, you are essentially getting a "bird's eye view" of the market. It answers the question: "While I am looking at this small price move right now, what is the bigger picture telling me?" It helps prevent you from trading against a major trend by highlighting where the heavier market forces are actually moving.
//+------------------------------------------------------------------+
//| Multi.Period.Stochastic.mq4 |
//| Copyright © 2010, Vladimir Hlystov |
//| cmillion@narod.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2010, Vladimir Hlystov"
#property link "http://cmillion.narod.ru"
//+------------------------------------------------------------------+
#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 100
#property indicator_buffers 2
#property indicator_color1 DarkOrange
#property indicator_width1 1
#property indicator_color2 Orange
#property indicator_width2 1
//---- input parameters
extern int KPeriod =5;
extern int DPeriod =3;
extern int Slowing =3;
extern int timeframe =60;
//---- buffers
double BufferS[];
double Buffer[];
int pUsr;
//+------------------------------------------------------------------+
int init()
{
if (timeframe<Period()) timeframe=Period();
IndicatorBuffers(2);
//---- indicator lines
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0, Buffer);
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1, BufferS);
//----
timeframe = next_period(timeframe);
SetIndexLabel(0, "Stochastic "+StrPer(timeframe));
pUsr=timeframe/Period();
return(0);
}
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
if(counted_bars>0) counted_bars--;
int limit=Bars-counted_bars;
for(int i=0; i<limit; i++)
{
BufferS[i] = iStochastic(NULL,timeframe,KPeriod,DPeriod,Slowing,MODE_SMA,0,MODE_MAIN,
iBarShift(NULL,timeframe,Time[i],false));
}
for(i=0; i<limit; i++)
{
Buffer[i] = iMAOnArray(BufferS,0,pUsr,0,MODE_SMA,i);
}
return(0);
}
//+------------------------------------------------------------------+
int next_period(int per)
{
if (per > 43200) return(0);
if (per > 10080) return(43200);
if (per > 1440) return(10080);
if (per > 240) return(1440);
if (per > 60) return(240);
if (per > 30) return(60);
if (per > 15) return(30);
if (per > 5) return(15);
if (per > 1) return(5);
if (per == 1) return(1);
if (per == 0) return(Period());
}
//+------------------------------------------------------------------+
string StrPer(int per)
{
if (per == 1) return(" M1 ");
if (per == 5) return(" M5 ");
if (per == 15) return(" M15 ");
if (per == 30) return(" M30 ");
if (per == 60) return(" H1 ");
if (per == 240) return(" H4 ");
if (per == 1440) return(" D1 ");
if (per == 10080) return(" W1 ");
if (per == 43200) return(" MN1 ");
return("îøèáêà ïåðèîäà");
}
//+------------------------------------------------------------------+
Comments