Server version in Opener - page 13

 
prostotrader:

There is another option, for copper (there seems to be 2 and 5),

all other futures are either 3 or 1 month.

You can automatically substitute a month.

Well, if that's the case, maybe it's better to take

TimeToString(SymbolInfoInteger(_Symbol, SYMBOL_EXPIRATION_TIME), TIME_DATE)

and pull the year and month+3(1) from that date.

Or stick this date in a structure and take the month and year from there. And then glue the character name together. I'm going to try the structure now.

 

I liked the way it turned out through the structure...

string newFutures(const string aSymbol, int month = 3)
 {
  MqlDateTime mqlDateTime;
  TimeToStruct(SymbolInfoInteger(aSymbol, SYMBOL_EXPIRATION_TIME), mqlDateTime);    // Заполнили структуру датой экспирации фьючерса
  string symb = StringSubstr(aSymbol, 0, StringFind(_Symbol, "-")+1);               // Вытащили имя символа вместе с дефисом
  return(symb+(string)(mqlDateTime.mon+month)+"."+(string)(mqlDateTime.year%1000)); // Вернули составленное имя следующего фьючерса
 }
 
Alexey Viktorov:

I liked the way it worked through the structure...

Now try for the futures XXX-12.20

That should work out to XXXX-3.21

Added by

And then try if you want not next futures, but through futures (NtxFutMonth = 6)

Документация по MQL5: Константы, перечисления и структуры / Состояние окружения / Информация об инструменте
Документация по MQL5: Константы, перечисления и структуры / Состояние окружения / Информация об инструменте
  • www.mql5.com
Для получения текущей рыночной информации служат функции SymbolInfoInteger(), SymbolInfoDouble() и SymbolInfoString(). В качестве второго параметра этих функций допустимо передавать один из идентификаторов из перечислений ENUM_SYMBOL_INFO_INTEGER, ENUM_SYMBOL_INFO_DOUBLE и ENUM_SYMBOL_INFO_STRING соответственно. Некоторые символы (как...
 
prostotrader:

Now try for futures XXXX-12.20

You should get XXXX-3.21.

Oh! Right. That's the next phase. I'll just finish it.

 
Alexey Viktorov:

Oh! Right. That's the next step. I'll get right on it.

:)

What's the point? The function I gave you has been working for years...

 
prostotrader:

Now try for futures XXX-12.20

That would be XXXX-3.21

Added

And then try if you want not next futures, but through futures (NtxFutMonth = 6)

Something came out too easy. Check it out please.

string newFutures(const string aSymbol, int month = 3) // Сюда можно вставить и 1 и 6
 {
  MqlDateTime mqlDateTime;
  TimeToStruct(SymbolInfoInteger(aSymbol, SYMBOL_EXPIRATION_TIME)+month*PeriodSeconds(PERIOD_MN1), mqlDateTime);// Получилось время экспирации следующего фьючерса
  string symb = StringSubstr(aSymbol, 0, StringFind(_Symbol, "-")+1);
  return(symb+(string)(mqlDateTime.mon)+"."+(string)(mqlDateTime.year%1000));
 }

I have.

newFutures("RTS-12.19")
brought back the RTS-3.20
 
prostotrader:

:)

What's the point? The function I gave you has been working for years...

I asked because I thought there was a simple option. I don't doubt your function at all, but from my point of view it's a bit more complicated than I did.
 
Alexey Viktorov:
I asked because I thought there was a simple option. I don't doubt the functionality of your function at all, but from my point of view it's a bit more complicated than I did.

OK, no problem.

PutNtxFutMonth = 6 on futures XXXX-12.20

 
prostotrader:

OK, no problem.

PutNtxFutMonth = 6 on futures XXXX-12.20

Put it on RTS-12.19.

newFutures("RTS-12.19", 6)

and got RTS-6.20.

I'm just afraid I've missed some subtleties. That's why I asked you to check.

 
Alexey Viktorov:

Put it on RTS-12.19

and got RTS-6.20

I'm just afraid I've missed some subtleties. That's why I asked you to check.

Try this one.

Current Next Futures
Current Next Futures
  • www.mql5.com
Cкрипт с тремя независимыми функциями для определения текущего (ближайшего) фьючерса рынка FORTS. В параметрах вводится короткое наименование фьючерса, например br (можно мелким шрифтом). На выходе полное...
Reason: