Author: Copyright � 2011, basisforex@gmail.com
Stoc-2B

This tool is designed to provide traders with a multi-layered perspective on market momentum by consolidating information from different timeframes into a single visual display. Instead of requiring you to switch back and forth between various charts, it synchronizes data to give you a "big picture" view at a glance.

Core Functionality

The script utilizes the Stochastic Oscillator, a common technical analysis tool used to identify overbought or oversold conditions. However, rather than showing just one standard Stochastic line, this script allows for the simultaneous monitoring of multiple timeframes.

How it Works

  • Multi-Timeframe Synchronization: The script automatically identifies the relationship between your current chart and higher timeframes (such as moving from a 15-minute chart to 30-minute, 1-hour, or 4-hour views). It then fetches the data for those specific higher intervals.
  • Customizable Layers: You have the flexibility to toggle on or off different "layers" of analysis. The logic is built to handle various combinations:
    • Current Timeframe: Shows the immediate momentum (Main and Signal lines).
    • Secondary Timeframe: Provides a medium-term trend context.
    • Tertiary/Quaternary Timeframes: Offers long-term perspective to ensure your trades align with the broader market direction.
  • Dynamic Feedback: As you switch between different periods on your chart, the script intelligently recalculates which higher timeframes are relevant and updates the display accordingly. It also provides a text comment on the screen to clearly identify which timeframe corresponds to which color on your indicator window.

Visual Organization

The data is organized using a specific color-coding system to help distinguish between different time layers:

  • White/Red: Typically represents the primary data from your current active chart.
  • Yellow, Green, and Blue: Represent the additional momentum layers pulled from the higher timeframes.

Summary for the Trader

By using this script, you can verify if a trade is supported by the "higher authorities" of the market. For example, you can see if a buying signal on your current chart is also being supported by the momentum of the 1-hour and 4-hour charts simultaneously, helping to filter out "noise" and potentially increasing the reliability of your entries.

Indicators Used
Stochastic oscillator
Miscellaneous
Implements a curve of type %1
13 Views
0 Downloads
0 Favorites
Stoc-2B
/*------------------------------------------------------------------+
 |                                                      Stoc-2B.mq4 |
 |                                                 Copyright © 2011 |
 |                                             basisforex@gmail.com |
 +------------------------------------------------------------------*/
#property copyright "Copyright © 2011, basisforex@gmail.com"
#property link      "basisforex@gmail.com"
//----------------------------------------
#property indicator_separate_window
#property indicator_buffers 8
#property indicator_color1 White
#property indicator_color2 Red
#property indicator_color3 Yellow
#property indicator_color4 Red
#property indicator_color5 Green
#property indicator_color6 Red
#property indicator_color7 Blue
#property indicator_color8 Red
//-------------------------------------
extern bool       TimeFrame2     = true;
extern bool       TimeFrame3     = true;
extern bool       TimeFrame4     = true;
//-----
extern int        KPeriod        = 5;
extern int        DPeriod        = 3;
extern int        Slowing        = 3;
//-----
double s1[];
double s2[];
double s3[];
double s4[];
double s5[];
double s6[];
double s7[];
double s8[];
//+------------------------------------------------------------------+
int init()
 {
   SetIndexBuffer(0, s1);
   SetIndexBuffer(1, s2);
   SetIndexBuffer(2, s3);
   SetIndexBuffer(3, s4);
   SetIndexBuffer(4, s5);
   SetIndexBuffer(5, s6);
   SetIndexBuffer(6, s7);
   SetIndexBuffer(7, s8);
   //-----
   SetIndexStyle(0, DRAW_LINE);
   SetIndexStyle(1, DRAW_LINE, STYLE_DOT);
   SetIndexStyle(2, DRAW_LINE);
   SetIndexStyle(3, DRAW_LINE, STYLE_DOT);
   SetIndexStyle(4, DRAW_LINE);
   SetIndexStyle(5, DRAW_LINE, STYLE_DOT);
   SetIndexStyle(6, DRAW_LINE);
   SetIndexStyle(7, DRAW_LINE, STYLE_DOT);
   //-----
   return(0);
 }
//+------------------------------------------------------------------+
string GetNextTF(int curTF)
 {
   switch(curTF)
    {
      case 1:
        return("5=15#30");
        break;
      case 5:
        return("15=30#60");
        break; 
      case 15:
        return("30=60#240");
        break;
      case 30:
        return("60=240#1440");
        break;
      case 60:
        return("240=1440#10080");
        break;
      case 240:
        return("1440=10080#43200");
        break;        
    }
 }
//+------------------------------------------------------------------+ 
int start()
 {
   int limit;
   int counted_bars = IndicatorCounted();
   if(counted_bars < 0) return(-1);
   if(counted_bars > 0) counted_bars--;
   limit = Bars - counted_bars;
   //-----
   string T = GetNextTF(Period());
   int tf2 = StrToDouble(StringSubstr(T, 0, StringFind(T, "=", 0)));
   int tf3 = StrToDouble(StringSubstr(T, StringFind(T, "=", 0) + 1, StringFind(T, "#", 0)));
   int tf4 = StrToDouble(StringSubstr(T, StringFind(T, "#", 0) + 1, StringLen(T)));
   //-----
   for(int i = limit - 1; i >= 0; i--)
    {
         //===============================================         __________________________________________________   st1  &  st2  &  st3  & st4
         if(TimeFrame2 == true && TimeFrame3 == true && TimeFrame4 == true)
          {
            Comment(Period(), " White", "\n", tf2, " Yellow", "\n", tf3, " Green", "\n", tf4, " Blue");
            s1[i]  = iStochastic(NULL, 0, KPeriod, DPeriod, Slowing, MODE_SMA,0,MODE_MAIN, i);
            s2[i]  = iStochastic(NULL, 0, KPeriod, DPeriod, Slowing, MODE_SMA,0,MODE_SIGNAL, i);
            s3[i]  = iStochastic(NULL, tf2, KPeriod, DPeriod, Slowing, MODE_SMA,0,MODE_MAIN, i / (tf2 / Period()));
            s5[i]  = iStochastic(NULL, tf3, KPeriod, DPeriod, Slowing, MODE_SMA,0,MODE_MAIN, i / (tf3 / Period()));
            s7[i]  = iStochastic(NULL, tf4, KPeriod, DPeriod, Slowing, MODE_SMA,0,MODE_MAIN, i / (tf4 / Period()));
          }
          //===============================================         __________________________________________________   st1  &  st2  &  st3   
         else if(TimeFrame2 == true && TimeFrame3 == true && TimeFrame4 == false)
          {     
            Comment(Period(), " White", "\n", tf2, " Yellow", "\n", tf3, " Green");
            s1[i]  = iStochastic(NULL, 0, KPeriod, DPeriod, Slowing, MODE_SMA,0,MODE_MAIN, i);
            s2[i]  = iStochastic(NULL, 0, KPeriod, DPeriod, Slowing, MODE_SMA,0,MODE_SIGNAL, i);
            s3[i]  = iStochastic(NULL, tf2, KPeriod, DPeriod, Slowing, MODE_SMA,0,MODE_MAIN, i / (tf2 / Period()));
            s5[i]  = iStochastic(NULL, tf3, KPeriod, DPeriod, Slowing, MODE_SMA,0,MODE_MAIN, i / (tf3 / Period()));
          }
         //===============================================         __________________________________________________   st1  &  st2  &  st4    
         else if(TimeFrame2 == true && TimeFrame3 == false && TimeFrame4 == true)
          {     
            Comment(Period(), " White", "\n", tf2, " Yellow", "\n", tf4, " Blue");
            s1[i]  = iStochastic(NULL, Period(), KPeriod, DPeriod, Slowing, MODE_SMA,0,MODE_MAIN, i);
            s2[i]  = iStochastic(NULL, Period(), KPeriod, DPeriod, Slowing, MODE_SMA,0,MODE_SIGNAL, i);
            s3[i]  = iStochastic(NULL, tf2, KPeriod, DPeriod, Slowing, MODE_SMA,0,MODE_MAIN, i / (tf2 / Period()));            
            s7[i]  = iStochastic(NULL, tf4, KPeriod, DPeriod, Slowing, MODE_SMA,0,MODE_MAIN, i / (tf4 / Period()));
          }
         //===============================================         __________________________________________________   st1  &  st3  &  st4    
         else if(TimeFrame2 == false && TimeFrame3 == true && TimeFrame4 == true)
          {     
            Comment(Period(), " White", "\n", tf3, " Green", "\n", tf4, " Blue");
            s1[i]  = iStochastic(NULL, Period(), KPeriod, DPeriod, Slowing, MODE_SMA,0,MODE_MAIN, i);
            s2[i]  = iStochastic(NULL, Period(), KPeriod, DPeriod, Slowing, MODE_SMA,0,MODE_SIGNAL, i);
            s5[i]  = iStochastic(NULL, tf3, KPeriod, DPeriod, Slowing, MODE_SMA,0,MODE_MAIN, i / (tf3 / Period()));
            s7[i]  = iStochastic(NULL, tf4, KPeriod, DPeriod, Slowing, MODE_SMA,0,MODE_MAIN, i / (tf4 / Period()));
          } 
         //===============================================         __________________________________________________   st1  &  st2    
         else if(TimeFrame2 == true && TimeFrame3 == false && TimeFrame4 == false)
          {     
            Comment(Period(), " White", "\n", tf2, " Yellow");
            s1[i]  = iStochastic(NULL, Period(), KPeriod, DPeriod, Slowing, MODE_SMA,0,MODE_MAIN, i);
            s2[i]  = iStochastic(NULL, Period(), KPeriod, DPeriod, Slowing, MODE_SMA,0,MODE_SIGNAL, i);
            s3[i]  = iStochastic(NULL, tf2, KPeriod, DPeriod, Slowing, MODE_SMA,0,MODE_MAIN, i / (tf2 / Period()));
            s4[i]  = iStochastic(NULL, tf2, KPeriod, DPeriod, Slowing, MODE_SMA,0,MODE_SIGNAL, i/ (tf2 / Period()));
          } 
         //===============================================         __________________________________________________   st1  &  st3    
         else if(TimeFrame2 == false && TimeFrame3 == true && TimeFrame4 == false)
          {     
            Comment(Period(), " White", "\n", tf3, " Green");
            s1[i]  = iStochastic(NULL, Period(), KPeriod, DPeriod, Slowing, MODE_SMA,0,MODE_MAIN, i);
            s2[i]  = iStochastic(NULL, Period(), KPeriod, DPeriod, Slowing, MODE_SMA,0,MODE_SIGNAL, i);
            s5[i]  = iStochastic(NULL, tf3, KPeriod, DPeriod, Slowing, MODE_SMA,0,MODE_MAIN, i / (tf3 / Period()));
            s6[i]  = iStochastic(NULL, tf3, KPeriod, DPeriod, Slowing, MODE_SMA,0,MODE_SIGNAL, i/ (tf3 / Period()));
          } 
         //===============================================         __________________________________________________   st1  &  st4    
         else if(TimeFrame2 == false && TimeFrame3 == false && TimeFrame4 == true)
          {     
            Comment(Period(), " White", "\n", tf4, " Blue");
            s1[i]  = iStochastic(NULL, 0, KPeriod, DPeriod, Slowing, MODE_SMA,0,MODE_MAIN, i);
            s2[i]  = iStochastic(NULL, 0, KPeriod, DPeriod, Slowing, MODE_SMA,0,MODE_SIGNAL, i);
            s7[i]  = iStochastic(NULL, tf4, KPeriod, DPeriod, Slowing, MODE_SMA,0,MODE_MAIN, i / (tf4 / Period()));
            s8[i]  = iStochastic(NULL, tf4, KPeriod, DPeriod, Slowing, MODE_SMA,0,MODE_SIGNAL, i/ (tf4 / Period()));
          }
         //===============================================          __________________________________________________   st1
         else if(TimeFrame2 == false && TimeFrame3 == false && TimeFrame4 == false)
          {
            Comment(Period(), " White");
             s1[i]  = iStochastic(NULL, 0, KPeriod, DPeriod, Slowing, MODE_SMA,0,MODE_MAIN, i);
             s2[i]  = iStochastic(NULL, 0, KPeriod, DPeriod, Slowing, MODE_SMA,0,MODE_SIGNAL, i);
          }        
    }  
   //==============================================================================================================================================
   return(0);
 }

Comments