Re: Stochastic indicators for MT4

841
Hi Mrtools

I have Jurik Stocahstics coded here in forex station

i like it but i will like you to add for me arrow on color change (on chart arrows), interpolation and also make it MTF

i appreciate all you're doing for me

Thanks in advance

Attached code below

Code: Select all

//+------------------------------------------------------------------
//|
//+------------------------------------------------------------------
#property copyright "www.forex-station.com"
#property link      "www.forex-station.com"

#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1  clrRed
#property indicator_color2  clrLimeGreen
#property indicator_color3  clrLimeGreen
#property indicator_width1  3
#property indicator_width2  3
#property indicator_width3  3
#property indicator_minimum  -5
#property indicator_maximum 105
#property strict

//
//
//
//
//

enum enPrices
{
   pr_close,      // Close
   pr_open,       // Open
   pr_high,       // High
   pr_low,        // Low
   pr_median,     // Median
   pr_typical,    // Typical
   pr_weighted,   // Weighted
   pr_average,    // Average (high+low+open+close)/4
   pr_medianb,    // Average median body (open+close)/2
   pr_tbiased,    // Trend biased price
   pr_tbiased2,   // Trend biased (extreme) price
   pr_haclose,    // Heiken ashi close
   pr_haopen ,    // Heiken ashi open
   pr_hahigh,     // Heiken ashi high
   pr_halow,      // Heiken ashi low
   pr_hamedian,   // Heiken ashi median
   pr_hatypical,  // Heiken ashi typical
   pr_haweighted, // Heiken ashi weighted
   pr_haaverage,  // Heiken ashi average
   pr_hamedianb,  // Heiken ashi median body
   pr_hatbiased,  // Heiken ashi trend biased price
   pr_hatbiased2, // Heiken ashi trend biased (extreme) price
   pr_habclose,   // Heiken ashi (better formula) close
   pr_habopen ,   // Heiken ashi (better formula) open
   pr_habhigh,    // Heiken ashi (better formula) high
   pr_hablow,     // Heiken ashi (better formula) low
   pr_habmedian,  // Heiken ashi (better formula) median
   pr_habtypical, // Heiken ashi (better formula) typical
   pr_habweighted,// Heiken ashi (better formula) weighted
   pr_habaverage, // Heiken ashi (better formula) average
   pr_habmedianb, // Heiken ashi (better formula) median body
   pr_habtbiased, // Heiken ashi (better formula) trend biased price
   pr_habtbiased2 // Heiken ashi (better formula) trend biased (extreme) price
};

extern int            StochasticPeriod = 55;           // Stochastic period
extern int            JmaLength1       = 10;           // First jma smoothing length
extern double         JmaPhase1        = 0;            // First jma smoothing phase
extern bool           JmaDouble1       = false;        // First jma smoothing double smooth
extern int            JmaLength2       = 10;           // Second jma smoothing length
extern double         JmaPhase2        = 0;            // Second jma smoothing phase
extern bool           JmaDouble2       = false;        // Second jma smoothing double smooth
extern enPrices       PriceForHigh     = pr_high;      // Price to use for high
extern enPrices       PriceForLow      = pr_low;       // Price to use for low
extern enPrices       PriceForClose    = pr_close;     // Price to use for close
extern double         UpLevel          = 80.0;         // Overbought level
extern double         DnLevel          = 20.0;         // Oversold level

double stoch[],stoUp[],stoDn[],calcBuffer[],prh[],prl[],trend[];


//------------------------------------------------------------------
//
//------------------------------------------------------------------
//
//
//
//

int init()
{
   IndicatorBuffers(7);
   SetIndexBuffer(0,stoch);  
   SetIndexBuffer(1,stoUp);  
   SetIndexBuffer(2,stoDn);   
   SetIndexBuffer(3,calcBuffer);
   SetIndexBuffer(4,prh);
   SetIndexBuffer(5,prl);
   SetIndexBuffer(6,trend);
   SetLevelValue(0,UpLevel);
   SetLevelValue(1,DnLevel);
   IndicatorShortName("Double jurik smoothed stochastic ("+(string)StochasticPeriod+","+(string)JmaLength1+","+(string)JmaLength2+")");
return(0);
}
int deinit() {   return(0); }
  
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
//
//
//
//
//

int start()
{
   int counted_bars=IndicatorCounted();
      if(counted_bars < 0) return(-1);
      if(counted_bars>0) counted_bars--;
         int limit = fmin(Bars-counted_bars,Bars-1);

   //
   //
   //
   //
   //
   
   if (trend[limit]==1) CleanPoint(limit,stoUp,stoDn);
   double prices[3];
   for(int i = limit; i >= 0; i--)
   {
       prices[0] = getPrice(PriceForHigh ,Open,Close,High,Low,i,Bars,0);
       prices[1] = getPrice(PriceForClose,Open,Close,High,Low,i,Bars,1);
       prices[2] = getPrice(PriceForLow  ,Open,Close,High,Low,i,Bars,2);
       ArraySort(prices);
       prl[i] = prices[0];
       prh[i] = prices[2];
       double max = prh[i], min = prl[i];
               for(int k=1; k<StochasticPeriod && (i+k)<Bars; k++)
               {
                  max = fmax(max,prh[i+k]);
                  min = fmin(min,prl[i+k]);
               }               
       double sto = (max!=min) ? (prices[1]-min)/(max-min)*100.00 : 0;
       calcBuffer[i] = iDSmooth(sto,JmaLength1,JmaPhase1,JmaDouble1,i,0);
            
      //
      //
      //
      //
      //
      
      max = calcBuffer[i];  min = calcBuffer[i];
               for(int k=1; k<StochasticPeriod && (i+k)<Bars; k++)
               {
                  max = fmax(max,calcBuffer[i+k]);
                  min = fmin(min,calcBuffer[i+k]);
               }               
      sto = (max!=min) ? (calcBuffer[i]-min)/(max-min)*100.00 : 0;
      stoch[i] = iDSmooth(iDSmooth(sto,JmaLength1,JmaPhase1,JmaDouble1,i,20),JmaLength2,JmaPhase2,JmaDouble2,i,40);
      stoUp[i] = EMPTY_VALUE;
      stoDn[i] = EMPTY_VALUE;
      trend[i] = (i<Bars-1) ? (stoch[i] > stoch[i+1]) ? 1 : (stoch[i] < stoch[i+1]) ? -1 : trend[i+1] : 0;      
      if (trend[i] == 1) PlotPoint(i,stoUp,stoDn,stoch);
   }   
return(0);
}

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

double wrk[][60];

#define bsmax  5
#define bsmin  6
#define volty  7
#define vsum   8
#define avolty 9

double iDSmooth(double price, double length, double phase, bool isDouble, int i, int s=0) 
{
   if (isDouble)
         return (iSmooth(iSmooth(price,MathSqrt(length),phase,i,s),MathSqrt(length),phase,i,s+10));
   else  return (iSmooth(price,length,phase,i,s));
}

//
//
//
//
//

double iSmooth(double price, double length, double phase, int i, int s=0)
{
   if (length <=1) return(price);
   if (ArrayRange(wrk,0) != Bars) ArrayResize(wrk,Bars);
   
   int r = Bars-i-1; 
      if (r==0) { int k; for(k=0; k<7; k++) wrk[r][k+s]=price; for(; k<10; k++) wrk[r][k+s]=0; return(price); }

   //
   //
   //
   //
   //
   
      double len1   = MathMax(MathLog(MathSqrt(0.5*(length-1)))/MathLog(2.0)+2.0,0);
      double pow1   = MathMax(len1-2.0,0.5);
      double del1   = price - wrk[r-1][bsmax+s];
      double del2   = price - wrk[r-1][bsmin+s];
      double div    = 1.0/(10.0+10.0*(MathMin(MathMax(length-10,0),100))/100);
      int    forBar = MathMin(r,10);
	
         wrk[r][volty+s] = 0;
               if(MathAbs(del1) > MathAbs(del2)) wrk[r][volty+s] = MathAbs(del1); 
               if(MathAbs(del1) < MathAbs(del2)) wrk[r][volty+s] = MathAbs(del2); 
         wrk[r][vsum+s] =	wrk[r-1][vsum+s] + (wrk[r][volty+s]-wrk[r-forBar][volty+s])*div;
         
         //
         //
         //
         //
         //
   
         wrk[r][avolty+s] = wrk[r-1][avolty+s]+(2.0/(MathMax(4.0*length,30)+1.0))*(wrk[r][vsum+s]-wrk[r-1][avolty+s]);
            double dVolty = 0;
            if (wrk[r][avolty+s] > 0)
                  dVolty = wrk[r][volty+s]/wrk[r][avolty+s];   
	               if (dVolty > MathPow(len1,1.0/pow1)) dVolty = MathPow(len1,1.0/pow1);
                  if (dVolty < 1)                      dVolty = 1.0;

      //
      //
      //
      //
      //
	        
   	double pow2 = MathPow(dVolty, pow1);
      double len2 = MathSqrt(0.5*(length-1))*len1;
      double Kv   = MathPow(len2/(len2+1), MathSqrt(pow2));

         if (del1 > 0) wrk[r][bsmax+s] = price; else wrk[r][bsmax+s] = price - Kv*del1;
         if (del2 < 0) wrk[r][bsmin+s] = price; else wrk[r][bsmin+s] = price - Kv*del2;
	
   //
   //
   //
   //
   //
      
      double R     = MathMax(MathMin(phase,100),-100)/100.0 + 1.5;
      double beta  = 0.45*(length-1)/(0.45*(length-1)+2);
      double alpha = MathPow(beta,pow2);

         wrk[r][0+s] = price + alpha*(wrk[r-1][0+s]-price);
         wrk[r][1+s] = (price - wrk[r][0+s])*(1-beta) + beta*wrk[r-1][1+s];
         wrk[r][2+s] = (wrk[r][0+s] + R*wrk[r][1+s]);
         wrk[r][3+s] = (wrk[r][2+s] - wrk[r-1][4+s])*MathPow((1-alpha),2) + MathPow(alpha,2)*wrk[r-1][3+s];
         wrk[r][4+s] = (wrk[r-1][4+s] + wrk[r][3+s]); 

   //
   //
   //
   //
   //

   return(wrk[r][4+s]);
}

//------------------------------------------------------------------
//
//------------------------------------------------------------------
//
//
//
//
//

#define _prHABF(_prtype) (_prtype>=pr_habclose && _prtype<=pr_habtbiased2)
#define _priceInstances     3
#define _priceInstancesSize 4
double workHa[][_priceInstances*_priceInstancesSize];
double getPrice(int tprice, const double& open[], const double& close[], const double& high[], const double& low[], int i, int bars, int instanceNo=0)
{
  if (tprice>=pr_haclose)
   {
      if (ArrayRange(workHa,0)!= Bars) ArrayResize(workHa,Bars); instanceNo*=_priceInstancesSize; int r = bars-i-1;
         
         //
         //
         //
         //
         //
         
         double haOpen  = (r>0) ? (workHa[r-1][instanceNo+2] + workHa[r-1][instanceNo+3])/2.0 : (open[i]+close[i])/2;;
         double haClose = (open[i]+high[i]+low[i]+close[i]) / 4.0;
         if (_prHABF(tprice))
               if (high[i]!=low[i])
                     haClose = (open[i]+close[i])/2.0+(((close[i]-open[i])/(high[i]-low[i]))*MathAbs((close[i]-open[i])/2.0));
               else  haClose = (open[i]+close[i])/2.0; 
         double haHigh  = fmax(high[i], fmax(haOpen,haClose));
         double haLow   = fmin(low[i] , fmin(haOpen,haClose));

         //
         //
         //
         //
         //
         
         if(haOpen<haClose) { workHa[r][instanceNo+0] = haLow;  workHa[r][instanceNo+1] = haHigh; } 
         else               { workHa[r][instanceNo+0] = haHigh; workHa[r][instanceNo+1] = haLow;  } 
                              workHa[r][instanceNo+2] = haOpen;
                              workHa[r][instanceNo+3] = haClose;
         //
         //
         //
         //
         //
         
         switch (tprice)
         {
            case pr_haclose:
            case pr_habclose:    return(haClose);
            case pr_haopen:   
            case pr_habopen:     return(haOpen);
            case pr_hahigh: 
            case pr_habhigh:     return(haHigh);
            case pr_halow:    
            case pr_hablow:      return(haLow);
            case pr_hamedian:
            case pr_habmedian:   return((haHigh+haLow)/2.0);
            case pr_hamedianb:
            case pr_habmedianb:  return((haOpen+haClose)/2.0);
            case pr_hatypical:
            case pr_habtypical:  return((haHigh+haLow+haClose)/3.0);
            case pr_haweighted:
            case pr_habweighted: return((haHigh+haLow+haClose+haClose)/4.0);
            case pr_haaverage:  
            case pr_habaverage:  return((haHigh+haLow+haClose+haOpen)/4.0);
            case pr_hatbiased:
            case pr_habtbiased:
               if (haClose>haOpen)
                     return((haHigh+haClose)/2.0);
               else  return((haLow+haClose)/2.0);        
            case pr_hatbiased2:
            case pr_habtbiased2:
               if (haClose>haOpen)  return(haHigh);
               if (haClose<haOpen)  return(haLow);
                                    return(haClose);        
         }
   }
   
   //
   //
   //
   //
   //
   
   switch (tprice)
   {
      case pr_close:     return(close[i]);
      case pr_open:      return(open[i]);
      case pr_high:      return(high[i]);
      case pr_low:       return(low[i]);
      case pr_median:    return((high[i]+low[i])/2.0);
      case pr_medianb:   return((open[i]+close[i])/2.0);
      case pr_typical:   return((high[i]+low[i]+close[i])/3.0);
      case pr_weighted:  return((high[i]+low[i]+close[i]+close[i])/4.0);
      case pr_average:   return((high[i]+low[i]+close[i]+open[i])/4.0);
      case pr_tbiased:   
               if (close[i]>open[i])
                     return((high[i]+close[i])/2.0);
               else  return((low[i]+close[i])/2.0);        
      case pr_tbiased2:   
               if (close[i]>open[i]) return(high[i]);
               if (close[i]<open[i]) return(low[i]);
                                     return(close[i]);        
   }
   return(0);
}

//-------------------------------------------------------------------
//                                                                  
//-------------------------------------------------------------------
//
//
//
//
//

void CleanPoint(int i,double& first[],double& second[])
{
   if (i>=Bars-3) return;
   if ((second[i]  != EMPTY_VALUE) && (second[i+1] != EMPTY_VALUE))
        second[i+1] = EMPTY_VALUE;
   else
      if ((first[i] != EMPTY_VALUE) && (first[i+1] != EMPTY_VALUE) && (first[i+2] == EMPTY_VALUE))
          first[i+1] = EMPTY_VALUE;
}

void PlotPoint(int i,double& first[],double& second[],double& from[])
{
   if (i>=Bars-2) return;
   if (first[i+1] == EMPTY_VALUE)
      if (first[i+2] == EMPTY_VALUE) 
            { first[i]  = from[i]; first[i+1]  = from[i+1]; second[i] = EMPTY_VALUE; }
      else  { second[i] = from[i]; second[i+1] = from[i+1]; first[i]  = EMPTY_VALUE; }
   else     { first[i]  = from[i];                          second[i] = EMPTY_VALUE; }
}



That which can Kill can also Save.How you use it makes the Difference.


Re: Stochastic indicators for MT4

842
rexey wrote: Mon Jun 13, 2022 9:15 am Hi Mrtools

I have Jurik Stocahstics coded here in forex station

i like it but i will like you to add for me arrow on color change (on chart arrows), interpolation and also make it MTF

i appreciate all you're doing for me

Thanks in advance

Attached code below

Code: Select all

//+------------------------------------------------------------------
//|
//+------------------------------------------------------------------
#property copyright "www.forex-station.com"
#property link      "www.forex-station.com"

#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1  clrRed
#property indicator_color2  clrLimeGreen
#property indicator_color3  clrLimeGreen
#property indicator_width1  3
#property indicator_width2  3
#property indicator_width3  3
#property indicator_minimum  -5
#property indicator_maximum 105
#property strict

//
//
//
//
//

enum enPrices
{
   pr_close,      // Close
   pr_open,       // Open
   pr_high,       // High
   pr_low,        // Low
   pr_median,     // Median
   pr_typical,    // Typical
   pr_weighted,   // Weighted
   pr_average,    // Average (high+low+open+close)/4
   pr_medianb,    // Average median body (open+close)/2
   pr_tbiased,    // Trend biased price
   pr_tbiased2,   // Trend biased (extreme) price
   pr_haclose,    // Heiken ashi close
   pr_haopen ,    // Heiken ashi open
   pr_hahigh,     // Heiken ashi high
   pr_halow,      // Heiken ashi low
   pr_hamedian,   // Heiken ashi median
   pr_hatypical,  // Heiken ashi typical
   pr_haweighted, // Heiken ashi weighted
   pr_haaverage,  // Heiken ashi average
   pr_hamedianb,  // Heiken ashi median body
   pr_hatbiased,  // Heiken ashi trend biased price
   pr_hatbiased2, // Heiken ashi trend biased (extreme) price
   pr_habclose,   // Heiken ashi (better formula) close
   pr_habopen ,   // Heiken ashi (better formula) open
   pr_habhigh,    // Heiken ashi (better formula) high
   pr_hablow,     // Heiken ashi (better formula) low
   pr_habmedian,  // Heiken ashi (better formula) median
   pr_habtypical, // Heiken ashi (better formula) typical
   pr_habweighted,// Heiken ashi (better formula) weighted
   pr_habaverage, // Heiken ashi (better formula) average
   pr_habmedianb, // Heiken ashi (better formula) median body
   pr_habtbiased, // Heiken ashi (better formula) trend biased price
   pr_habtbiased2 // Heiken ashi (better formula) trend biased (extreme) price
};

extern int            StochasticPeriod = 55;           // Stochastic period
extern int            JmaLength1       = 10;           // First jma smoothing length
extern double         JmaPhase1        = 0;            // First jma smoothing phase
extern bool           JmaDouble1       = false;        // First jma smoothing double smooth
extern int            JmaLength2       = 10;           // Second jma smoothing length
extern double         JmaPhase2        = 0;            // Second jma smoothing phase
extern bool           JmaDouble2       = false;        // Second jma smoothing double smooth
extern enPrices       PriceForHigh     = pr_high;      // Price to use for high
extern enPrices       PriceForLow      = pr_low;       // Price to use for low
extern enPrices       PriceForClose    = pr_close;     // Price to use for close
extern double         UpLevel          = 80.0;         // Overbought level
extern double         DnLevel          = 20.0;         // Oversold level

double stoch[],stoUp[],stoDn[],calcBuffer[],prh[],prl[],trend[];


//------------------------------------------------------------------
//
//------------------------------------------------------------------
//
//
//
//

int init()
{
   IndicatorBuffers(7);
   SetIndexBuffer(0,stoch);  
   SetIndexBuffer(1,stoUp);  
   SetIndexBuffer(2,stoDn);   
   SetIndexBuffer(3,calcBuffer);
   SetIndexBuffer(4,prh);
   SetIndexBuffer(5,prl);
   SetIndexBuffer(6,trend);
   SetLevelValue(0,UpLevel);
   SetLevelValue(1,DnLevel);
   IndicatorShortName("Double jurik smoothed stochastic ("+(string)StochasticPeriod+","+(string)JmaLength1+","+(string)JmaLength2+")");
return(0);
}
int deinit() {   return(0); }
  
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
//
//
//
//
//

int start()
{
   int counted_bars=IndicatorCounted();
      if(counted_bars < 0) return(-1);
      if(counted_bars>0) counted_bars--;
         int limit = fmin(Bars-counted_bars,Bars-1);

   //
   //
   //
   //
   //
   
   if (trend[limit]==1) CleanPoint(limit,stoUp,stoDn);
   double prices[3];
   for(int i = limit; i >= 0; i--)
   {
       prices[0] = getPrice(PriceForHigh ,Open,Close,High,Low,i,Bars,0);
       prices[1] = getPrice(PriceForClose,Open,Close,High,Low,i,Bars,1);
       prices[2] = getPrice(PriceForLow  ,Open,Close,High,Low,i,Bars,2);
       ArraySort(prices);
       prl[i] = prices[0];
       prh[i] = prices[2];
       double max = prh[i], min = prl[i];
               for(int k=1; k<StochasticPeriod && (i+k)<Bars; k++)
               {
                  max = fmax(max,prh[i+k]);
                  min = fmin(min,prl[i+k]);
               }               
       double sto = (max!=min) ? (prices[1]-min)/(max-min)*100.00 : 0;
       calcBuffer[i] = iDSmooth(sto,JmaLength1,JmaPhase1,JmaDouble1,i,0);
            
      //
      //
      //
      //
      //
      
      max = calcBuffer[i];  min = calcBuffer[i];
               for(int k=1; k<StochasticPeriod && (i+k)<Bars; k++)
               {
                  max = fmax(max,calcBuffer[i+k]);
                  min = fmin(min,calcBuffer[i+k]);
               }               
      sto = (max!=min) ? (calcBuffer[i]-min)/(max-min)*100.00 : 0;
      stoch[i] = iDSmooth(iDSmooth(sto,JmaLength1,JmaPhase1,JmaDouble1,i,20),JmaLength2,JmaPhase2,JmaDouble2,i,40);
      stoUp[i] = EMPTY_VALUE;
      stoDn[i] = EMPTY_VALUE;
      trend[i] = (i<Bars-1) ? (stoch[i] > stoch[i+1]) ? 1 : (stoch[i] < stoch[i+1]) ? -1 : trend[i+1] : 0;      
      if (trend[i] == 1) PlotPoint(i,stoUp,stoDn,stoch);
   }   
return(0);
}

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

double wrk[][60];

#define bsmax  5
#define bsmin  6
#define volty  7
#define vsum   8
#define avolty 9

double iDSmooth(double price, double length, double phase, bool isDouble, int i, int s=0) 
{
   if (isDouble)
         return (iSmooth(iSmooth(price,MathSqrt(length),phase,i,s),MathSqrt(length),phase,i,s+10));
   else  return (iSmooth(price,length,phase,i,s));
}

//
//
//
//
//

double iSmooth(double price, double length, double phase, int i, int s=0)
{
   if (length <=1) return(price);
   if (ArrayRange(wrk,0) != Bars) ArrayResize(wrk,Bars);
   
   int r = Bars-i-1; 
      if (r==0) { int k; for(k=0; k<7; k++) wrk[r][k+s]=price; for(; k<10; k++) wrk[r][k+s]=0; return(price); }

   //
   //
   //
   //
   //
   
      double len1   = MathMax(MathLog(MathSqrt(0.5*(length-1)))/MathLog(2.0)+2.0,0);
      double pow1   = MathMax(len1-2.0,0.5);
      double del1   = price - wrk[r-1][bsmax+s];
      double del2   = price - wrk[r-1][bsmin+s];
      double div    = 1.0/(10.0+10.0*(MathMin(MathMax(length-10,0),100))/100);
      int    forBar = MathMin(r,10);
	
         wrk[r][volty+s] = 0;
               if(MathAbs(del1) > MathAbs(del2)) wrk[r][volty+s] = MathAbs(del1); 
               if(MathAbs(del1) < MathAbs(del2)) wrk[r][volty+s] = MathAbs(del2); 
         wrk[r][vsum+s] =	wrk[r-1][vsum+s] + (wrk[r][volty+s]-wrk[r-forBar][volty+s])*div;
         
         //
         //
         //
         //
         //
   
         wrk[r][avolty+s] = wrk[r-1][avolty+s]+(2.0/(MathMax(4.0*length,30)+1.0))*(wrk[r][vsum+s]-wrk[r-1][avolty+s]);
            double dVolty = 0;
            if (wrk[r][avolty+s] > 0)
                  dVolty = wrk[r][volty+s]/wrk[r][avolty+s];   
	               if (dVolty > MathPow(len1,1.0/pow1)) dVolty = MathPow(len1,1.0/pow1);
                  if (dVolty < 1)                      dVolty = 1.0;

      //
      //
      //
      //
      //
	        
   	double pow2 = MathPow(dVolty, pow1);
      double len2 = MathSqrt(0.5*(length-1))*len1;
      double Kv   = MathPow(len2/(len2+1), MathSqrt(pow2));

         if (del1 > 0) wrk[r][bsmax+s] = price; else wrk[r][bsmax+s] = price - Kv*del1;
         if (del2 < 0) wrk[r][bsmin+s] = price; else wrk[r][bsmin+s] = price - Kv*del2;
	
   //
   //
   //
   //
   //
      
      double R     = MathMax(MathMin(phase,100),-100)/100.0 + 1.5;
      double beta  = 0.45*(length-1)/(0.45*(length-1)+2);
      double alpha = MathPow(beta,pow2);

         wrk[r][0+s] = price + alpha*(wrk[r-1][0+s]-price);
         wrk[r][1+s] = (price - wrk[r][0+s])*(1-beta) + beta*wrk[r-1][1+s];
         wrk[r][2+s] = (wrk[r][0+s] + R*wrk[r][1+s]);
         wrk[r][3+s] = (wrk[r][2+s] - wrk[r-1][4+s])*MathPow((1-alpha),2) + MathPow(alpha,2)*wrk[r-1][3+s];
         wrk[r][4+s] = (wrk[r-1][4+s] + wrk[r][3+s]); 

   //
   //
   //
   //
   //

   return(wrk[r][4+s]);
}

//------------------------------------------------------------------
//
//------------------------------------------------------------------
//
//
//
//
//

#define _prHABF(_prtype) (_prtype>=pr_habclose && _prtype<=pr_habtbiased2)
#define _priceInstances     3
#define _priceInstancesSize 4
double workHa[][_priceInstances*_priceInstancesSize];
double getPrice(int tprice, const double& open[], const double& close[], const double& high[], const double& low[], int i, int bars, int instanceNo=0)
{
  if (tprice>=pr_haclose)
   {
      if (ArrayRange(workHa,0)!= Bars) ArrayResize(workHa,Bars); instanceNo*=_priceInstancesSize; int r = bars-i-1;
         
         //
         //
         //
         //
         //
         
         double haOpen  = (r>0) ? (workHa[r-1][instanceNo+2] + workHa[r-1][instanceNo+3])/2.0 : (open[i]+close[i])/2;;
         double haClose = (open[i]+high[i]+low[i]+close[i]) / 4.0;
         if (_prHABF(tprice))
               if (high[i]!=low[i])
                     haClose = (open[i]+close[i])/2.0+(((close[i]-open[i])/(high[i]-low[i]))*MathAbs((close[i]-open[i])/2.0));
               else  haClose = (open[i]+close[i])/2.0; 
         double haHigh  = fmax(high[i], fmax(haOpen,haClose));
         double haLow   = fmin(low[i] , fmin(haOpen,haClose));

         //
         //
         //
         //
         //
         
         if(haOpen<haClose) { workHa[r][instanceNo+0] = haLow;  workHa[r][instanceNo+1] = haHigh; } 
         else               { workHa[r][instanceNo+0] = haHigh; workHa[r][instanceNo+1] = haLow;  } 
                              workHa[r][instanceNo+2] = haOpen;
                              workHa[r][instanceNo+3] = haClose;
         //
         //
         //
         //
         //
         
         switch (tprice)
         {
            case pr_haclose:
            case pr_habclose:    return(haClose);
            case pr_haopen:   
            case pr_habopen:     return(haOpen);
            case pr_hahigh: 
            case pr_habhigh:     return(haHigh);
            case pr_halow:    
            case pr_hablow:      return(haLow);
            case pr_hamedian:
            case pr_habmedian:   return((haHigh+haLow)/2.0);
            case pr_hamedianb:
            case pr_habmedianb:  return((haOpen+haClose)/2.0);
            case pr_hatypical:
            case pr_habtypical:  return((haHigh+haLow+haClose)/3.0);
            case pr_haweighted:
            case pr_habweighted: return((haHigh+haLow+haClose+haClose)/4.0);
            case pr_haaverage:  
            case pr_habaverage:  return((haHigh+haLow+haClose+haOpen)/4.0);
            case pr_hatbiased:
            case pr_habtbiased:
               if (haClose>haOpen)
                     return((haHigh+haClose)/2.0);
               else  return((haLow+haClose)/2.0);        
            case pr_hatbiased2:
            case pr_habtbiased2:
               if (haClose>haOpen)  return(haHigh);
               if (haClose<haOpen)  return(haLow);
                                    return(haClose);        
         }
   }
   
   //
   //
   //
   //
   //
   
   switch (tprice)
   {
      case pr_close:     return(close[i]);
      case pr_open:      return(open[i]);
      case pr_high:      return(high[i]);
      case pr_low:       return(low[i]);
      case pr_median:    return((high[i]+low[i])/2.0);
      case pr_medianb:   return((open[i]+close[i])/2.0);
      case pr_typical:   return((high[i]+low[i]+close[i])/3.0);
      case pr_weighted:  return((high[i]+low[i]+close[i]+close[i])/4.0);
      case pr_average:   return((high[i]+low[i]+close[i]+open[i])/4.0);
      case pr_tbiased:   
               if (close[i]>open[i])
                     return((high[i]+close[i])/2.0);
               else  return((low[i]+close[i])/2.0);        
      case pr_tbiased2:   
               if (close[i]>open[i]) return(high[i]);
               if (close[i]<open[i]) return(low[i]);
                                     return(close[i]);        
   }
   return(0);
}

//-------------------------------------------------------------------
//                                                                  
//-------------------------------------------------------------------
//
//
//
//
//

void CleanPoint(int i,double& first[],double& second[])
{
   if (i>=Bars-3) return;
   if ((second[i]  != EMPTY_VALUE) && (second[i+1] != EMPTY_VALUE))
        second[i+1] = EMPTY_VALUE;
   else
      if ((first[i] != EMPTY_VALUE) && (first[i+1] != EMPTY_VALUE) && (first[i+2] == EMPTY_VALUE))
          first[i+1] = EMPTY_VALUE;
}

void PlotPoint(int i,double& first[],double& second[],double& from[])
{
   if (i>=Bars-2) return;
   if (first[i+1] == EMPTY_VALUE)
      if (first[i+2] == EMPTY_VALUE) 
            { first[i]  = from[i]; first[i+1]  = from[i+1]; second[i] = EMPTY_VALUE; }
      else  { second[i] = from[i]; second[i+1] = from[i+1]; first[i]  = EMPTY_VALUE; }
   else     { first[i]  = from[i];                          second[i] = EMPTY_VALUE; }
}



Added interpolated mtf and arrows.
These users thanked the author mrtools for the post (total 3):
camisa, rexey, alexm

Re: Stochastic indicators for MT4

844
mrtools wrote: Mon Jun 13, 2022 12:34 pm Added interpolated mtf and arrows.
Hi Mrtools

I was shocked at how you responded quickly to my post. I can't thank you enough for giving my post this level of attention.

It is my fault for not specifying all the options i needed on the stochastics jurik. i need:

1. Arrows only (No sub indicator window)
2. Arrows on color change
3. Arrows on entering overbought/oversold
4. Arrows on leaving overbought/oversold
5. Mtf and interpolation
6. Alerts
7. Alerts on entering overbought/oversold
8 Alerts on leaving overbought/oversold

I want to use monitor trend direction on higher timeframes and then trade it following my setup on lower timeframe.

Your help is highly appreciated
That which can Kill can also Save.How you use it makes the Difference.


DislikeRe: Stochastic indicators for MT4

846
Take it easy on the listed requests mate you've just joined.

Urging you to read this before you post any more requests: Why was I banned from Forex-station? 🚷

rexey wrote: Mon Jun 13, 2022 7:01 pm I was shocked... i need:

1. Arrows only (No sub indicator window)
2. Arrows on color change
3. Arrows on entering overbought/oversold
4. Arrows on leaving overbought/oversold
5. Mtf and interpolation
6. Alerts
7. Alerts on entering overbought/oversold
8 Alerts on leaving overbought/oversold
These users thanked the author Jimmy for the post (total 3):
Jedidiah, moey_dw, kvak
Are you looking for a Forex broker? FBS cuts spreads by up to 58%. Click here to begin your trading journey, today.
No commissions are earned by Forex-station.


Guide to the "All Averages" Filters (ADXvma, Laguerre etc.) 🆕
Use Fibonacci numbers for indicator settings + How to draw Fibonacci Extensions
An easy trick for drawing Support & Resistance

Re: Stochastic indicators for MT4

847
Jimmy wrote: Tue Jun 14, 2022 6:43 pm Take it easy on the listed requests mate you've just joined.

Urging you to read this before you post any more requests: Why was I banned from Forex-station? 🚷
Yes, you are right Jimmy.
But for learning to make multiple instance of arrows, alerts I made this version for us......viewtopic.php?p=1295480269#p1295480269
These users thanked the author kvak for the post (total 3):
Jedidiah, Jimmy, rexey


Who is online

Users browsing this forum: alimpe2000 and 72 guests