Stochastic_3

Download script
Author: Copyright � 2009, Vladimir Hlystov
Stochastic_3

This script is designed to provide a comprehensive overview of market momentum by consolidating information from multiple timeframes into a single visual window. Instead of forcing a trader to switch back and forth between different charts (like 5-minute, 1-hour, and Daily) to see the "big picture," this tool automatically gathers that data and displays it simultaneously.

Core Functionality

The logic operates on three primary layers:

1. Automated Multi-Timeframe Analysis The script intelligently identifies which timeframes are appropriate based on the chart you are currently viewing. It looks at your current timeframe and then automatically finds the next logical "step up" in time (for example, if you are on a 15-minute chart, it will look for 1-hour data; if you are on an hour chart, it looks for a 4-hour chart). It repeats this process until it has identified up to three distinct tiers of time perspectives.

2. Synchronized Data Processing The tool calculates the "Stochastic" indicator—a common momentum oscillator—for all three identified timeframes at once. A key feature of this logic is that it synchronizes the data correctly: it ensures that the information shown for a higher timeframe (like Daily) corresponds exactly to the specific moment in time currently displayed on your lower timeframe chart.

3. Unified Signal Calculation Once the script gathers the momentum data from these different perspectives, it performs two types of visual outputs:

  • Individual Lines: It draws separate lines representing each specific timeframe, allowing you to see how short-term momentum differs from long-term momentum.
  • The Composite Signal: The script calculates a "Signal" line, which is the mathematical average of all available timeframes. This serves as a balanced summary, smoothing out the noise of smaller charts while still respecting the trends of larger ones.

Key Benefits for the User

  • Efficiency: You can monitor long-term trends and short-term fluctuations in one glance without changing tabs or windows.
  • Contextual Awareness: By seeing multiple timeframes together, it becomes easier to identify if a short-term price move is supported by the larger trend or if it is an isolated fluctuation.
  • Dynamic Scaling: Because the script automatically detects your timeframe, it adjusts its "steps" dynamically, making it versatile for day traders, swing traders, and long-term investors alike.
Indicators Used
Stochastic oscillator
Miscellaneous
Implements a curve of type %1
16 Views
0 Downloads
0 Favorites
Stochastic_3
//+------------------------------------------------------------------+
//|                                                  Stochastic3.mq4 |
//|                               Copyright © 2009, Vladimir Hlystov |
//|            Stochastic ïîêàçûâàåò ãðàôèêè 3 ïåðèîäîâ â îäíîì îêíå |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, Vladimir Hlystov"
#property link      "cmillion@narod.ru"

#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 100
#property indicator_level1	20
#property indicator_level3	50
#property indicator_level2	80
#property indicator_levelcolor	Silver//	öâåò ãîðèçîíòàëüíûõ óðîâíåé èíäèêàòîðà
#property indicator_levelwidth	0//	òîëùèíà ãîðèçîíòàëüíûõ óðîâíåé èíäèêàòîðà
#property indicator_levelstyle	2//	ñòèëü ãîðèçîíòàëüíûõ óðîâíåé èíäèêàòîðà
#property indicator_buffers 4
#property indicator_color1 Maroon
#property indicator_style1 2
#property indicator_color2 DarkGreen
#property indicator_style2 2
#property indicator_color3 Navy
#property indicator_style3 2
#property indicator_color4 Yellow
#property indicator_width4 2
//---- buffers
double SignalBuffer[];
double BUFFER_1[];
double BUFFER_2[];
double BUFFER_3[];
   int per1;
   int per2;
   int per3;
   int n=3;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   IndicatorBuffers(4);
   IndicatorDigits(0);
//---- indicator lines
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0, BUFFER_1);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1, BUFFER_2);
   SetIndexStyle(2,DRAW_LINE);
   SetIndexBuffer(2, BUFFER_3);
   SetIndexStyle(3,DRAW_LINE);
   SetIndexBuffer(3, SignalBuffer);
//---- name for DataWindow and indicator subwindow label
   per1=Period();
   per2 = next_period(per1+1);
   if (per2==0) n=1;
   per3 = next_period(per2+1);
   if (per3==0&&per2!=0) n=2;
   SetIndexLabel(0, string_ïåð(per1));
   SetIndexLabel(1, string_ïåð(per2));
   SetIndexLabel(2, string_ïåð(per3));
   SetIndexLabel(3, "Ñðåäíåå");
   IndicatorShortName("Stochastic ("+string_ïåð(per1)+""+string_ïåð(per2)+""+string_ïåð(per3)+")");
   return(0);
  }
//+------------------------------------------------------------------+
//| Stochastic oscillator                                            |
//+------------------------------------------------------------------+
int start()
{
   int    counted_bars=IndicatorCounted();
   if(counted_bars>0) counted_bars--;
   int limit=Bars-counted_bars;
   for(int i=0; i<limit; i++)
   {
      BUFFER_1[i]  = iStochastic(NULL,per1    ,5,3,3,MODE_SMA,0,MODE_MAIN,iBarShift(NULL,per1    ,Time[i],false));
      if (n>1) BUFFER_2[i]  = iStochastic(NULL,per2    ,5,3,3,MODE_SMA,0,MODE_MAIN,iBarShift(NULL,per2    ,Time[i],false));
      if (n>2) BUFFER_3[i] = iStochastic(NULL,per3   ,5,3,3,MODE_SMA,0,MODE_MAIN,iBarShift(NULL,per3   ,Time[i],false));
      if (n==3) SignalBuffer[i]  = (BUFFER_1[i]+BUFFER_2[i]+BUFFER_3[i])/n;
      if (n==2) SignalBuffer[i]  = (BUFFER_1[i]+BUFFER_2[i])/n;
      if (n==1) SignalBuffer[i]  = BUFFER_1[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);   
}
//+------------------------------------------------------------------+
string string_ïåð(int per)
{
   if (per == 1)     return(" M1  ");   //1 ìèíóòà
   if (per == 5)     return(" M5  ");   //5 ìèíóò 
   if (per == 15)    return(" M15 ");  //15 ìèíóò
   if (per == 30)    return(" M30 ");  //30 ìèíóò
   if (per == 60)    return(" H1  ");   //1 ÷àñ
   if (per == 240)   return(" H4  ");   //4 ÷àñà
   if (per == 1440)  return(" D1  ");   //1 äåíü
   if (per == 10080) return(" W1  ");   //1 íåäåëÿ
   if (per == 43200) return(" MN1 ");  //1 ìåñÿö
return("îøèáêà ïåðèîäà");
}
//+------------------------------------------------------------------+

Comments