//+------------------------------------------------------------------+
//|                                                WeightedStoch.mq4 |
//|                      Copyright © 2004, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link      "cgaw70@hotmail.com"

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 White
#property indicator_color2 Red


//---- input parameters
extern int K_Period=5; //15 / 5 /5 vir die 1-m !!!5M = 15/3/5.
extern int D_Period=3;
extern int Slowing=3;
extern int PriceField =0;
extern int ChartTime =15;

double stok1=0,stok2=0,stok3=0,stok4=0,stok5=0,stok6=0,stok7=0,stok8=0,stok9=0,stok10=0,mov=0,stoksmoothed=0,smoothing=15;
int shift=0, MAType=1, cnt=0,  prevbars=0,loopbegin=0;

bool first=true;
//---- buffers
double TrendBuffer[];
double LoBuffer[];
double HiBuffer[];
double PlusSdiBuffer[];
double MinusSdiBuffer[];
double TempBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- 3 additional buffers are used for counting.
   IndicatorBuffers(3);
//---- indicator buffers
   SetIndexBuffer(0,TrendBuffer);
   SetIndexBuffer(1,LoBuffer);
   
    SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2,White);
    SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,2,Red);
    IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("WeightedStochs");
   
   SetIndexDrawBegin(0,TrendBuffer);
   SetIndexDrawBegin(1,LoBuffer);
   
   return(0);
  }
//+------------------------------------------------------------------+
//| Average Directional Movement Index                               |
//+------------------------------------------------------------------+
int start()
  {
  // initial checkings
// check for additional bars loading or total reloading
if (Bars < prevbars )  first = true;
if (Bars-prevbars>1) first = true;
prevbars = Bars;
if (first) 
{
// loopbegin prevent couning of counted bars exclude current
loopbegin = Bars-1;
if (loopbegin < 0) return(0);      // not enough bars for counting


first = False;
   }
  
 
  loopbegin = loopbegin+1; 
 // Comment( loopbegin);            // current bar is to be recounted too
  for (shift = loopbegin; shift>= 0 ;shift--)
{

/*stok1 = (iStochastic(NULL,0,5,3,3,MODE_SMA,NULL,MODE_MAIN,shift))*0.148;
stok2 = (iStochastic(NULL,0,14,3,3,MODE_SMA,NULL,MODE_MAIN,shift))*0.411;
stok3 = (iStochastic(NULL,0,15,5,5,MODE_SMA,NULL,MODE_MAIN,shift))*0.441;
//stok4 = (iStochastic(NULL,0,34,8,3,MODE_SMA,NULL,MODE_MAIN,shift))*0.16;
//stok5 = (iStochastic(NULL,0,21,5,3,MODE_SMA,NULL,MODE_MAIN,shift))*0.10;
stok6 = (iStochastic(NULL,0,5,3,3,MODE_SMA,NULL,MODE_SIGNAL,shift))*0.273;
stok7 = (iStochastic(NULL,0,14,3,3,MODE_SMA,NULL,MODE_SIGNAL,shift))*0.273;
stok8 = (iStochastic(NULL,0,15,5,3,MODE_SMA,NULL,MODE_SIGNAL,shift))*0.454;
//stok9 = (iStochastic(NULL,0,34,8,3,MODE_SMA,NULL,MODE_SIGNAL,shift))*0.16;
//stok10 = (iStochastic(NULL,0,21,5,3,MODE_SMA,NULL,MODE_SIGNAL,shift))*0.10;
mov   = stok1+stok2+stok3;
stoksmoothed = stok6+stok7+stok8;
//stoksmoothed = mov/smoothing + LoBuffer[shift+1]*(smoothing-1)/smoothing;

TrendBuffer[shift]=mov;
LoBuffer[shift]=stoksmoothed;*/


/*stok2 = (iStochastic(NULL,0,5,3,3,MODE_SMA,NULL,MODE_MAIN,shift));
stok3 = (iStochastic(NULL,0,14,3,3,MODE_SMA,NULL,MODE_MAIN,shift));
stok4 = (iStochastic(NULL,0,15,5,5,MODE_SMA,NULL,MODE_MAIN,shift));
mov   = ((stok2+stok3+stok4)/3);
stok5 = (iStochastic(NULL,0,5,3,3,MODE_SMA,NULL,MODE_SIGNAL,shift));
stok6 = (iStochastic(NULL,0,14,3,3,MODE_SMA,NULL,MODE_SIGNAL,shift));
stok7 = (iStochastic(NULL,0,15,5,5,MODE_SMA,NULL,MODE_SIGNAL,shift));
stoksmoothed = ((stok5+stok6+stok7)/3);
TrendBuffer[shift]=mov;
LoBuffer[shift]=stoksmoothed;*/

if (ChartTime == 1 || ChartTime == 5)

//1,5,and15M Timeframe
{
stok1 = (iStochastic(NULL,1,K_Period,D_Period,Slowing,MODE_SMA,PriceField,MODE_MAIN,shift))*0.167;
stok2 = (iStochastic(NULL,5,K_Period,D_Period,Slowing,MODE_SMA,PriceField,MODE_MAIN,shift))*0.833;
stok6 = (iStochastic(NULL,1,K_Period,D_Period,Slowing,MODE_SMA,PriceField,MODE_SIGNAL,shift))*0.167;
stok7 = (iStochastic(NULL,5,K_Period,D_Period,Slowing,MODE_SMA,PriceField,MODE_SIGNAL,shift))*0.833;
}
if (ChartTime == 15)
//15M Timeframe
{
stok1 = (iStochastic(NULL,1,K_Period,D_Period,Slowing,MODE_SMA,PriceField,MODE_MAIN,shift))*0.048;
stok2 = (iStochastic(NULL,5,K_Period,D_Period,Slowing,MODE_SMA,PriceField,MODE_MAIN,shift))*0.238;
stok3 = (iStochastic(NULL,15,K_Period,D_Period,Slowing,MODE_SMA,PriceField,MODE_MAIN,shift))*0.714;
stok6 = (iStochastic(NULL,1,K_Period,D_Period,Slowing,MODE_SMA,PriceField,MODE_SIGNAL,shift))*0.048;
stok7 = (iStochastic(NULL,5,K_Period,D_Period,Slowing,MODE_SMA,PriceField,MODE_SIGNAL,shift))*0.238;
stok8 = (iStochastic(NULL,15,K_Period,D_Period,Slowing,MODE_SMA,PriceField,MODE_SIGNAL,shift))*0.714;
}
if (ChartTime == 30)
//30M Timeframe
{
stok1 = (iStochastic(NULL,5,K_Period,D_Period,Slowing,MODE_SMA,PriceField,MODE_MAIN,shift))*0.1;
stok2 = (iStochastic(NULL,15,K_Period,D_Period,Slowing,MODE_SMA,PriceField,MODE_MAIN,shift))*0.3;
stok3 = (iStochastic(NULL,30,K_Period,D_Period,Slowing,MODE_SMA,PriceField,MODE_MAIN,shift))*0.6;
stok6 = (iStochastic(NULL,5,K_Period,D_Period,Slowing,MODE_SMA,PriceField,MODE_SIGNAL,shift))*0.1;
stok7 = (iStochastic(NULL,15,K_Period,D_Period,Slowing,MODE_SMA,PriceField,MODE_SIGNAL,shift))*0.3;
stok8 = (iStochastic(NULL,30,K_Period,D_Period,Slowing,MODE_SMA,PriceField,MODE_SIGNAL,shift))*0.6;
}
if (ChartTime == 60)
//60M Timeframe
{
stok1 = (iStochastic(NULL,15,K_Period,D_Period,Slowing,MODE_SMA,PriceField,MODE_MAIN,shift))*0.143;
stok2 = (iStochastic(NULL,30,K_Period,D_Period,Slowing,MODE_SMA,PriceField,MODE_MAIN,shift))*0.286;
stok3 = (iStochastic(NULL,60,K_Period,D_Period,Slowing,MODE_SMA,PriceField,MODE_MAIN,shift))*0.571;
stok6 = (iStochastic(NULL,15,K_Period,D_Period,Slowing,MODE_SMA,PriceField,MODE_SIGNAL,shift))*0.143;
stok7 = (iStochastic(NULL,30,K_Period,D_Period,Slowing,MODE_SMA,PriceField,MODE_SIGNAL,shift))*0.286;
stok8 = (iStochastic(NULL,60,K_Period,D_Period,Slowing,MODE_SMA,PriceField,MODE_SIGNAL,shift))*0.571;
}

mov   = stok1+stok2+stok3+stok4+stok5;
stoksmoothed = stok6+stok7+stok8+stok9+stok10;
TrendBuffer[shift]=mov;
LoBuffer[shift]=stoksmoothed;






loopbegin = loopbegin-1;     
}}
return(0);
    // prevent to previous bars recounting