How to handle candlestick formation in real time
- Hot to print last 5 candlestick values
- Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes
- Need to change this script
Did you check candle 0 which is the current candle ?
double current_open = iOpen(_Symbol,PERIOD_M1,0), current_high = iHigh(_Symbol,PERIOD_M1,0), current_low = iOpen(_Symbol,PERIOD_M1,0), current_close = iClose(_Symbol,PERIOD_M1,0);
or
double current_open = Open[0], current_high = High[0], current_low = Open[0], current_close = Close[0];
Hi.
The right moment when new 1-minute candle is formed can be obtained by :
void OnTick(){ static datetime oldTime; datetime newTime = iTime(_Symbol,PERIOD_M1,0); if (newTime!=oldTime) { oldTime=newTime; //...codes } }
Thank you for the code snippet.
Just use PERIOD_CURRENT instead of PERIOD_M1
(If I understood your question correctly)HI!
I've tried the code and I have a problem
The code is:
void OnTick() { //--- static datetime oldTime; string new_prices; datetime newTime = iTime(_Symbol,PERIOD_CURRENT,0); if(newTime!=oldTime){ oldTime=newTime; new_prices = StringFormat("Open:%g, Close:%g, High:%g, Low:%g, Volume:%g, Time:%s", iOpen(_Symbol,PERIOD_CURRENT,0), iClose(_Symbol,PERIOD_CURRENT,0), iHigh(_Symbol,PERIOD_CURRENT,0), iLow(_Symbol,PERIOD_CURRENT,0), iVolume(_Symbol,PERIOD_CURRENT,0), TimeToStr(iTime(_Symbol,PERIOD_CURRENT,0))); Print(new_prices); } }
The timing is ok. The information is printed once the candlestick is completly formed.
The problem is that the information about the candlestick are not correct. The Volume is always 1. The other values are always the same.
Any hints?
edit:
I solved shifting by 1 al the values.