i understand the function iClose and iOpen, but i do not understand Close and Open when Programming.

 

i  busy creating an indicator looking back at history bid price in history and the ask price of now. 

now the history part i get and works. as shown in the code.

range = DoubleToStr((((iClose("EURGBP",0,i))-iOpen("EURGBP",0,i))*10000) +(((iClose("GBPUSD",0,i))-iOpen("GBPUSD",0,i))),0);


however for the ask price i simply thought i could do remove the i from iClose and iOpen but that did not work.

range = DoubleToStr((((Close("EURGBP",0,i))-Open("EURGBP",0,i))*10000) +(((Close("GBPUSD",0,i))-Open("GBPUSD",0,i))),0);


i understand i could do DoubletoStr(ask,digits) but how would that work in the example at the top? i am a very basic programmer with very few coding skills, but 

creating something history wise i understand MQ4 fine. it is just i get confused by how Open and Close compared to iClose and iOpen in what i try to do. i am sure once i get the understanding of it and it clicks with me i understand, but at the moment i am lost. could someone teach me or help me out here, what i miss in logic of understanding Open and Close compared to iClose and iOpen?

 

Read the documentation:

Also, check the sections to which above mql elements belong.

Close - Predefined Variables - MQL4 Reference
Close - Predefined Variables - MQL4 Reference
  • docs.mql4.com
Close - Predefined Variables - MQL4 Reference
 

MQL does not provide what you think it should provides. Place the cursor on iClose and press F1.

Beside that look at parameters of the function OnCalculate...

Beside that assume that 99% of your ideas or questions are already worked out here.

So search before trying - it's a lot faster and you won't step into most of the possible error traps.

 
All the functions with an i deliver a series which has by definition of mql5 the latest candle zero.

the close[] array within OnCalculate is not a series in its default state ending with rates_total - 1 instead.

But you can use ArraySetAsSeries on close[] to turn around the counting fashion so you don't have to copy the values around with iClose.
 
Tobias Johannes Zimmer #: All the functions with an i deliver a series which has by definition of mql5 the latest candle zero. The close[] array within OnCalculate is not a series in its default state ending with rates_total - 1 instead. But you can use ArraySetAsSeries on close[] to turn around the counting fashion so you don't have to copy the values around with iClose.
Please note that OP is referring to MQL4 code, that has both the Close[] predefined variable as well as the close[] parameter of OnCalculate which is predefined as a series array (unlike MQL5).
 
tim4dexlus: i  busy creating an indicator looking back at history bid price in history and the ask price of now. now the history part i get and works. as shown in the code. however for the ask price i simply thought i could do remove the i from iClose and iOpen but that did not work. i understand i could do DoubletoStr(ask,digits) but how would that work in the example at the top? i am a very basic programmer with very few coding skills, but 

creating something history wise i understand MQ4 fine. it is just i get confused by how Open and Close compared to iClose and iOpen in what i try to do. i am sure once i get the understanding of it and it clicks with me i understand, but at the moment i am lost. could someone teach me or help me out here, what i miss in logic of understanding Open and Close compared to iClose and iOpen?

Please be aware of where you post. Given that you are are asking about MT4/MQL4, then please post in that section (which is at the end of the forum).

Otherwise, you may end up getting responses about MQL5 coding which may not be relevant and just end up confusing you and making it even worse.

For now, Drazen Penic's post is the most relevant and you should read up on the links provided.

Forum on trading, automated trading systems and testing trading strategies

i understand the function iClose and iOpen, but i do not understand Close and Open when Programming.

Drazen Penic, 2022.09.05 12:45

Read the documentation:

Also, check the sections to which above mql elements belong.

 
Drazen Penic #:

Read the documentation:

Also, check the sections to which above mql elements belon

i think i understand it half, so if do iClose - iOpen, i do for example  (Close[i] <= Open[i]) ?

 
tim4dexlus #:i think i understand it half, so if do iClose - iOpen, i do for example  (Close[i] <= Open[i]) ?

No! "Close[i]" would be equivalent to "iClose( _Symbol, _Period, i)", and "Open[i]" would be equivalent to "iOpen( _Symbol, _Period, i)"

Close[] / Open[] refers only to the current chart symbol and time-frame (on MQL4 only), and iClose() / iOpen() can get values for any symbol or time-frame independently of the chart and it works on both MQL4 and MQL5.
 
Fernando Carreiro #:

No! "Close[i]" would be equivalent to "iClose( _Symbol, _Period, i)", and "Open[i]" would be equivalent to "iOpen( _Symbol, _Period, i)"

Close[] / Open[] refers only to the current chart symbol and time-frame (on MQL4 only), and iClose() / iOpen() can get values for any symbol or time-frame independently of the chart and it works on both MQL4 and MQL5.

thank you for the responce, but what code would i need to do then in metatrader 4 to do close price - open price ( for the ask price instead of the bid price ) because history data is only bid price.

what i like to do is use the history ( close ) and compare it to the open ask price, instead of what metatrader does it checking close pride bid with open price bid.

 
tim4dexlus #: thank you for the responce, but what code would i need to do then in metatrader 4 to do close price - open price ( for the ask price instead of the bid price ) because history data is only bid price. what i like to do is use the history ( close ) and compare it to the open ask price, instead of what metatrader does it checking close pride bid with open price bid.

There is no OHLC data for Ask prices. All OHLC bar data on all charts is based on Bid prices. This is for both MT4 and MT5.

On MT4, the only Ask price you have access to is the current Ask price. However, on MT5, you can also access historical tick data, for both Bid and Ask prices, independently of OHLC Bid prices.

So, the answer to your question, is that on MT4, you can't do it (unless you plan to collect the tick data yourself).

 
and if i want to compare it with current price. so if i want to compare for example EURUSD Open ask price with EURUSD current bid price is that possible?