Download MetaTrader 5

Heiken Ashi Smoothed without using iCustom

To add comments, please log in or register
Find out how to install MetaTrader on Mac OS
xanderhinds
104
xanderhinds 2017.03.19 19:02 

Hi,


I'm trying to use the heiken ashi without using the iCustom call, am I on the right lines with this:

   int MaMetod=2;
   int MaPeriod = 24;
   int MaMetod2 = 3;
   int MaPeriod2= 2;

   double maOpen1=iMA(NULL,0,MaPeriod,0,MaMetod,PRICE_OPEN,1);
   double maClose1=iMA(NULL,0,MaPeriod,0,MaMetod,PRICE_CLOSE,1);
   double maLow1=iMA(NULL,0,MaPeriod,0,MaMetod,PRICE_LOW,1);
   double maHigh1=iMA(NULL,0,MaPeriod,0,MaMetod,PRICE_HIGH,1);
   double maOpen2=iMA(NULL,0,MaPeriod,0,MaMetod,PRICE_OPEN,2);
   double maClose2=iMA(NULL,0,MaPeriod,0,MaMetod,PRICE_CLOSE,2);
   double maLow2=iMA(NULL,0,MaPeriod,0,MaMetod,PRICE_LOW,2);
   double maHigh2=iMA(NULL,0,MaPeriod,0,MaMetod,PRICE_HIGH,2);
   double maOpen3=iMA(NULL,0,MaPeriod,0,MaMetod,PRICE_OPEN,3);
   double maClose3=iMA(NULL,0,MaPeriod,0,MaMetod,PRICE_CLOSE,3);
   double maLow3=iMA(NULL,0,MaPeriod,0,MaMetod,PRICE_LOW,3);
   double maHigh3=iMA(NULL,0,MaPeriod,0,MaMetod,PRICE_HIGH,3);

   double maOpen4=iMA(NULL,0,MaPeriod,0,MaMetod,PRICE_OPEN,4);
   double maClose4=iMA(NULL,0,MaPeriod,0,MaMetod,PRICE_CLOSE,4);

   haOpen1 =(haOpen2+ haClose2)/2;
   haClose1=(maOpen1+maHigh1+maLow1+maClose1)/4;
   double haHigh1=MathMax(maHigh1,MathMax(haOpen1,haClose1));
   double haLow1=MathMin(maLow1,MathMin(haOpen1,haClose1));

   haOpen2 =(haOpen3+ haClose3)/2;
   haClose2=(maOpen2+maHigh2+maLow2+maClose2)/4;
   double haHigh2=MathMax(maHigh2,MathMax(haOpen2,haClose2));
   double haLow2=MathMin(maLow2,MathMin(haOpen2,haClose2));

   haOpen3 =(haOpen4 + haClose4)/2;
   haClose3=(maOpen3+maHigh3+maLow3+maClose3)/4;
   double haHigh3=MathMax(maHigh3,MathMax(haOpen3,haClose3));
   double haLow3=MathMin(maLow3,MathMin(haOpen3,haClose3));

 if((haOpen1>haClose1) && (haOpen2<haClose2)); // buy
 if((haOpen1>haClose1) && (haOpen2<haClose2)); //sell

it doesn't seem to work, yet I can't figure out from the Hieken Ashi Smoothed source code how haHigh and haLow are factored into the iCustom call... can anyone provide further guidance?

xanderhinds
104
xanderhinds 2017.03.19 19:25  
otherwise, does anyone know why back testing on the daily TF is so unbearably slow?
Marco vd Heijden
Moderator
4706
Marco vd Heijden 2017.03.19 20:31  

you can also 'just' use

iMA(Symbol(),PERIOD_CURRENT,4,bar,MODE_SMMA,PRICE_MEDIAN,0)

Instead of

   int MaMetod=2;
   int MaPeriod = 24;
   int MaMetod2 = 3;
   int MaPeriod2= 2;

   double maOpen1=iMA(NULL,0,MaPeriod,0,MaMetod,PRICE_OPEN,1);
   double maClose1=iMA(NULL,0,MaPeriod,0,MaMetod,PRICE_CLOSE,1);
   double maLow1=iMA(NULL,0,MaPeriod,0,MaMetod,PRICE_LOW,1);
   double maHigh1=iMA(NULL,0,MaPeriod,0,MaMetod,PRICE_HIGH,1);
   double maOpen2=iMA(NULL,0,MaPeriod,0,MaMetod,PRICE_OPEN,2);
   double maClose2=iMA(NULL,0,MaPeriod,0,MaMetod,PRICE_CLOSE,2);
   double maLow2=iMA(NULL,0,MaPeriod,0,MaMetod,PRICE_LOW,2);
   double maHigh2=iMA(NULL,0,MaPeriod,0,MaMetod,PRICE_HIGH,2);
   double maOpen3=iMA(NULL,0,MaPeriod,0,MaMetod,PRICE_OPEN,3);
   double maClose3=iMA(NULL,0,MaPeriod,0,MaMetod,PRICE_CLOSE,3);
   double maLow3=iMA(NULL,0,MaPeriod,0,MaMetod,PRICE_LOW,3);
   double maHigh3=iMA(NULL,0,MaPeriod,0,MaMetod,PRICE_HIGH,3);

   double maOpen4=iMA(NULL,0,MaPeriod,0,MaMetod,PRICE_OPEN,4);
   double maClose4=iMA(NULL,0,MaPeriod,0,MaMetod,PRICE_CLOSE,4);

   haOpen1 =(haOpen2+ haClose2)/2;
   haClose1=(maOpen1+maHigh1+maLow1+maClose1)/4;
   double haHigh1=MathMax(maHigh1,MathMax(haOpen1,haClose1));
   double haLow1=MathMin(maLow1,MathMin(haOpen1,haClose1));

   haOpen2 =(haOpen3+ haClose3)/2;
   haClose2=(maOpen2+maHigh2+maLow2+maClose2)/4;
   double haHigh2=MathMax(maHigh2,MathMax(haOpen2,haClose2));
   double haLow2=MathMin(maLow2,MathMin(haOpen2,haClose2));

   haOpen3 =(haOpen4 + haClose4)/2;
   haClose3=(maOpen3+maHigh3+maLow3+maClose3)/4;
   double haHigh3=MathMax(maHigh3,MathMax(haOpen3,haClose3));
   double haLow3=MathMin(maLow3,MathMin(haOpen3,haClose3));

 if((haOpen1>haClose1) && (haOpen2<haClose2)); // buy
 if((haOpen1>haClose1) && (haOpen2<haClose2)); //sell
Mladen Rakic
54679
Mladen Rakic 2017.03.19 21:29  

Try like this :

The call :

         double haHigh,haLow,haOpen,haClose;
            calculateHA(MaPeriod,MaMethod,haOpen,haClose,haHigh,haLow,i);
            
            hahu[i]  = haHigh; 
            hahd[i]  = haLow;
            hahbu[i] = haOpen;
            hahbd[i] = haClose;


The function :

#define _haInstances     1
#define _haInstancesSize 4
double workHa[][_haInstances*_haInstancesSize];
#define _haH 0
#define _haL 1
#define _haO 2
#define _haC 3

void calculateHA(int maPeriod, int maMethod, double& tOpen, double& tClose, double& tHigh, double& tLow, int i, int instanceNo=0)
{
   if (ArrayRange(workHa,0)!= Bars) ArrayResize(workHa,Bars); int r=Bars-i-1; instanceNo*=_haInstancesSize;
   
   //
   //
   //
   //
   //
   
      double maOpen  = iMA(NULL,0,maPeriod,0,maMethod,PRICE_OPEN ,i);
      double maClose = iMA(NULL,0,maPeriod,0,maMethod,PRICE_CLOSE,i);
      double maLow   = iMA(NULL,0,maPeriod,0,maMethod,PRICE_LOW  ,i);
      double maHigh  = iMA(NULL,0,maPeriod,0,maMethod,PRICE_HIGH ,i);
      double haOpen  = (r>0) ? (workHa[r-1][instanceNo+_haO] + workHa[r-1][instanceNo+_haC])/2.0 : maOpen;
      double haClose = (maOpen+maHigh+maLow+maClose)/4;
      double haHigh  = MathMax(maHigh, MathMax(haOpen, haClose));
      double haLow   = MathMin(maLow,  MathMin(haOpen, haClose));

      if(haOpen<haClose) { workHa[r][instanceNo+_haH] = haLow;  workHa[r][instanceNo+_haL] = haHigh; } 
      else               { workHa[r][instanceNo+_haH] = haHigh; workHa[r][instanceNo+_haL] = haLow;  } 
                           workHa[r][instanceNo+_haO] = haOpen;
                           workHa[r][instanceNo+_haC] = haClose;
      //
      //
      //
      //
      //
      
   tHigh  = workHa[r][instanceNo+_haH];
   tLow   = workHa[r][instanceNo+_haL];
   tOpen  = workHa[r][instanceNo+_haO];
   tClose = workHa[r][instanceNo+_haC];
}
xanderhinds
104
xanderhinds 2017.03.20 20:43  
Marco vd Heijden:

you can also 'just' use

Instead of


Grand, that'd save my scrolling finger from fatigue.. Could you explain how that code would provide the result? I rather enjoy understanding how all these things work but that code doesn't translate into Heiken ashi smoothed to me..
xanderhinds
104
xanderhinds 2017.03.20 20:45  
Mladen Rakic:

Try like this :

The call :


The function :


Thanks man, i'll try this instead!
Marco vd Heijden
Moderator
4706
Marco vd Heijden 2017.03.20 20:56  
xanderhinds:

Grand, that'd save my scrolling finger from fatigue.. Could you explain how that code would provide the result? I rather enjoy understanding how all these things work but that code doesn't translate into Heiken ashi smoothed to me..

Really?

Well maybe this does:


To add comments, please log in or register