Artwork

内容由Raimund Bauer提供。所有播客内容(包括剧集、图形和播客描述)均由 Raimund Bauer 或其播客平台合作伙伴直接上传和提供。如果您认为有人在未经您许可的情况下使用您的受版权保护的作品,您可以按照此处概述的流程进行操作https://zh.player.fm/legal
Player FM -播客应用
使用Player FM应用程序离线!

MQL5 TUTORIAL – SIMPLE CUSTOM TIME FUNCTION

5:10
 
分享
 

Manage episode 395340184 series 1376757
内容由Raimund Bauer提供。所有播客内容(包括剧集、图形和播客描述)均由 Raimund Bauer 或其播客平台合作伙伴直接上传和提供。如果您认为有人在未经您许可的情况下使用您的受版权保护的作品,您可以按照此处概述的流程进行操作https://zh.player.fm/legal
MQL5 TUTORIAL – SIMPLE CUSTOM TIME FUNCTION

In this video we are going to talk about a simple custom time function that we have created in MQL5.
You see the output here on the chart, we have the date and we have the time including the seconds that is the local time that has been traded right here in the Strategy Tester and now we are going to find out how we can do a custom time function that is going to return the time and this readable format and to do that please click on the little button here or press F4 on your keyboard.
Now you should see the Metaeditor and here you want to click on: “File/ New/ Expert Advisor (template)” from template, “Continue”, I will call this file: “SimpleCustomTimeFunction”, click on “Continue”, “Continue” and “Finish” and now you can delete everything above the “OnTick” function and the two comment lines here.
Okay, that’s it.
First we need to create a string variable for our custom time that will be called: “myTime” and it’s of the type string, so it can contain text and to calculate it we just want to call a custom function called: “GetTime” to calculate the time, so the value of “myTime” will be calculated in the function “GetTime” and when we click on the “Compile” button right now we will see that the “GetTime” function is not defined, so that’s what we are going to do now.
To create a custom function you can use a return type, in our case we will use the string return type, because we are going to deliver the time as text. The name of the function is: “GetTime” as we are calling it here and we don’t have any parameters so let’s add two brackets here, we use a local string that will be called: time with seconds (TimeWithSeconds). Now we create a string for the time with seconds (TimeWithSeconds) that’s also a string type variable and the name will be: “TimeWithSeconds”.
Here comes the interesting part; we calculate the time with seconds (TimeWithSeconds) for the local time and that is done by using “TIME_LOCAL”. If you mark “TIME_LOCAL” and press the F1 key you will see that it returns the local time of a computer where the client terminal is running, but it’s a datetime variable so we use “TimeToStr” to change it to a text and the function: “TimeToStr” (time to string) is converting a value containing time in seconds since the 1st of January in 1970 into a string in this format.
We use “TIME_DATE” that will give us the year, the month and the day – that’s the first part here, this is the pipe sign, it separates the first from the second parameter, the second parameter is “TIME_SECONDS” and that will deliver us the local time including the seconds.
Okay. In the last step we want to return the calculated time to the main function by using the “return” function for “TimeWithSeconds” so it will return the calculated value here and assign it to “myTime” and to see it on the chart we use the “Comment” function to create a chart output for the time and when you are done you can click on the “Compile” button here, that should work without any errors now and if that is the case you can click on the little button here to go back to Metatrader.
In Metatrader you want to click on “View/ Strategy Tester” or press CTRL and R and now you should see the Strategy Tester here, please select the “SimpleCustomTimeFunction.ex5”, mark the visualization option here and start your test.
We have the date and the time directly on the Forex Chart and now you know how to create an Expert Advisor to calculate the formatted time output on your chart and you have done it with a few lines of MQL5 code.

Download “MQL5 TUTORIAL - SIMPLE CUSTOM TIME FUNCTION”

SimpleCustomTimeFunction.txt – Downloaded 405 times – 598.00 B

The post MQL5 TUTORIAL – SIMPLE CUSTOM TIME FUNCTION appeared first on MQL5 Tutorial.

  continue reading

34集单集

Artwork
icon分享
 
Manage episode 395340184 series 1376757
内容由Raimund Bauer提供。所有播客内容(包括剧集、图形和播客描述)均由 Raimund Bauer 或其播客平台合作伙伴直接上传和提供。如果您认为有人在未经您许可的情况下使用您的受版权保护的作品,您可以按照此处概述的流程进行操作https://zh.player.fm/legal
MQL5 TUTORIAL – SIMPLE CUSTOM TIME FUNCTION

In this video we are going to talk about a simple custom time function that we have created in MQL5.
You see the output here on the chart, we have the date and we have the time including the seconds that is the local time that has been traded right here in the Strategy Tester and now we are going to find out how we can do a custom time function that is going to return the time and this readable format and to do that please click on the little button here or press F4 on your keyboard.
Now you should see the Metaeditor and here you want to click on: “File/ New/ Expert Advisor (template)” from template, “Continue”, I will call this file: “SimpleCustomTimeFunction”, click on “Continue”, “Continue” and “Finish” and now you can delete everything above the “OnTick” function and the two comment lines here.
Okay, that’s it.
First we need to create a string variable for our custom time that will be called: “myTime” and it’s of the type string, so it can contain text and to calculate it we just want to call a custom function called: “GetTime” to calculate the time, so the value of “myTime” will be calculated in the function “GetTime” and when we click on the “Compile” button right now we will see that the “GetTime” function is not defined, so that’s what we are going to do now.
To create a custom function you can use a return type, in our case we will use the string return type, because we are going to deliver the time as text. The name of the function is: “GetTime” as we are calling it here and we don’t have any parameters so let’s add two brackets here, we use a local string that will be called: time with seconds (TimeWithSeconds). Now we create a string for the time with seconds (TimeWithSeconds) that’s also a string type variable and the name will be: “TimeWithSeconds”.
Here comes the interesting part; we calculate the time with seconds (TimeWithSeconds) for the local time and that is done by using “TIME_LOCAL”. If you mark “TIME_LOCAL” and press the F1 key you will see that it returns the local time of a computer where the client terminal is running, but it’s a datetime variable so we use “TimeToStr” to change it to a text and the function: “TimeToStr” (time to string) is converting a value containing time in seconds since the 1st of January in 1970 into a string in this format.
We use “TIME_DATE” that will give us the year, the month and the day – that’s the first part here, this is the pipe sign, it separates the first from the second parameter, the second parameter is “TIME_SECONDS” and that will deliver us the local time including the seconds.
Okay. In the last step we want to return the calculated time to the main function by using the “return” function for “TimeWithSeconds” so it will return the calculated value here and assign it to “myTime” and to see it on the chart we use the “Comment” function to create a chart output for the time and when you are done you can click on the “Compile” button here, that should work without any errors now and if that is the case you can click on the little button here to go back to Metatrader.
In Metatrader you want to click on “View/ Strategy Tester” or press CTRL and R and now you should see the Strategy Tester here, please select the “SimpleCustomTimeFunction.ex5”, mark the visualization option here and start your test.
We have the date and the time directly on the Forex Chart and now you know how to create an Expert Advisor to calculate the formatted time output on your chart and you have done it with a few lines of MQL5 code.

Download “MQL5 TUTORIAL - SIMPLE CUSTOM TIME FUNCTION”

SimpleCustomTimeFunction.txt – Downloaded 405 times – 598.00 B

The post MQL5 TUTORIAL – SIMPLE CUSTOM TIME FUNCTION appeared first on MQL5 Tutorial.

  continue reading

34集单集

所有剧集

×
 
Loading …

欢迎使用Player FM

Player FM正在网上搜索高质量的播客,以便您现在享受。它是最好的播客应用程序,适用于安卓、iPhone和网络。注册以跨设备同步订阅。

 

快速参考指南