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.
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.
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.
- How can I read value of bars on close?
- Also in logs where I have highlighted it show that bar is white but in actual that bar is red why?
- 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).
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.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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?