All_Stoch_indi_NoAlert





//+------------------------------------------------------------------+
//|                                               All_Stoch_indi.mq4 |
//|                                                              Zen |
//|                    Based on "All Woodies CCIv1.0" made by mladen |
//+------------------------------------------------------------------+
#property copyright   "Zen"

#property indicator_separate_window
#property indicator_maximum 100
#property indicator_minimum 0
#property indicator_buffers 2
#property indicator_color1  LightSeaGreen
#property indicator_color2  Red

#property indicator_width1  1
#property indicator_width2  1

#property indicator_level1  20
#property indicator_level2  80
#property indicator_levelcolor Silver

#define LOOK_TO_BUY      1
#define LOOK_TO_SELL     2
#define UNDECIDED        0

extern string _                    = "Stochastic Inputs";
extern int    K_Period             = 14;
extern int    D_Period             =  1;
extern int    Slowing              =  3;
extern string PriceField_Setting   = "0 - Low/High or 1 - Close/Close";
extern int    PriceField           = 0;
extern string MA_Method_Setting    = "0 - SMA, 1 - EMA, 2 - SMMA, 3 - LWMA";
extern int    MA_Method            = 0;
extern string timeFrames           = "M1;M5;M15;M30;H1;H4;D1;W1;MN";
extern int    barsPerTimeFrame     = 20;
extern bool   shiftRight           = False; 
extern bool   currentFirst         = true; 
extern color  txtColor             = Silver; 
extern color  separatorColor       = DimGray; 
extern int    Low_Level            = 20;
extern int    High_Level           = 80;

//---- buffers
double buffer1[];
double buffer2[];

//

string shortName;
string labels[];
int    periods[];
int    Shift;
double minValue;
double maxValue;
string indicatorName;


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

int init()
{
   
   SetIndexBuffer(0,buffer1); SetIndexStyle(0, DRAW_LINE, STYLE_SOLID);

   SetIndexBuffer(1,buffer2); SetIndexStyle(1, DRAW_LINE, STYLE_DOT);
 
   SetIndexLabel(0,"Main");
   SetIndexLabel(1,"Signal");

  // if (_=="CalculateWoodie") return(0);
            
   if (shiftRight) 
   {
      Shift = 20;
   }
   else
   {
      Shift = 0;
   }
   
   barsPerTimeFrame = MathMax(barsPerTimeFrame,21);      
   shortName =  "All Stochastic ("+K_Period+","+D_Period+","+Slowing+")";
   IndicatorShortName(shortName);
         
   for (int k =0;k <8; k++) 
   {
      SetIndexShift(k,Shift*(barsPerTimeFrame+50));
   }
   
   timeFrames = 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] = TimeFrameToString(time); 
         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 (k=i ;k>0; k--)
            {
               labels[k]  = labels[k-1];
               periods[k] = periods[k-1];
            }
            labels[0]  = tmpLbl;
            periods[0] = tmpPer;
         }
      }
   }
   indicatorName = WindowExpertName();                  
   return(0);
}


int deinit()
{
   for(int l=0;l<ArraySize(periods);l++) 
   {
         ObjectDelete(indicatorName+l);
         ObjectDelete(indicatorName+l+"label");
   }         
   return(0);
}


//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

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

   minValue =  0;
   maxValue = 100;
   
   for(int p=0; p<ArraySize(periods);p++)
   {
      for(int i=0; i<barsPerTimeFrame;i++,k++)
      {
         buffer1[k] = iStochastic(NULL, periods[p], K_Period, D_Period, Slowing, MA_Method, PriceField, 0, i);
         buffer2[k] = iStochastic(NULL, periods[p], K_Period, D_Period, Slowing, MA_Method, PriceField, 1, i);
        
         // checkMinMax(k);
      }
      
      buffer1[k] = EMPTY_VALUE;
      buffer2[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)-5));
      ObjectSetText(separator,labels[p],9,"Arial",txtColor);
   }

   for(p=0; p<ArraySize(periods);p++) 
   {
      separator = indicatorName+p;
      ObjectSet(separator,OBJPROP_PRICE1,minValue);
      ObjectSet(separator,OBJPROP_PRICE2,maxValue);
      separator = indicatorName+p+"label";
      ObjectSet(separator,OBJPROP_PRICE1,maxValue);
   }

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


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

int stringToTimeFrame(string tfs)
{
   int tf=0;
       tfs = StringUpperCase(tfs);
       
         if (tfs=="M1" || tfs=="1")       tf=PERIOD_M1;
         if (tfs=="M5" || tfs=="5")       tf=PERIOD_M5;
         if (tfs=="M15"|| tfs=="15")      tf=PERIOD_M15;
         if (tfs=="M30"|| tfs=="30")      tf=PERIOD_M30;
         if (tfs=="H1" || tfs=="60")      tf=PERIOD_H1;
         if (tfs=="H4" || tfs=="240")     tf=PERIOD_H4;
         if (tfs=="D1" || tfs=="1440")    tf=PERIOD_D1;
         if (tfs=="W1" || tfs=="10080")   tf=PERIOD_W1;
         if (tfs=="MN" || tfs=="43200")   tf=PERIOD_MN1;
         
   return(tf);
}
string TimeFrameToString(int tf)
{
   string tfs="Current time frame";
   switch(tf) {
      case PERIOD_M1:  tfs="M1"  ; break;
      case PERIOD_M5:  tfs="M5"  ; break;
      case PERIOD_M15: tfs="M15" ; break;
      case PERIOD_M30: tfs="M30" ; break;
      case PERIOD_H1:  tfs="H1"  ; break;
      case PERIOD_H4:  tfs="H4"  ; break;
      case PERIOD_D1:  tfs="D1"  ; break;
      case PERIOD_W1:  tfs="W1"  ; break;
      case PERIOD_MN1: tfs="MN1";
   }
   return(tfs);
}


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


Indicators Used:

Stochastic oscillator


Custom Indicators Used:

Order Management characteristics:

Other Features: