StochColorBars

Download script
Author: Copyright � 2004-35, banzai
StochColorBars

This tool is a visual trading indicator designed to simplify the analysis of market momentum by translating complex mathematical data into easy-to-read color-coded bars. Instead of requiring you to manually interpret overlapping lines and moving averages, this script provides an immediate visual "pulse" of the market's direction and intensity.

How it Works

The logic is based on the Stochastic Oscillator, a common technical tool used to determine if a currency or asset is overbought (priced too high) or oversold (priced too low). The script automatically calculates these values in the background and displays them as four distinct visual layers:

  • Trend Direction (Uptrend vs. Downtrend): The indicator constantly compares two primary mathematical signals (the "Main" line and the "Signal" line).

    • If the Main signal is higher than the Signal line, it identifies an Uptrend, highlighting the bars in Lime.
    • If the Main signal falls below the Signal line, it identifies a Downtrend, highlighting the bars in Red.
  • Extreme Market Conditions (Overbought vs. Oversold): Beyond just the direction, the script monitors how "stretched" the price has become relative to its recent range. It uses two customizable thresholds:

    • Overbought: When the momentum reaches a pre-set high level (typically 80), it signals that the market might be overextended to the upside, marking these bars in Dark Green.
    • Oversold: When the momentum drops below a pre-set low level (typically 20), it suggests the market might be overextended to the downside, marking these bars in Maroon.

Key Customization Features

The script is highly flexible and allows you to tailor the sensitivity of the data to match your specific trading style:

  • Timeframe Selection: You can choose to view the momentum based on different time periods (e.g., 1-minute, 1-hour, or Daily charts).
  • Sensitivity Settings: You can adjust the "K" and "D" periods as well as the "Slowing" factor. Increasing these numbers will make the indicator smoother and slower to react, while decreasing them will make it more sensitive to rapid price changes.
  • Price Source: You can choose whether the logic should calculate based on the highest/lowest prices reached or the actual closing prices of the candles.

Summary for the Trader

By using this script, you no longer have to guess where the "turning points" are. You get a real-time visual map: the Lime and Red colors tell you which way the wind is blowing, while the Dark Green and Maroon colors warn you when that wind might be running out of steam.

Indicators Used
Stochastic oscillator
Miscellaneous
Implements a curve of type %1
5 Views
0 Downloads
0 Favorites
StochColorBars
//+------------------------------------------------------------------+
//|                                               StochColorBars.mq4 |
//|                                      Copyright © 2004-35, banzai |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004-35, banzai"
#property link      "http://www.forex-tsd.com/indicators-metatrader-4/4108-stochastic-color-bar.html"

#property indicator_separate_window
#property indicator_buffers   4
#property  indicator_minimum 0
#property  indicator_maximum 1
#property indicator_color1 Lime //Uptrend
#property indicator_color2 Red //Downtrend
#property indicator_color3 DarkGreen //Overbought
#property indicator_color4 Maroon //Oversold
 
//extern string note1 = "Chart Time Frame";
//extern string note2 = "0=current time frame";
//extern string note3 = "1=M1, 5=M5, 15=M15, 30=M30";
//extern string note4 = "60=H1, 240=H4, 1440=D1";
//extern string note5 = "10080=W1, 43200=MN1";
int	TimeFrame	= 0;		// {1=M1, 5=M5, 15=M15, ..., 1440=D1, 10080=W1, 43200=MN1}
extern string note6 = "Stochastic settings";
extern int       KPeriod     =  14;
extern int       DPeriod     =  3;
extern int       Slowing     =  3;
extern string note7 = "0=sma, 1=ema, 2=smma, 3=lwma";
extern int       MAMethod    =   0;
extern string note8 = "0=high/low, 1=close/close";
extern int       PriceField  =   1;
extern string note9 = "overbought level";
extern int       overBought  =  80;
extern string note10 = "oversold level";
extern int       overSold    =  20;

double Uptrend[];
double Downtrend[];
double Upper[];
double Lower[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+

int init()
{
   SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,4,indicator_color1);
   SetIndexBuffer(0,Uptrend);
   SetIndexLabel(0,"Uptrend");
   
   SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID,4,indicator_color2);
   SetIndexBuffer(1,Downtrend);
   SetIndexLabel(1,"Downtrend");
   
   SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_SOLID,4,indicator_color3);
   SetIndexBuffer(2,Upper);
   SetIndexLabel(2,"Upper");   
   SetIndexStyle(3,DRAW_HISTOGRAM,STYLE_SOLID,4,indicator_color4);
   SetIndexBuffer(3,Lower);
   SetIndexLabel(3,"Lower");          
         
   IndicatorShortName("StochBars ("+KPeriod+","+DPeriod+","+Slowing+")");
   return(0);
}

int deinit()
{
   return(0);
}

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+

int start()
{
   int    counted_bars=IndicatorCounted(), limit, banzai;
   double percentK, percentD;
   
   if(counted_bars<0) return(-1);
   limit=Bars-counted_bars;
      
   for(banzai=limit; banzai>=0; banzai--)
      {
            percentK = iStochastic(NULL,TimeFrame,KPeriod,DPeriod,Slowing,MAMethod,PriceField,MODE_MAIN,banzai);
            percentD = iStochastic(NULL,TimeFrame,KPeriod,DPeriod,Slowing,MAMethod,PriceField,MODE_SIGNAL,banzai);
            if (percentK >= percentD)   { Uptrend[banzai]   = 1;}
            if (percentK <= percentD)   { Downtrend[banzai] = 1;}
            if (percentK >= overBought) { Upper[banzai]     = 1;}
            if (percentK <= overSold)   { Lower[banzai]     = 1;}                   
      }
 
   return(0);
}


Comments