Hi.
I am writing my very first EA.
I need to use open, close, high, and low values of candlesticks in a one minute timeframe.
I have no problem handling the candlesticks already formed when the EA starts.
Yet I do not know how to handle the new candlesticks while they are incoming in real time.
Is there any function which monitors the updating candlesticks?
Any suggestion will be appreciated.
- Hot to print last 5 candlestick values
- Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes
- Questions from Beginners MQL5 MT5 MetaTrader 5
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];
vaeVictis:
Hi.
If your main code is running inside OnTick() or OnTimer() events (which I think it needs to) the job is done for you. Hi.
I am writing my very first EA.
I need to use open, close, high, and low values of candlesticks in a one minute timeframe.
I have no problem handling the candlesticks already formed when the EA starts.
Yet I do not know how to handle the new candlesticks while they are incoming in real time.
Is there any function which monitors the updating candlesticks?
Any suggestion will be appreciated.
As real time changes, iClose(....,1) will be the close of the previous bar, whatever the time is.
vaeVictis:
What I need is to grab the exact moment when the last candle is completly formed.
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 one last question.
How can I make "PERIOD_M1" dependent on the chart timeframe?
Thank you in advance.
vaeVictis:
Thank you for the code snippet.
Thank you for the code snippet.
Just one last question.
How can I make "PERIOD_M1" dependent on the chart timeframe?
Thank you in advance.
Just use PERIOD_CURRENT instead of PERIOD_M1
(If I understood your question correctly)
I think you understood.
I'll update you when I have a computer at hand.
Many thanks you all
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.
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register