Color Stochastic_Pivot

Download script
Author: mladen

This script is a multi-functional trading tool designed to provide traders with several layers of visual data at once: momentum analysis, pivot point levels, and market statistics. It combines standard technical indicators with custom calculations to help identify potential price reversals and trends.

Momentum Analysis (Stochastic Oscillator)

The primary visual component of the script is based on the Stochastic Oscillator. This tool measures the location of the current price relative to its high/low range over a specific period.

  • Fast and Slow Lines: The script plots two main lines (Fast and Signal) that help traders identify momentum.
  • Dynamic Highlighting: A unique feature of this script is its ability to "color" or highlight the stochastic lines based on extreme market conditions. When the price enters an Overbought zone (the market is considered high/expensive) or an Oversold zone (the market is considered low/cheap), the script visually isolates these segments. This helps traders quickly identify when a trend might be reaching its limit and could potentially reverse.

Pivot Point Levels

The script automatically calculates and draws several horizontal "Pivot Points" based on the previous day's price action. These are used by many traders to identify support and resistance zones:

  • Central Pivot (PP): The baseline balance point for the current day.
  • Support Levels (S1, S2): These represent potential "floors" where the price might find buying interest.
  • Resistance Levels (R1, R2): These represent potential "ceilings" where the price might face selling pressure.
  • High/Low Projections: The script also includes dashed lines that project the previous days' highs and lows into the current session to provide a clearer picture of the immediate trading range.

Market Statistics & Real-Time Data

In addition to the visual charts, the script provides a live data summary in a text comment on the screen. This allows traders to see critical information at a glance without manual calculation:

  • Average Daily Range (ADR): The script calculates the average distance between the daily high and low across historical data. This helps traders understand how much "room" the market typically has to move in a single day.
  • Broker Swap Information: It automatically checks and displays the "Swap" rates (overnight interest) for both long and short positions, helping traders manage the costs of holding trades overnight.
  • Live Spread: It displays the current difference between the Buy and Sell prices (the spread), ensuring the trader knows the current liquidity cost.

Summary of Behavior

For a user, this tool acts as an all-in-one dashboard. It tells you where the price has been (Pivots), how fast it is moving right now (Stochastic), and how much room it has left to move (Average Daily Range), while simultaneously alerting you via visual highlights when the market becomes overextended.

Price Data Components
Series array that contains open time of each barSeries array that contains the highest prices of each barSeries array that contains the lowest prices of each barSeries array that contains close prices for each bar
Indicators Used
Stochastic oscillator
Miscellaneous
Implements a curve of type %1It issuies visual alerts to the screen
8 Views
0 Downloads
0 Favorites
Color Stochastic_Pivot
//+------------------------------------------------------------------+
//|                                             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[];
string DR;
double avg.rng, rng, sum.rng;

//+------------------------------------------------------------------+
//| 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; }                            
      }

   //
   //
   //
   //
   //
   Pivot.Plot();
   Daily.Range();
   comments();
   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);
}
//+------------------------------------------------------------------+

void Pivot.Plot()  {
   string t1,t2,PPn,s1n,s2n,r1n,r2n,LOPS1n,LOPS2n,HOPS1n,HOPS2n;
   double PP,s1,s2,r1,r2,LOPS1,LOPS2,HOPS1,HOPS2,H,L,C;
   
   PPn="PP "+TimeToStr(CurTime(),TIME_DATE);
   s1n="S1 "+TimeToStr(CurTime(),TIME_DATE);
   s2n="S2 "+TimeToStr(CurTime(),TIME_DATE);
   r1n="R1 "+TimeToStr(CurTime(),TIME_DATE);
   r2n="R2 "+TimeToStr(CurTime(),TIME_DATE);
   LOPS1n="LOPS1 "+TimeToStr(CurTime(),TIME_DATE);
   LOPS2n="LOPS2 "+TimeToStr(CurTime(),TIME_DATE);
   HOPS1n="HOPS1 "+TimeToStr(CurTime(),TIME_DATE);
   HOPS2n="HOPS2 "+TimeToStr(CurTime(),TIME_DATE);
   
   H=iHigh(Symbol(),PERIOD_D1,1);
   L=iLow(Symbol(),PERIOD_D1,1);
   C=iClose(Symbol(),PERIOD_D1,1);
   LOPS1=iLow(Symbol(),PERIOD_D1,1);
   LOPS2=iLow(Symbol(),PERIOD_D1,2);
   HOPS1=iHigh(Symbol(),PERIOD_D1,1);
   HOPS2=iHigh(Symbol(),PERIOD_D1,2);
   
   t1=TimeToStr(CurTime(),TIME_DATE)+" 00:00:00";
   t2=TimeToStr(CurTime(),TIME_DATE)+" 23:59:59";
   
   PP=NormalizeDouble((H+L+C)/3,Digits);
   s1=NormalizeDouble((PP*2)-H,Digits);
   r1=NormalizeDouble((PP*2)-L,Digits);
   s2=NormalizeDouble(PP-(r1-s1),Digits);
   r2=NormalizeDouble(PP+(r1-s1),Digits);
   ObjectCreate(PPn,OBJ_TREND,0,StrToTime(t1),PP,StrToTime(t2),PP);
   ObjectSet(PPn,10,false);
   ObjectSet(PPn,6,Gray);
   ObjectSet(PPn,7,STYLE_DOT);
   ObjectSet(PPn,9,true);
   ObjectCreate(s1n,OBJ_TREND,0,StrToTime(t1),s1,StrToTime(t2),s1);
   ObjectSet(s1n,10,false);
   ObjectSet(s1n,6,LightCoral);
   ObjectSet(s1n,7,STYLE_DOT);
   ObjectSet(s1n,9,true);
   ObjectCreate(s2n,OBJ_TREND,0,StrToTime(t1),s2,StrToTime(t2),s2);
   ObjectSet(s2n,10,false);
   ObjectSet(s2n,6,Tomato);
   ObjectSet(s2n,7,STYLE_DOT);
   ObjectSet(s2n,9,true);
   ObjectCreate(r1n,OBJ_TREND,0,StrToTime(t1),r1,StrToTime(t2),r1);
   ObjectSet(r1n,10,false);
   ObjectSet(r1n,6,LightGreen);
   ObjectSet(r1n,7,STYLE_DOT);
   ObjectSet(r1n,9,true);
   ObjectCreate(r2n,OBJ_TREND,0,StrToTime(t1),r2,StrToTime(t2),r2);
   ObjectSet(r2n,10,false);
   ObjectSet(r2n,6,SpringGreen);
   ObjectSet(r2n,7,STYLE_DOT);
   ObjectSet(r2n,9,true);
   ObjectCreate(LOPS1n,OBJ_TREND,0,StrToTime(t1),LOPS1,StrToTime(t2),LOPS1);
   ObjectSet(LOPS1n,10,false);
   ObjectSet(LOPS1n,6,LightGreen);
   ObjectSet(LOPS1n,7,STYLE_DASH);
   ObjectSet(LOPS1n,9,true);
   ObjectCreate(LOPS2n,OBJ_TREND,0,StrToTime(t1),LOPS2,StrToTime(t2),LOPS2);
   ObjectSet(LOPS2n,10,false);
   ObjectSet(LOPS2n,6,SpringGreen);
   ObjectSet(LOPS2n,7,STYLE_DASH);
   ObjectSet(LOPS2n,9,true);
   ObjectCreate(HOPS1n,OBJ_TREND,0,StrToTime(t1),HOPS1,StrToTime(t2),HOPS1);
   ObjectSet(HOPS1n,10,false);
   ObjectSet(HOPS1n,6,LightCoral);
   ObjectSet(HOPS1n,7,STYLE_DASH);
   ObjectSet(HOPS1n,9,true);
   ObjectCreate(HOPS2n,OBJ_TREND,0,StrToTime(t1),HOPS2,StrToTime(t2),HOPS2);
   ObjectSet(HOPS2n,10,false);
   ObjectSet(HOPS2n,6,Tomato);
   ObjectSet(HOPS2n,7,STYLE_DASH);
   ObjectSet(HOPS2n,9,true);

   if(Period()>=1440)   {ObjectDelete(PPn);   ObjectDelete(s1n);   ObjectDelete(s2n);   ObjectDelete(r1n);
                         ObjectDelete(r2n);   ObjectDelete(LOPS1n);ObjectDelete(LOPS2n);ObjectDelete(HOPS1n);
                         ObjectDelete(HOPS2n); }}
   

double Daily.Range() {
   if(DR==TimeToStr(CurTime(),TIME_DATE)) 
{return(NormalizeDouble(avg.rng,Digits));}
   //Print(DR,"  ",NormalizeDouble(avg.rng,Digits));
   rng=0;sum.rng=0;avg.rng=0;
   for(int i=0;i<iBars(Symbol(),1440);i++) {
      rng=(iHigh(Symbol(),PERIOD_D1,i)-iLow(Symbol(),PERIOD_D1,i));
      sum.rng+=rng;}

   double db=iBars(Symbol(),1440);   
   avg.rng=sum.rng/db;
   DR=TimeToStr(CurTime(),TIME_DATE);
return(NormalizeDouble(avg.rng,Digits));}


void comments()   {
if(MarketInfo(Symbol(),MODE_SWAPLONG)>0) string swap="longs,";
else swap="shorts.";
if(MarketInfo(Symbol(),MODE_SWAPLONG)<0 && MarketInfo(Symbol(),MODE_SWAPSHORT)<0) swap="your broker, :(";

   Comment("Last Tick: ",TimeToStr(CurTime(),TIME_DATE|TIME_SECONDS),"\n",
           "Swap favors ",swap,
           " Swap Long ",MarketInfo(Symbol(),MODE_SWAPLONG),
           ", Swap Short ",MarketInfo(Symbol(),MODE_SWAPSHORT),"\n",
           "Average Daily Range: ",NormalizeDouble(avg.rng,Digits),"\n",
           "Current Spread: ",Ask-Bid); }

Comments