Getting different values of Heiken Ashi candles in Data Window & in my code

To add comments, please log in or register
kumaillakhani
165
kumaillakhani  

Hello,

Why I am getting different values of Heiken Ashi candles in Data Window & in my code values I am getting from my code is mentioned in highlighted logs. Can anyone guide me where I have made the mistake?

// Here is he chunk of code
datetime H1,H4;
double OPEN,CLOSE,H1EMAprev,HAHigh,HALow,HAOpen,HAClose,H1iHighest;
int total=9999999999,i;

   OPEN=iCustom(_Symbol,PERIOD_H1,"Heiken Ashi",Red,White,Red,White,2,1);
   CLOSE=iCustom(_Symbol,PERIOD_H1,"Heiken Ashi",Red,White,Red,White,3,1);
   H1EMAprev=NormalizeDouble(iMA(_Symbol,PERIOD_H1,14,0,MODE_EMA,PRICE_CLOSE,1),Digits());

   if(H1!=iTime(Symbol(),PERIOD_H1,0)) // new candle on D1
     {
      if(OPEN<CLOSE)
        {
         for(i=0;i<total;i++)
           {
            OPEN=NormalizeDouble(iCustom(_Symbol,PERIOD_H1,"Heiken Ashi",Red,White,Red,White,2,i),Digits);
            CLOSE=NormalizeDouble(iCustom(_Symbol,PERIOD_H1,"Heiken Ashi",Red,White,Red,White,3,i),Digits);
            HAHigh= NormalizeDouble(iCustom(_Symbol,PERIOD_H1,"Heiken Ashi",0,i),Digits);
            HALow = NormalizeDouble(iCustom(_Symbol,PERIOD_H1,"Heiken Ashi",1,i),Digits);
            HAOpen= NormalizeDouble(iCustom(_Symbol,PERIOD_H1,"Heiken Ashi",2,i),Digits);
            HAClose=NormalizeDouble(iCustom(_Symbol,PERIOD_H1,"Heiken Ashi",3,i),Digits);
            H1iHighest=NormalizeDouble(iHigh(Symbol(),PERIOD_H1,iHighest(Symbol(),PERIOD_H1,MODE_HIGH,i-1,i)),Digits);
            if(OPEN<CLOSE)
              {
               Print("its White, i: ",i,", HAHigh: ",HAHigh,", HALow: ",HALow,", HAOpen: ",HAOpen,", HAClose: ",HAClose,
                     ", OPEN: ",OPEN,", CLOSE: ",CLOSE,", Symbol: ",_Symbol,", H1iHighest: ",H1iHighest);
               break;
              }
           }
        }
      else
        {
         Print("its Red");
        }
      //Do Something...
      H1=iTime(Symbol(),PERIOD_H1,0);    // overwrite old with new value
     }

Heikin Ashi calculations... how do I get the high/low/close/open
Heikin Ashi calculations... how do I get the high/low/close/open
  • 2010.12.06
  • www.mql5.com
Hello, Is there anything out there that can get me the current Heikin Ashi candles high/low/close/open...
Minions Labs
1731
Minions Labs  
You are using the same name "heiken ashi" to all your objects... Are your sure that your are comparing the same things???
Smith Stuggatt
129
Smith Stuggatt  
Complicated
Andrey Barinov
42408
Andrey Barinov  
kumaillakhani:

Hello,

Why I am getting different values of Heiken Ashi candles in Data Window & in my code values I am getting from my code is mentioned in highlighted logs. Can anyone guide me where I have made the mistake?

Hi,

in your code you are reading data of HA on the bar open moment. During that time the value of HA close has not been formed yet (note that HA open value is the same). But in data window you observe the candle after it has already been formed. Thus the difference.

kumaillakhani
165
kumaillakhani  
Minions Labs:
You are using the same name "heiken ashi" to all your objects... Are your sure that your are comparing the same things???

// Here is he chunk of code
datetime H1,H4;
double OPEN,CLOSE,H1EMAprev,HAHigh,HALow,HAOpen,HAClose,H1iHighest;
int total=9999999999,i;

   OPEN=iCustom(_Symbol,PERIOD_H1,"Heiken Ashi",Red,White,Red,White,2,1);
   CLOSE=iCustom(_Symbol,PERIOD_H1,"Heiken Ashi",Red,White,Red,White,3,1);
   H1EMAprev=NormalizeDouble(iMA(_Symbol,PERIOD_H1,14,0,MODE_EMA,PRICE_CLOSE,1),Digits());

   if(H1!=iTime(Symbol(),PERIOD_H1,0)) // new candle on D1
     {
      if(OPEN<CLOSE)
        {
         for(i=0;i<total;i++)
           {
            // OPEN=NormalizeDouble(iCustom(_Symbol,PERIOD_H1,"Heiken Ashi",Red,White,Red,White,2,i),Digits);
            // CLOSE=NormalizeDouble(iCustom(_Symbol,PERIOD_H1,"Heiken Ashi",Red,White,Red,White,3,i),Digits);
            HAHigh= NormalizeDouble(iCustom(_Symbol,PERIOD_H1,"Heiken Ashi",0,i),Digits);
            HALow = NormalizeDouble(iCustom(_Symbol,PERIOD_H1,"Heiken Ashi",1,i),Digits);
            HAOpen= NormalizeDouble(iCustom(_Symbol,PERIOD_H1,"Heiken Ashi",2,i),Digits);
            HAClose=NormalizeDouble(iCustom(_Symbol,PERIOD_H1,"Heiken Ashi",3,i),Digits);
            H1iHighest=NormalizeDouble(iHigh(Symbol(),PERIOD_H1,iHighest(Symbol(),PERIOD_H1,MODE_HIGH,i-1,i)),Digits);
            if(OPEN<CLOSE)
              {
               Print("its White, i: ",i,", HAHigh: ",HAHigh,", HALow: ",HALow,", HAOpen: ",HAOpen,", HAClose: ",HAClose,
                     ", OPEN: ",OPEN,", CLOSE: ",CLOSE,", Symbol: ",_Symbol,", H1iHighest: ",H1iHighest);
               break;
              }
           }
        }
      else
        {
         Print("its Red");
        }
      //Do Something...
      H1=iTime(Symbol(),PERIOD_H1,0);    // overwrite old with new value
     }
I have commented OPEN & CLOSE but still no difference.
kumaillakhani
165
kumaillakhani  
Andrey Barinov:

Hi,

in your code you are reading data of HA on the bar open moment. During that time the value of HA close has not been formed yet (note that HA open value is the same). But in data window you observe the candle after it has already been formed. Thus the difference.

  1. How can I read value of bars on close?
  2. Also in logs where I have highlighted it show that bar is white but in actual that bar is red why?

Andrey Barinov
42408
Andrey Barinov  
kumaillakhani:

How can I read value of bars on close?

Read it when it is closed :), meaning do not use bar shift ==0, but only starting from 1.

kumaillakhani
165
kumaillakhani  
Andrey Barinov:

Read it when it is closed :), meaning do not use bar shift ==0, but only starting from 1.

  1. Also in logs where I have highlighted it show that 19:00:00 hour bar is white but in actual that bar is red why?
kumaillakhani
165
kumaillakhani  
In logs its shows me 4 bars are red and than I got white but in actual 5 bars are red and than 1 white bar appear. Where I have mistaken?
Andrey Barinov
42408
Andrey Barinov  
kumaillakhani:
  1. Also in logs where I have highlighted it show that bar is white but in actual that bar is red why?

Because you use WRONG close value in your code. When the bar just opened, and you read its data it WAS white, but than it turned red (after you read the data).

kumaillakhani
165
kumaillakhani  
Andrey Barinov:

Because you use WRONG close value in your code. When the bar just opened, and you read its data it WAS white, but than it turned red (after you read the data).


   OPEN=iCustom(_Symbol,PERIOD_H1,"Heiken Ashi",Red,White,Red,White,2,1);
   CLOSE=iCustom(_Symbol,PERIOD_H1,"Heiken Ashi",Red,White,Red,White,3,1);
   H1EMAprev=NormalizeDouble(iMA(_Symbol,PERIOD_H1,14,0,MODE_EMA,PRICE_CLOSE,1),Digits());

   if(H1!=iTime(Symbol(),PERIOD_H1,1)) // new candle on D1
     {
      if(OPEN<CLOSE)
        {
         for(i=0;i<total;i++)
           {
//            OPEN=NormalizeDouble(iCustom(_Symbol,PERIOD_H1,"Heiken Ashi",Red,White,Red,White,2,i),Digits);
//            CLOSE=NormalizeDouble(iCustom(_Symbol,PERIOD_H1,"Heiken Ashi",Red,White,Red,White,3,i),Digits);
            HAHigh= NormalizeDouble(iCustom(_Symbol,PERIOD_H1,"Heiken Ashi",0,i),Digits);
            HALow = NormalizeDouble(iCustom(_Symbol,PERIOD_H1,"Heiken Ashi",1,i),Digits);
            HAOpen= NormalizeDouble(iCustom(_Symbol,PERIOD_H1,"Heiken Ashi",2,i),Digits);
            HAClose=NormalizeDouble(iCustom(_Symbol,PERIOD_H1,"Heiken Ashi",3,i),Digits);
            H1iHighest=NormalizeDouble(iHigh(Symbol(),PERIOD_H1,iHighest(Symbol(),PERIOD_H1,MODE_HIGH,i-1,i)),Digits);

            if(OPEN<CLOSE)
              {
               Print("its White, i: ",i,", HAHigh: ",HAHigh,", HALow: ",HALow,", HAOpen: ",HAOpen,", HAClose: ",HAClose,
                     ", OPEN: ",OPEN,", CLOSE: ",CLOSE,", Symbol: ",_Symbol,", H1iHighest: ",H1iHighest);
               break;
              }
           }
        }
      else
        {
         Print("its Red");
        }

      //Do Something...
      H1=iTime(Symbol(),PERIOD_H1,1);    // overwrite old with new value
     }
   

Changed the code but still not solved my problem. Review snapshot.


12
To add comments, please log in or register