Color Stochastic
Download scriptThis tool is designed as a visual aid for traders to identify specific momentum conditions in the financial markets. It builds upon the standard "Stochastic Oscillator" by adding a unique layer of visual highlighting that focuses on extreme market conditions.
Core Functionality
The script processes price data to create two primary moving lines on your chart:
- The Fast Line: Represents the immediate momentum of the market.
- The Slow Line (Signal): Acts as a smoothed average of the fast line, helping to filter out minor "noise" and identify the broader direction of the movement.
Key Features & Logic
Unlike standard oscillators that only show lines, this script includes specific logic to alert you visually when the market reaches "Overbought" or "Oversold" zones. Here is how that works:
1. Dynamic Threshold Monitoring The script constantly monitors where the Fast Line sits relative to two boundaries (levels) that you can customize. Typically, these are set to 80 (Overbought) and 20 (Oversold).
2. Visual Highlighting (The "Color" Logic) Instead of just watching the line cross a level, the script automatically tracks when the price remains in an extreme state:
- Upper Highlight: When the Fast Line climbs above your designated high threshold, the script triggers a visual indicator (colored Lime). It is designed to stay active as long as the momentum remains in that elevated zone.
- Lower Highlight: When the Fast Line drops below your designated low threshold, the script triggers a secondary visual indicator (colored Red). This highlights sustained downward momentum.
3. Customization Options The logic allows you to fine-tune how these calculations are performed based on your trading style:
- Smoothing Methods: You can choose between different types of Moving Averages (Simple, Exponential, Smoothed, or Linear Weighted) to determine how "fast" or "slow" the lines react to price changes.
- Price Source: You can choose whether the script calculates based on the highest/lowest prices of a candle or the actual closing price.
- Sensitivity: By adjusting the period settings, you can make the indicator more sensitive to quick price spikes or more stable for long-term trend following.
Summary for the Trader
In short, this script does the heavy lifting of monitoring extreme market zones for you. Rather than squinting at the numbers, it provides clear, color-coded visual cues that light up when the market is stretched too far in one direction, making it easier to spot potential exhaustion points or trend shifts.
//+------------------------------------------------------------------+
//| Color Stochastic.mq4 |
//| mladen |
//| |
//+------------------------------------------------------------------+
#property copyright "mladen"
#property link ""
#property indicator_separate_window
#property indicator_buffers 4
#property indicator_minimum 0
#property indicator_maximum 100
#property indicator_color1 DimGray
#property indicator_style1 STYLE_DOT
#property indicator_color2 DimGray
#property indicator_color3 Lime
#property indicator_color4 Red
#property indicator_width3 2
#property indicator_width4 2
//---- input parameters
//
// nice setings for trend = 35,10,1
//
//
extern string note1 = "Stochastic settings";
extern int KPeriod = 30;
extern int Slowing = 10;
extern int DPeriod = 10;
extern string note4 = "0=sma, 1=ema, 2=smma, 3=lwma";
extern int MAMethod = 0;
extern string note5 = "0=high/low, 1=close/close";
extern int PriceField = 1;
extern string note6 = "overbought level";
extern int overBought = 80;
extern string note7 = "oversold level";
extern int overSold = 20;
//---- buffers
//
//
//
//
//
double KFull[];
double DFull[];
double Upper[];
double Lower[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
SetIndexBuffer(0,DFull);
SetIndexBuffer(1,KFull);
SetIndexBuffer(2,Upper);
SetIndexBuffer(3,Lower);
SetIndexLabel(1,"Fast");
SetIndexLabel(2,NULL);
SetIndexLabel(3,NULL);
//
//
//
//
//
DPeriod = MathMax(DPeriod,1);
if (DPeriod==1) {
SetIndexStyle(0,DRAW_NONE);
SetIndexLabel(0,NULL);
}
else {
SetIndexStyle(0,DRAW_LINE);
SetIndexLabel(0,"Slow");
}
//
//
//
//
//
string shortName = "Stochastic ("+KPeriod+","+Slowing+","+DPeriod+","+maDescription(MAMethod)+","+priceDescription(PriceField);
if (overBought < overSold) overBought = overSold;
if (overBought < 100) shortName = shortName+","+overBought;
if (overSold > 0) shortName = shortName+","+overSold;
IndicatorShortName(shortName+")");
return(0);
}
//
//
//
//
//
int deinit()
{
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
int limit;
int i;
if(counted_bars<0) return(-1);
limit=Bars-counted_bars;
//
//
//
//
//
for(i=limit; i>=0; i--)
{
KFull[i] = iStochastic(NULL,0,KPeriod,DPeriod,Slowing,MAMethod,PriceField,MODE_MAIN,i);
DFull[i] = iStochastic(NULL,0,KPeriod,DPeriod,Slowing,MAMethod,PriceField,MODE_SIGNAL,i);
//
//
//
//
//
if (KFull[i] > overBought) { Upper[i] = KFull[i]; Upper[i+1] = KFull[i+1]; }
else { Upper[i] = EMPTY_VALUE;
if (Upper[i+2] == EMPTY_VALUE)
Upper[i+1] = EMPTY_VALUE; }
if (KFull[i] < overSold) { Lower[i] = KFull[i]; Lower[i+1] = KFull[i+1]; }
else { Lower[i] = EMPTY_VALUE;
if (Lower[i+2] == EMPTY_VALUE)
Lower[i+1] = EMPTY_VALUE; }
}
//
//
//
//
//
return(0);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
string priceDescription(int mode)
{
string answer;
switch(mode)
{
case 0: answer = "Low/High" ; break;
case 1: answer = "Close/Close" ; break;
default: answer = "Invalid price field requested";
Alert(answer);
}
return(answer);
}
string maDescription(int mode)
{
string answer;
switch(mode)
{
case MODE_SMA: answer = "SMA" ; break;
case MODE_EMA: answer = "EMA" ; break;
case MODE_SMMA: answer = "SMMA" ; break;
case MODE_LWMA: answer = "LWMA" ; break;
default: answer = "Invalid MA mode requested";
Alert(answer);
}
return(answer);
}
Comments