All Color Stochastic Test





//+------------------------------------------------------------------+
//|                                               All Stochastic.mq4 |
//|                                                 made by : mladen |
//+------------------------------------------------------------------+
#property copyright   "this is public domain software"
#property link        "www.forex-tsd.com"
#define indicatorName "All Stochastic"

//
//
//
//
//

#property indicator_separate_window
#property indicator_buffers   6
#property indicator_minimum   0
#property indicator_maximum 100
#property indicator_color1 DimGray
#property indicator_style1 STYLE_DOT
#property indicator_color2 Yellow //Neutral
#property indicator_color3 Green //UPPER
#property indicator_color4 Tomato //LOWER
#property indicator_color5 Lime //UPTREND
#property indicator_color6 Red //DOWNTREND
#property indicator_width2 4
#property indicator_width3 4
#property indicator_width4 4
#property indicator_width5 4
#property indicator_width6 4
#define SignalName "StochasticSignal"

//---- input parameters
//
//
//
//
//

extern int    Kperiod              = 5;
extern int    Dperiod              = 3;
extern int    Slowing              = 3;
extern int    MAMethod             = 3;
extern int    PriceField           = 1;
extern int       overSold      =  70,
       overBought    =  30;

extern string __                   = "Chose timeframes (as in periodicity bar)";
extern string timeFrames           = "M1;M5;M15;M30;H1;H4;D1;W1;MN";
extern int    barsPerTimeFrame     = 35;
extern bool   shiftRight           = False;
extern bool   currentFirst         = False; 
extern color  txtColor             = Silver; 
extern color  separatorColor       = DimGray; 
//tambahan

//extern string note6 = "Stochastic settings";
//extern int       KPeriod       =   10,
//                 DPeriod       =   3,
//                 Slowing       =   3;
//extern string note7 = "0=sma, 1=ema, 2=smma, 3=lwma";
//extern int       MAMethod      =   3;
//extern string note8 = "0=high/low, 1=close/close";
//extern int       PriceField    =   1;
//extern string note9 = "OverSold/OverBought Level";
//extern int       overSold      =  80,
//                 overBought    =  20;
extern string note11 = "Directional: true/false";
extern bool      Directional   = true,
                 showBars      = false,
                 showArrows    = false,
                 alertsOn      = true,
                 alertsMessage = true,
                 alertsSound   = true,
                 alertsEmail   = false;

//tamat


//---- buffers
//
//
//
//
//tambahan
double   KFull[],
         DFull[],
         Upper[],
         Lower[],
         Uptrend[],
         Downtrend[];

double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
double ExtMapBuffer5[];


//
//
//
//
//

string shortName;
string labels[];
int    periods[];
int    Shift; 

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()///tambahan
{

      SetIndexBuffer(0,DFull);
      SetIndexBuffer(1,KFull);
      SetIndexBuffer(2,Upper);
      SetIndexBuffer(3,Lower);
      SetIndexBuffer(4,Uptrend);
      SetIndexBuffer(5,Downtrend);
         
         //
         //
         //
         //
         //
         
      //if (showBars)
      //   {      
      //      SetIndexStyle(0,DRAW_NONE);
      //      SetIndexStyle(1,DRAW_NONE);
      //      SetIndexStyle(2,DRAW_HISTOGRAM);
      //      SetIndexStyle(3,DRAW_HISTOGRAM);
       //     SetIndexStyle(4,DRAW_HISTOGRAM);
      //      SetIndexStyle(5,DRAW_HISTOGRAM);
       //     SetIndexLabel(0,NULL);
        //    SetIndexLabel(1,NULL);
       //     SetIndexLabel(2,"Stochastic");
       //     SetIndexLabel(3,"Stochastic");
       //     SetIndexLabel(4,"Stochastic");
       //     SetIndexLabel(5,"Stochastic");
       //  }                  
      //else
         {
            SetIndexLabel(0,"Stochastic");
            SetIndexLabel(1,"Stochastic");
            SetIndexLabel(2,NULL);
            SetIndexLabel(3,NULL);
            SetIndexLabel(4,NULL);
            SetIndexLabel(5,NULL);
            SetIndexStyle(0,DRAW_LINE);
            SetIndexStyle(1,DRAW_LINE);
            SetIndexStyle(2,DRAW_LINE);
            SetIndexStyle(3,DRAW_LINE);
            SetIndexStyle(4,DRAW_NONE);
            SetIndexStyle(5,DRAW_NONE);
            //DPeriod = MathMax(DPeriod,1);
            //if (DPeriod==1) 
            {
                  SetIndexStyle(0,DRAW_NONE);
                  SetIndexLabel(0,NULL);
              // }
           // else 
           // {
              //    SetIndexStyle(0,DRAW_LINE); 
               //   SetIndexLabel(0,"Signal");
               }               
         }
              
         //
         //tamat

      if (shiftRight) Shift = 1;
      else            Shift = 0;
            barsPerTimeFrame = MathMax(barsPerTimeFrame,15);      
            shortName = indicatorName+" ("+Kperiod+","+Dperiod+","+Slowing+","+MAMethod+")";
                        IndicatorShortName(shortName);

      //
      //
      //
      //
      //

         SetIndexBuffer(0,ExtMapBuffer1);
         SetIndexBuffer(1,ExtMapBuffer2);
         SetIndexBuffer(2,ExtMapBuffer3);
         SetIndexBuffer(3,ExtMapBuffer4);
         
        

         SetIndexShift(0,Shift*(barsPerTimeFrame+1));
         SetIndexShift(1,Shift*(barsPerTimeFrame+1));
         SetIndexShift(2,Shift*(barsPerTimeFrame+1));
         SetIndexShift(3,Shift*(barsPerTimeFrame+1));
         
         SetIndexLabel(0,"Stochastic");
         SetIndexLabel(1,"Signal");      

      //
      //
      //
      //
      //
      
      timeFrames = StringUpperCase(StringTrimLeft(StringTrimRight(timeFrames)));
      if (StringSubstr(timeFrames,StringLen(timeFrames),1) != ";")
                       timeFrames = StringConcatenate(timeFrames,";");

         //
         //
         //
         //
         //                                   
            
         int s = 0;
         int i = StringFind(timeFrames,";",s);
         int time;
         string current;
            while (i > 0)
            {
               current = StringSubstr(timeFrames,s,i-s);
               time    = stringToTimeFrame(current);
               if (time > 0) {
                     ArrayResize(labels ,ArraySize(labels)+1);
                     ArrayResize(periods,ArraySize(periods)+1);
                                 labels[ArraySize(labels)-1] = current; 
                                 periods[ArraySize(periods)-1] = time; }
                                 s = i + 1;
                                     i = StringFind(timeFrames,";",s);
            }
      
      //
      //
      //
      //
      //

      if(currentFirst)
         for (i=1;i<ArraySize(periods);i++)
         if (Period()==periods[i])
            {
               string tmpLbl = labels[i];
               int    tmpPer = periods[i];
               
               //
               //
               //
               //
               //
               
               for (int k=i ;k>0; k--) {
                     labels[k]  = labels[k-1];
                     periods[k] = periods[k-1];
                  }                     
               labels[0]  = tmpLbl;
               periods[0] = tmpPer;
            }
   return(0);
}


//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
{
   for(int l=0;l<ArraySize(periods);l++) {
         ObjectDelete(indicatorName+l);
         ObjectDelete(indicatorName+l+"label");
      }         
   return(0);
}

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

int start()
{
     string separator;
     int    window=WindowFind(shortName);
     int    k=0;


     //
     //
     //
     //
     //
              
            for(int p=0; p<ArraySize(periods);p++)
                  {
                     for(int i=0; i<barsPerTimeFrame;i++,k++)
                           {
                              ExtMapBuffer1[k] = iStochastic(NULL,periods[p],Kperiod,Dperiod,Slowing,MAMethod,PriceField,0,i);
                              ExtMapBuffer2[k] = iStochastic(NULL,periods[p],Kperiod,Dperiod,Slowing,MAMethod,PriceField,1,i);
                           }
                           ExtMapBuffer1[k] =EMPTY_VALUE;
                           ExtMapBuffer2[k] =EMPTY_VALUE;
                           k += 1;
                           
                           //
                           //
                           //
                           //
                           //
                           
                           separator = indicatorName+p;
                           if(ObjectFind(separator)==-1)
                              ObjectCreate(separator,OBJ_TREND,window,0,0);
                              ObjectSet(separator,OBJPROP_TIME1,barTime(k-Shift*(barsPerTimeFrame+1)-1));
                              ObjectSet(separator,OBJPROP_TIME2,barTime(k-Shift*(barsPerTimeFrame+1)-1));
                              ObjectSet(separator,OBJPROP_PRICE1,  0);
                              ObjectSet(separator,OBJPROP_PRICE2,100);
                              ObjectSet(separator,OBJPROP_COLOR ,separatorColor);
                              ObjectSet(separator,OBJPROP_WIDTH ,2);
                           separator = indicatorName+p+"label";
                           if(ObjectFind(separator)==-1)
                              ObjectCreate(separator,OBJ_TEXT,window,0,0);
                              ObjectSet(separator,OBJPROP_TIME1,barTime(k-Shift*(barsPerTimeFrame+1)-5));
                              ObjectSet(separator,OBJPROP_PRICE1,100);            
                              ObjectSetText(separator,labels[p],9,"Arial",txtColor);
                  }

      //
      //
      //
      //
      //
      
      SetIndexDrawBegin(0,Bars-k);
      SetIndexDrawBegin(1,Bars-k);              
   return(0);
}

//+------------------------------------------------------------------+
//+ Custom functions and procedures                                  +
//+------------------------------------------------------------------+

int barTime(int a)
{
   if(a<0)
         return(Time[0]+Period()*60*MathAbs(a));
   else  return(Time[a]);   
}

//+------------------------------------------------------------------+
//+                                                                  +
//+------------------------------------------------------------------+
//
//
//
//
//

int stringToTimeFrame(string TimeFrame)
{
   int TimeFrameInt=0;
      if (TimeFrame=="M1")  TimeFrameInt=PERIOD_M1;
      if (TimeFrame=="M5")  TimeFrameInt=PERIOD_M5;
      if (TimeFrame=="M15") TimeFrameInt=PERIOD_M15;
      if (TimeFrame=="M30") TimeFrameInt=PERIOD_M30;
      if (TimeFrame=="H1")  TimeFrameInt=PERIOD_H1;
      if (TimeFrame=="H4")  TimeFrameInt=PERIOD_H4;
      if (TimeFrame=="D1")  TimeFrameInt=PERIOD_D1;
      if (TimeFrame=="W1")  TimeFrameInt=PERIOD_W1;
      if (TimeFrame=="MN")  TimeFrameInt=PERIOD_MN1;
   return(TimeFrameInt);
}

//
//
//
//
//

string StringUpperCase(string str)
{
   string   s = str;
   int      lenght = StringLen(str) - 1;
   int      char;
   
   while(lenght >= 0)
      {
         char = StringGetChar(s, lenght);
         
         //
         //
         //
         //
         //
         
         if((char > 96 && char < 123) || (char > 223 && char < 256))
                  s = StringSetChar(s, lenght, char - 32);
          else 
              if(char > -33 && char < 0)
                  s = StringSetChar(s, lenght, char + 224);
                  
         //
         //
         //
         //
         //
                                 
         lenght--;
   }
   
   //
   //
   //
   //
   //
   
   return(s);
}



Sample





Analysis



Market Information Used:

Series array that contains open time of each bar


Indicator Curves created:


Implements a curve of type DRAW_LINE
Implements a curve of type DRAW_NONE

Indicators Used:

Stochastic oscillator


Custom Indicators Used:

Order Management characteristics:

Other Features: