How can I capture the outputs from iCustom function against previous candlestick?

To add comments, please log in or register
Nrjetik
10
Nrjetik  

Hi All,


I am trying to get the outputs for the Heiken Ashi indicator on the previous candlestick but I was unable to find a method that was clear to me.


What I am attempting to do is determine a shift in direction, by checking if the current Heiken Ashi candle colour is different from the previous Heiken Ashi candle colour. I am aware that I am I'm actually comparing the values, not the colours but just wanted to put it in laymen terms.


I was hoping there was something similar to the OLHC function (i.e. PrevOpenPrice = Open[1], or CurrentOpenPrice = Open[0]) that I can leverage, but I think it's going to be more complex than that.


This is all I really have as far as defining variables goes:

      // Declaring Heiken Ashi Setting
      // Current Values
      double Heik0=iCustom(local_instrument,Period(),"Heiken Ashi",0,0);
      double Heik1=iCustom(local_instrument,Period(),"Heiken Ashi",1,0);
      double Heik2=iCustom(local_instrument,Period(),"Heiken Ashi",2,0);
      double Heik3=iCustom(local_instrument,Period(),"Heiken Ashi",3,0);
      
      // Previous Bar Heiken Ashi


Hope someone is able to help! Thanks.

Seng Joo Thio
1219
Seng Joo Thio  
Nrjetik:

I am trying to get the outputs for the Heiken Ashi indicator on the previous candlestick but I was unable to find a method that was clear to me.

What I am attempting to do is determine a shift in direction, by checking if the current Heiken Ashi candle colour is different from the previous Heiken Ashi candle colour. I am aware that I am I'm actually comparing the values, not the colours but just wanted to put it in laymen terms.

I was hoping there was something similar to the OLHC function (i.e. PrevOpenPrice = Open[1], or CurrentOpenPrice = Open[0]) that I can leverage, but I think it's going to be more complex than that.

This is all I really have as far as defining variables goes:

Hope someone is able to help! Thanks.

I happened to have this function:

const string nameOfHA = "Heiken Ashi";

double GetHA(int bar, int type=PRICE_CLOSE, int tf=0, string symb=NULL)
{
   if (tf==0)
      tf = Period();
   else
   {
      int tfs[] = {1,5,15,30,60,240,1440,10080,43200};
      int tfIdx = ArrayBsearch(tfs,tf);
      tf = tfs[tfIdx];
   }

   if (symb==NULL)
      symb = Symbol();
      
   if (type==PRICE_CLOSE)
      return (iCustom(symb,tf,nameOfHA,3,bar));
   
   if (type==PRICE_OPEN)
      return (iCustom(symb,tf,nameOfHA,2,bar));
   
   if (type==PRICE_HIGH || type==PRICE_LOW)
   {
      double hl = iCustom(symb,tf,nameOfHA,0,bar);
      double lh = iCustom(symb,tf,nameOfHA,1,bar);
      
      if (type==PRICE_HIGH)
         return (MathMax(hl,lh));
      else
         return (MathMin(hl,lh));
   }
   
   return (0);
}   

So you can just call GetHA(bar,PRICE_CLOSE) for close, GetHA(bar,PRICE_HIGH) for high, etc.

To add comments, please log in or register