Closing price for Friday and Sunday's opening price? How to get?

 

Hello everybody, I would like to know how to get the closing price of Friday and the opening price on Sunday for an operation that shows the difference between these two prices and shows it on the chart.

Suppose the price of the EURUSD has closed Friday at 1.36095 and today(Sunday) the opening price is 1.35835, so I want to show on the chart that the difference between these two prices is 26 Pips.



Thank you for your help.



 

Code that will display ANY daily gap is perhaps something like

   double gap = iOpen(NULL, PERIOD_D1, ix) - iClose(NULL, PERIOD_D1, ix+1);

For JUST the Friday-Sunday gap, you;'ll need to add some day of week checking, maybe something like TimeDayOfWeek(iTime(NULL, PERIOD_D1, ix);

NB Code just typed, not compiled or checked

Also ix will need to reflect DAILY bar index, not current timeframe (unless it's also Daily)

 
brewmanz:

Code that will display ANY daily gap is perhaps something like

For JUST the Friday-Sunday gap, you;'ll need to add some day of week checking, maybe something like TimeDayOfWeek(iTime(NULL, PERIOD_D1, ix);

NB Code just typed, not compiled or checked

Also ix will need to reflect DAILY bar index, not current timeframe (unless it's also Daily)


ix and ix+1 is necessary? I´d like to put on M1 timeframe.
 
brewmanz:

[...]

For JUST the Friday-Sunday gap, you;'ll need to add some day of week checking,

????


double gap = iOpen(NULL, PERIOD_W1, 0) - iClose(NULL, PERIOD_W1, 1);
 
rcartaxo:

I´ll change from W1 to M1 timeframe. So, should be like that?


double gap = iOpen(NULL, PERIOD_M1, 0) - iClose(NULL, PERIOD_M1, 1);


That´s it?


Thank you.

 
rcartaxo:

That´s it?

Thank you.


do whatever u want but it's doesn't gonna give u the gap u want (& it's doesn't matter on what TF u put this)
 
qjol:

do whatever u want but it's doesn't gonna give u the gap u want (& it's doesn't matter on what TF u put this)

Why this code won´t give the number of pips between close friday and open sunday?
 

qjol's code is good, and better than my attempt (hey! I learnt a better way to do something - the forum works!)

racrtaxo, If you ask a question, and someone gives an answer, do not dispute it unless you've tried it and found it doesn't work. Try it and see.

Then think through why PERIOD_W does it easily, and PERIOD_M1 will only give you 'gap for last MINUTE'

 

Helló!

Here is gap-indicator.Use W1 chart and see gap!

Files:
gap.ex4  4 kb
 
brewmanz:

qjol's code is good, and better than my attempt (hey! I learnt a better way to do something - the forum works!)

racrtaxo, If you ask a question, and someone gives an answer, do not dispute it unless you've tried it and found it doesn't work. Try it and see.

Then think through why PERIOD_W does it easily, and PERIOD_M1 will only give you 'gap for last MINUTE'


I understand now, I just asked him why, because I´m new in MQL programming and I was trying to understand the diference between PERIOD_W1 and PERDIO_M1.


I tried this and i think it is working:


double gap = (iOpen(NULL, PERIOD_D1, 0) - iClose(NULL, PERIOD_M1, 1));
But the number of pips is formatted like this: 0.00782000. How to format it to look like this: "78.00" pips


Thank you guys you´re helping me a lot!

 
rcartaxo:

...
But the
number of pips is formatted like this: 0.00782000. How to format it to look like this: "78.00" pips
...

MQL4 Reference - Conversion functions - DoubleToStr