How to give date with variable

 

Hi!


I have a problem what I cannot solve. 

I want to create a variable, which has a datime form and I want to give its value with different variables just like in the excel with date function


var1=2014  (number of year)

var2=3  (number of month)

var3=5  (number of day)


in the excel=date(var1,var2,var3)


How can I do this in Mql4?


Thank in advance,

roley

 
roley:I have a problem what I cannot solve. 

I want to create a variable, which has a datime form and I want to give its value with different variables just like in the excel with date function

var1=2014  (number of year)

var2=3  (number of month)

var3=5  (number of day)

in the excel=date(var1,var2,var3)

How can I do this in Mql4?

Please take some time to first familiarise yoursef with MQL coding by reading the MQL4 Reference Documentation.

There is a section dedicated to Date and Time functions and there you can focus your attention on the StructToTime() function as well as the MqlDateTime data structure. These to not provide exactly the same functionality as you require, but it is similar and you can then code your own function to accomplish exactly what you need.

I would also like to suggest the following book to help you along:

Forum on trading, automated trading systems and testing trading strategies

Something Interesting to Read

Sergey Golubev, 2017.09.16 05:40

Expert Advisor Programming for MetaTrader 4


This book will teach you the following concepts:

  • The basic of the MLQ4 language, including variables and data types, operations, conditional and loop operators, functions, classes and objects, event handlers and more.
  • Place, modify and close market and pending orders.
  • Add a stop loss and/or take profit price to an individual order, or to multiple orders.
  • Close orders individually or by order type.
  • Get a total of all currently opened orders.
  • Work with OHLC bar data and locate basic candlestick patterns.
  • Find the highest high and lowest low of recent bars.
  • Work with MetaTrader’s built-in indicators, as well as custom indicators.
  • Add a trailing stop or break even stop feature to an expert advisor.
  • Use money management and lot size verification techniques.
  • Add a flexible trading timer to an expert advisor.
  • Construct several types of trading systems, including trend, counter-trend and breakout systems.
  • Add alert, emails, sounds and other notifications.
  • Add and manipulate chart objects.
  • Read and write to CSV files.
  • Construct basic indicators, scripts and libraries.
  • Learn how to effective debug your programs, and use the Strategy Tester to test your strategies.

All of the source code in this book is available for download, including an expert advisor framework that allows you to build robust and fully-featured expert advisors with minimal effort.

Date and Time - MQL4 Reference
Date and Time - MQL4 Reference
  • docs.mql4.com
This is the group of functions for working with data of datetime type (an integer that represents the number of seconds elapsed from 0 hours of January 1, 1970).
 
roley:

Hi!


I have a problem what I cannot solve. 

I want to create a variable, which has a datime form and I want to give its value with different variables just like in the excel with date function


var1=2014  (number of year)

var2=3  (number of month)

var3=5  (number of day)


in the excel=date(var1,var2,var3)


How can I do this in Mql4?


Thank in advance,

roley

You can try more ways..
For example: Array
 

I fund the TimeToStruct function but an example would be very helpful in the short run.

 


 
roley: I fund the TimeToStruct function but an example would be very helpful in the short run.

There is an example and in my post I gave you several links to follow. Please follow-up on the posts and don't just ignore the advice given here.

There is a section dedicated to Date and Time functions and there you can focus your attention on the StructToTime() function as well as the MqlDateTime data structure. These to not provide exactly the same functionality as you require, but it is similar and you can then code your own function to accomplish exactly what you need.

 
roley:

Hi!

I have a problem what I cannot solve. 

I want to create a variable, which has a datime form and I want to give its value with different variables just like in the excel with date function

var1=2014  (number of year)

var2=3  (number of month)

var3=5  (number of day)

in the excel=date(var1,var2,var3)

How can I do this in Mql4?

Thank in advance,

roley



There are built in functions to give you what you want, with examples.

Day: https://docs.mql4.com/dateandtime/day

Month: https://docs.mql4.com/dateandtime/month

Year: https://docs.mql4.com/dateandtime/year


In addition, it would be helpful for you to read over the following information for the date and time functions.

https://docs.mql4.com/dateandtime

- Jack








Date and Time - MQL4 Reference
Date and Time - MQL4 Reference
  • docs.mql4.com
This is the group of functions for working with data of datetime type (an integer that represents the number of seconds elapsed from 0 hours of January 1, 1970).
Reason: