Stochastic-4H-v1

Download script
Stochastic-4H-v1

This tool is designed to help traders analyze market trends by viewing data from a larger timeframe while staying on their current chart. Essentially, it allows you to see "the big picture" without having to switch back and forth between different time periods (such as looking at 4-hour trends while trading on a much smaller, faster chart).

How the Logic Works

1. Multi-Timeframe Synchronization The primary function of this script is to bridge the gap between two different timeframes. While you may be watching short-term price movements, the tool reaches out to a specific "old" or larger timeframe (set by default to 4 hours). It calculates technical data from that larger window and projects it onto your current screen.

2. Time Alignment To ensure the information is accurate, the script performs a sophisticated time translation. It identifies the exact starting point of a candle on the smaller timeframe and finds the corresponding candle on the larger timeframe. This ensures that the visual data you see matches the specific moment in history you are currently viewing.

3. Stochastic Analysis The tool utilizes a "Stochastic Oscillator" calculation. In trading, this is used to determine if an asset is overbought (priced too high) or oversold (priced too low). The script takes two specific lines of data:

  • The Main Line: Represents the primary momentum of the large timeframe.
  • The Signal Line: A smoothed average that helps identify where the momentum is heading.

4. Visual Representation Instead of just providing raw numbers, the script draws these two lines clearly on a separate window below your main price chart. By observing how these lines behave—specifically when they move in relation to each other based on the 4-hour data—traders can make more informed decisions about whether the broader market trend supports their current trade.

Summary for the User

In short, this script acts like a "window" into the larger market. It automatically calculates and displays the 4-hour Stochastic momentum on your current chart, allowing you to see if the long-term trend is moving with or against your immediate trades in real-time.

Indicators Used
Stochastic oscillator
Miscellaneous
Implements a curve of type %1
9 Views
0 Downloads
0 Favorites
Stochastic-4H-v1
//+------------------------------------------------------------------+
//|                                                Stochastic 4H.mq4 |
//|                                         Copyright © 2006, lukas1 |
//|                               Stochastic from   old   timeframe  |
//|                                     v.1  enable for visual mode  |
//+------------------------------------------------------------------+
#property  copyright "Copyright © 2006, lukas1"
//---- indicator settings
#property  indicator_separate_window
#property  indicator_buffers 2
#property  indicator_color1  MediumPurple
#property  indicator_color2  Red
#property  indicator_width1  2
//---- indicator parameters
extern int FastEMA=5;
extern int SlowEMA=3;
extern int SignalSMA=3;
extern int AppliedPrice = 0;   // 0=PRICE_CLOSE; 1=PRICE_OPEN; 5=PRICE_TYPICAL
extern int VarPeriod=240;      //old timeframe
         //PERIOD_M5   5         5 minutes
         //PERIOD_M15  15        15 minutes 
         //PERIOD_M30  30        30 minutes 
         //PERIOD_H1   60        1 hour 
         //PERIOD_H4   240       4 hours 
         //PERIOD_D1   1440      1 day 
         //PERIOD_W1   10080     1 week 
         //PERIOD_MN1  43200     1 month 
//---- indicator buffers
double     Buffer0[],Buffer1[];
int p;  // current period
int k;  // repetition factor old timeframe
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- drawing settings
   SetIndexStyle(0, DRAW_LINE);
   SetIndexStyle(1, DRAW_LINE);
   SetIndexStyle(2, 12);
   SetIndexStyle(3, 12);   
   SetIndexDrawBegin(0, SlowEMA);
   SetIndexDrawBegin(1, SlowEMA);   
   IndicatorDigits(Digits + 1);
//---- indicator buffers mapping
   SetIndexBuffer(0, Buffer0);
   SetIndexBuffer(1, Buffer1);
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("Stoch 4H (" + FastEMA + "," + SlowEMA + "," + SignalSMA + 
                      ", " + VarPeriod + "min)");
   SetIndexLabel(0, "Stoch 4H(" + VarPeriod + ")");
   SetIndexLabel(1, "Signal 4H(" + VarPeriod + ")");
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//|                                    Stochastic for old timeframe  |
//+------------------------------------------------------------------+
int start()
  {
   int i, limit;
   int counted_bars = IndicatorCounted();
   //---- check for possible errors
   if(counted_bars < 0)       return(-1);
   if(counted_bars <= SlowEMA)
       limit = Bars - SlowEMA ;
   else
       limit = Bars - counted_bars;   
   p = Period();
   k = VarPeriod/p;                              // repetition factor old timeframe
   i=limit-1;
   while (i>=0)
      {
      int bb=HighBar(Symbol(), 0, i, VarPeriod); // definition of HighBar, having symbol, lowTF,
                                                 // and bar's number in lowTF, calculated highTF;
                                                 // (symbol, lowTF, bar's number, highTF)     
      if (bb==-1) continue;       
      Buffer0[i] =iStochastic(Symbol(), VarPeriod, FastEMA, SlowEMA, SignalSMA, 0,AppliedPrice, 0, bb);
      Buffer1[i]=iStochastic(Symbol(),VarPeriod, FastEMA, SlowEMA, SignalSMA, 0,AppliedPrice, 1, bb);
      i--;
      }
//---- done
   return(0);
  }
//+------------------------------------------------------------------+
int HighBar(string symbol,int TFLow,int BarLow,int TFHigh) 
                                                   // definition of HighBar, having symbol, lowTF,
                                                   // and bar's number in lowTF, calculated highTF;
                                                   // (symbol, lowTF, bar's number, highTF)     
 {
   datetime BarTimeLow=iTime(symbol, TFLow, BarLow);    // time's value of bar means in BarLow
   int error=GetLastError();
   if(error==4066) return (-1);
   
   int res=iBarShift(symbol, TFHigh, BarTimeLow, false);// displacement of bar means in BarTimeLow
   error=GetLastError();
   if(error==4066) return (-1);
   return (res);
 }
//+------------------------------------------------------------------+

Comments