Adaptive lookback indicators - page 90

 
mladen:

mntiwana

I am afraid I do not understand the question. It already has HA prices

Dearest MLADEN

and poster

i am sorry if i was unable to describe exact my question/request but i was means about "price smoothing method" where we can chose one from any of 4 price options.picture attached........ and yes it has already HA prices in pane "rsi price to use"

regards

Files:
 
mntiwana:

Dearest MLADEN

and poster

i am sorry if i was unable to describe exact my question/request but i was means about "price smoothing method" where we can chose one from any of 4 price options.picture attached........ and yes it has already HA prices in pane "rsi price to use"

regards

mntiwana

You mean to add more averages types to rsi price smoothing option?

 
mladen:

mntiwana

You mean to add more averages types to rsi price smoothing option?

Dearest MLADEN

thanks to reply,i think if only one of HA prices (HA median body) will be added it can turn it more smooth and as a result possibly remove some extra false small signals,just my guess ........ aside from this,if it is possible to just add only one HA price in some indicator (HA median body) because in a lot of cases i experiment,this does a good job ...... and if i can know,is there any easy/short way to add only one HA price in some indicator.......... as an experiment,kindly can you try adding only one of this price.;)

regards

 
mladen:

Talaat E

This should be it : parabolic_sar_of_kama_1_4.mq4

Hello Mladen,

Can you please help me understand what is the difference in Parabolic SAR of KAMA 1_4.mq4 andParabolic SAR of KAMA.mq4 When I attache both the indicator on my chart (5 min) I am seeing difference while giving me the signal. can you please help me on this

Thanks

SKC

 
skc321:

Hello Mladen,

Can you please help me understand what is the difference in Parabolic SAR of KAMA 1_4.mq4 andParabolic SAR of KAMA.mq4 When I attache both the indicator on my chart (5 min) I am seeing difference while giving me the signal. can you please help me on this

Thanks

SKC

SKC

The difference is in options that can be used for displays (and what can be displayed) and the code is reworked. Also the whole code was made compatible with new metatrader 4 strict mode. But I do not see difference in signals between the two.

Can you provide us with examples and settings where the two are showing different signals?

 
skc321:

Hello Mladen,

Can you please help me understand what is the difference in Parabolic SAR of KAMA 1_4.mq4 andParabolic SAR of KAMA.mq4 When I attache both the indicator on my chart (5 min) I am seeing difference while giving me the signal. can you please help me on this

Thanks

SKC

The new version :


 
mladen, can you please add your big bundle of averages to Schaff Trend RSX (vhf adaptive) 2_4 as you did with Schaff Trend Cycle (vhf adaptive) averages? Thx a lot
 
krelian99:
mladen, can you please add your big bundle of averages to Schaff Trend RSX (vhf adaptive) 2_4 as you did with Schaff Trend Cycle (vhf adaptive) averages? Thx a lot

krelian99

As soon as the major issues of posting are solved, will do that

 
mladen:

The new version :


Forced to this way now - this is the newest version of parabolic SAR of Kaufman AMA :

//------------------------------------------------------------------
#property copyright "mladen"
#property link      "mladenfx@gmail.com"
#property description "file name Parabolic SAR of KAMA 1_5"
//------------------------------------------------------------------
#property indicator_chart_window
#property indicator_buffers 5
#property indicator_color1  clrDeepSkyBlue
#property indicator_color2  clrSandyBrown
#property indicator_color3  clrDeepSkyBlue
#property indicator_color4  clrSandyBrown
#property indicator_color5  clrSandyBrown
#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_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
};
enum enDisplayType
{
   dt_disSar,  // Display SAR value
   dt_disAma,  // Display Kaufman ama value
   dt_disAll   // Display both
};

extern ENUM_TIMEFRAMES TimeFrame = PERIOD_CURRENT; // Time frame to use
extern double    AccStep         = 0.02;      // Accumulation step
extern double    AccLimit        = 0.2;       // Accumulation limit
extern int       AmaPeriod       = 10;        // Kaufman AMA period
extern enPrices  AmaPrice        = pr_close;  // Price to be used by Kaufman AMA
extern double    FastEnd         = 2;         // Kaufman AMA fast end
extern double    SlowEnd         = 30;        // Kaufman AMA slow end
extern double    SmoothPower     = 2;         // Smooth power
extern bool      JurikFDAdaptive = true;      // Should the Kaufman AMA be Jurik fractal dimension adaptive?
extern enDisplayType DisplayType = dt_disSar; // What should be displayed?
extern int       LineWidth       = 2;         // Lines width
extern int       ArrowsWidth     = 0;         // Arrows (dots) width
extern bool      Interpolate     = true;      // Interpolate in multi time frame mode?

double sarUp[];
double sarDn[];
double ama[],amada[],amadb[];
string indicatorFileName;
bool   returnBars;

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

int init()
{
   int atype = DRAW_NONE; if (DisplayType!=dt_disSar) atype= DRAW_LINE;
   int stype = DRAW_NONE; if (DisplayType!=dt_disAma) stype= DRAW_ARROW;
   SetIndexBuffer(0,sarUp); SetIndexStyle(0,stype,EMPTY,ArrowsWidth); SetIndexArrow(0,159);
   SetIndexBuffer(1,sarDn); SetIndexStyle(1,stype,EMPTY,ArrowsWidth); SetIndexArrow(1,159);
   SetIndexBuffer(2,ama);   SetIndexStyle(2,atype,EMPTY,LineWidth);
   SetIndexBuffer(3,amada); SetIndexStyle(3,atype,EMPTY,LineWidth);
   SetIndexBuffer(4,amadb); SetIndexStyle(4,atype,EMPTY,LineWidth);
      indicatorFileName = WindowExpertName();
      returnBars        = TimeFrame==-99;
      TimeFrame         = MathMax(TimeFrame,_Period);
   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 = MathMin(Bars-counted_bars,Bars-1);
         if (returnBars) { sarUp[0] = limit+1; return(0); }

   //
   //
   //
   //
   //
    
   if (TimeFrame == Period())
   { 
      if (sarDn[limit]!=EMPTY_VALUE) CleanPoint(limit,amada,amadb);
      for(int i = limit; i >= 0; i--)
      {
         double sarClose;
         double sarOpen;
         double sarPosition;
         double sarChange;
         amada[i] = EMPTY_VALUE;
         amadb[i] = EMPTY_VALUE;
         ama[i]   = iKama(AmaPeriod,FastEnd,SlowEnd,AmaPrice,SmoothPower,JurikFDAdaptive,i);
            iParabolic(ama[i],ama[i],AccStep,AccLimit,sarClose,sarOpen,sarPosition,sarChange,i);
            sarUp[i] = EMPTY_VALUE;
            sarDn[i] = EMPTY_VALUE;
            if (sarPosition==1)
                  sarUp[i] = sarClose;
            else  sarDn[i] = sarClose;
            if (sarDn[i] != EMPTY_VALUE)PlotPoint(i,amada,amadb,ama);
      }
      return(0);
   }
   
   //
   //
   //
   //
   //
   
   limit = (int)MathMax(limit,MathMin(Bars-1,iCustom(NULL,TimeFrame,indicatorFileName,-99,0,0)*TimeFrame/Period()));
   if (sarDn[limit]!=EMPTY_VALUE) CleanPoint(limit,amada,amadb);
   for (int i=limit;i>=0;i--)
   {
      int y = iBarShift(NULL,TimeFrame,Time[i]);
         sarUp[i] = iCustom(NULL,TimeFrame,indicatorFileName,PERIOD_CURRENT,AccStep,AccLimit,AmaPeriod,AmaPrice,FastEnd,SlowEnd,SmoothPower,JurikFDAdaptive,0,y); 
         sarDn[i] = iCustom(NULL,TimeFrame,indicatorFileName,PERIOD_CURRENT,AccStep,AccLimit,AmaPeriod,AmaPrice,FastEnd,SlowEnd,SmoothPower,JurikFDAdaptive,1,y); 
         ama[i]   = iCustom(NULL,TimeFrame,indicatorFileName,PERIOD_CURRENT,AccStep,AccLimit,AmaPeriod,AmaPrice,FastEnd,SlowEnd,SmoothPower,JurikFDAdaptive,2,y); 
         amada[i] = EMPTY_VALUE;
         amadb[i] = EMPTY_VALUE;
         
         //
         //
         //
         //
         //
      
         if (!Interpolate || (i>0 && y==iBarShift(NULL,TimeFrame,Time[i-1]))) continue;
                  
         //
         //
         //
         //
         //
                  
         int n,j; datetime time = iTime(NULL,TimeFrame,y);
            for(n = 1; (i+n)<Bars && Time[i+n] >= time; n++) continue;  
            for(j = 1; j<n && (i+n)<Bars && (i+j)<Bars; j++)
            {
               ama[i+j] = ama[i] + (ama[i+n]-ama[i])*j/n;
               if (sarUp[i+n]!=EMPTY_VALUE && sarUp[i]!= EMPTY_VALUE) sarUp[i+j] = sarUp[i] + (sarUp[i+n]-sarUp[i])*j/n;
               if (sarDn[i+n]!=EMPTY_VALUE && sarDn[i]!= EMPTY_VALUE) sarDn[i+j] = sarDn[i] + (sarDn[i+n]-sarDn[i])*j/n;
            }
   }
   for (int i=limit;i>=0;i--) if (sarDn[i] != EMPTY_VALUE)PlotPoint(i,amada,amadb,ama);           
   return(0);       
}


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

double workAma[][3];
#define _diff  0
#define _kama  1
#define _price 2

double iKama(int period, double fast, double slow, int priceType, double power, bool JurikFD, int i)
{
   if (ArrayRange(workAma,0)!=Bars) ArrayResize(workAma,Bars);
   double price = getPrice(priceType,Open,Close,High,Low,i); int r = Bars-i-1; if (r<period) return(price);
   double fastend = (2.0 /(fast + 1));
   double slowend = (2.0 /(slow + 1));
   
   //
   //
   //
   //
   //

      double efratio=1; workAma[r][_price] = price;
      if (JurikFD) efratio = MathMin(2.0-iJurikFractalDimension(period,2,i),1.0);
      else
      {
         double signal = MathAbs(price-workAma[r-period][_price]);
         double noise  = 0;
            workAma[r][_diff] = MathAbs(price-workAma[r-1][_price]);
            for (int k=0; k<period; k++) 
                  noise += workAma[r-k][_diff];

            //
            //
            //
            //
            //

            if (noise != 0)
                  efratio = signal/noise;
            else  efratio = 1;
      }
      double smooth = MathPow(efratio*(fastend-slowend)+slowend,power);
          workAma[r][_kama] = workAma[r-1][_kama] + smooth*(price-workAma[r-1][_kama]);
   return(workAma[r][_kama]);
}

//
//
//
//
//

double workFd[][2];
#define _smlRange 0
#define _smlSumm  1

//
//
//
//
//

double iJurikFractalDimension(int size, int count,int i)
{
   if (ArrayRange(workFd,0)!=Bars) ArrayResize(workFd,Bars);

   int window1  = size*(count-1);
   int window2  = size* count;
   int r        = Bars-i-1;

   //
   //
   //
   //
   //

      workFd[r][_smlRange] = iFdRange(size,i);
      workFd[r][_smlSumm]  = workFd[r-1][_smlSumm]+workFd[r][_smlRange];
      
      if (r>=window1)
      {
         workFd[r][_smlSumm] -= workFd[r-window1][_smlRange];
         if (r>=window2)
               return(2.0-MathLog(iFdRange(window2,i)/(workFd[r][_smlSumm]/window1))/MathLog(count));
         else  return(0.5);   
      }
      else return(0.5);
}
double iFdRange(int size,int i) { return(MathMax(Close[size+i],High[ArrayMaximum(High,size,i)])-MathMin(Close[size+i],Low[ArrayMinimum(Low,size,i)]));} 

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

double work[][7];
#define _high     0
#define _low      1
#define _ohigh    2
#define _olow     3
#define _open     4
#define _position 5
#define _af       6


void iParabolic(double high, double low, double step, double limit, double& pClose, double& pOpen, double& pPosition, double& pChange, int i)
{
   if (ArrayRange(work,0)!=Bars) ArrayResize(work,Bars); i = Bars-i-1;
   
   //
   //
   //
   //
   //
   
      pChange = 0;
         work[i][_ohigh]    = high;
         work[i][_olow]     = low;
            if (i<1)
               {
                  work[i][_high]     = high;
                  work[i][_low]      = low;
                  work[i][_open]     = high;
                  work[i][_position] = -1;
                  return;
               }
         work[i][_open]     = work[i-1][_open];
         work[i][_af]       = work[i-1][_af];
         work[i][_position] = work[i-1][_position];
         work[i][_high]     = MathMax(work[i-1][_high],high);
         work[i][_low]      = MathMin(work[i-1][_low] ,low );
      
   //
   //
   //
   //
   //
            
   if (work[i][_position] == 1)
      if (low<=work[i][_open])
         {
            work[i][_position] = -1;
               pChange = -1;
               pClose  = work[i][_high];
                         work[i][_high] = high;
                         work[i][_low]  = low;
                         work[i][_af]   = step;
                         work[i][_open] = pClose + work[i][_af]*(work[i][_low]-pClose);
                            if (work[i][_open]<work[i  ][_ohigh]) work[i][_open] = work[i  ][_ohigh];
                            if (work[i][_open]<work[i-1][_ohigh]) work[i][_open] = work[i-1][_ohigh];
         }
      else
         {
               pClose = work[i][_open];
                    if (work[i][_high]>work[i-1][_high] && work[i][_af]<limit) work[i][_af] = MathMin(work[i][_af]+step,limit);
                        work[i][_open] = pClose + work[i][_af]*(work[i][_high]-pClose);
                            if (work[i][_open]>work[i  ][_olow]) work[i][_open] = work[i  ][_olow];
                            if (work[i][_open]>work[i-1][_olow]) work[i][_open] = work[i-1][_olow];
         }
   else
      if (high>=work[i][_open])
         {
            work[i][_position] = 1;
               pChange = 1;
               pClose  = work[i][_low];
                         work[i][_low]  = low;
                         work[i][_high] = high;
                         work[i][_af]   = step;
                         work[i][_open] = pClose + work[i][_af]*(work[i][_high]-pClose);
                            if (work[i][_open]>work[i  ][_olow]) work[i][_open] = work[i  ][_olow];
                            if (work[i][_open]>work[i-1][_olow]) work[i][_open] = work[i-1][_olow];
         }
      else
         {
               pClose = work[i][_open];
               if (work[i][_low]<work[i-1][_low] && work[i][_af]<limit) work[i][_af] = MathMin(work[i][_af]+step,limit);
                   work[i][_open] = pClose + work[i][_af]*(work[i][_low]-pClose);
                            if (work[i][_open]<work[i  ][_ohigh]) work[i][_open] = work[i  ][_ohigh];
                            if (work[i][_open]<work[i-1][_ohigh]) work[i][_open] = work[i-1][_ohigh];
         }

   //
   //
   //
   //
   //
   
   pOpen     = work[i][_open];
   pPosition = work[i][_position];
}

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

double workHa[][4];
double getPrice(int price, const double& open[], const double& close[], const double& high[], const double& low[], int i, int instanceNo=0)
{
  if (price>=pr_haclose)
   {
      if (ArrayRange(workHa,0)!= Bars) ArrayResize(workHa,Bars);
         int r = Bars-i-1;
         
         //
         //
         //
         //
         //
         
         double haOpen;
         if (r>0)
                haOpen  = (workHa[r-1][instanceNo+2] + workHa[r-1][instanceNo+3])/2.0;
         else   haOpen  = (open[i]+close[i])/2;
         double haClose = (open[i] + high[i] + low[i] + close[i]) / 4.0;
         double haHigh  = MathMax(high[i], MathMax(haOpen,haClose));
         double haLow   = MathMin(low[i] , MathMin(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 (price)
         {
            case pr_haclose:     return(haClose);
            case pr_haopen:      return(haOpen);
            case pr_hahigh:      return(haHigh);
            case pr_halow:       return(haLow);
            case pr_hamedian:    return((haHigh+haLow)/2.0);
            case pr_hamedianb:   return((haOpen+haClose)/2.0);
            case pr_hatypical:   return((haHigh+haLow+haClose)/3.0);
            case pr_haweighted:  return((haHigh+haLow+haClose+haClose)/4.0);
            case pr_haaverage:   return((haHigh+haLow+haClose+haOpen)/4.0);
            case pr_hatbiased:
               if (haClose>haOpen)
                     return((haHigh+haClose)/2.0);
               else  return((haLow+haClose)/2.0);        
         }
   }
   
   //
   //
   //
   //
   //
   
   switch (price)
   {
      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);        
   }
   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; }
}
 
mladen:

Forced to this way now - this is the newest version of parabolic SAR of Kaufman AMA :

It is working :)
Reason: