Download MetaTrader 5

Market Value of SP500

To add comments, please log in or register
giehlc 2016.06.17 13:22 

Hi community,

for my EA, I need a function that is able to show the market value of SP500 when it opens and when it closes from the previous day.

Does something like this exists and if not, what I assume since I didn't find anything, has anyone of you an idea how to solve this?

Best regards


P.S. Sorry for any spelling mistakes

Fernando Carreiro
Fernando Carreiro 2016.06.17 13:39  

With such a vague and general request, it seems obvious that your coding skill is most probably close to ZERO, so I suggest that you head on over to the Freelance section and hire someone to code it for you!

EDIT: PS! Hopefully your broker already supports trading the S&P 500, otherwise you will have to find a broker that does.

Carl Schreiber
Carl Schreiber 2016.06.17 13:50  
Read about iOpen() and iClose() in the editor's reference...
giehlc 2016.06.17 15:22  
iopen and iclose seems like the function I was searching for. Thank you very much!
giehlc 2016.06.19 11:26  

Hi again,

just want to post my soultion in case anyone is searching for something similar:


   double  Sp500_Open, Sp500_Close;

   if(DayOfWeek()>=2) {

      Sp500_Open = iOpen("[SP500]",PERIOD_D1, 1);

      Sp500_Close = iClose("[SP500]",PERIOD_D1, 1);


   else {

      Sp500_Open = iOpen("[SP500]",PERIOD_D1, 3);

      Sp500_Close = iClose("[SP500]",PERIOD_D1, 3);



You first need to check which day of the week it is because obviously when you say "give the opening value of SP500 from the previous day" on a monday, you won't get a value.

This is why the function checks if the day is greater or equal tuesday. If this is the case, you get the opening price of Market [SP500] for period 1 Day minus 1 (so yesterday). Same goes for closing price.

However if it's a monday, you get the prices from 3 days ago (last friday).


Thanks again gooly. 

To add comments, please log in or register