MQL5 TUTORIAL - SIMPLE STRING CONCATENATION FUNCTION

Published: 09 July 2023
on channel: MQL5 Tutorial
391
9

https://mql5tutorial.com

Introduction to String Concatenation Function (00:01 - 00:08)

Introduction to the topic of creating a simple string concatenation function in MQL5 to display date and time in a readable format on the chart.
Opening MetaEditor and Creating a New File (00:08 - 00:37)

Instructions on opening the MetaEditor and creating a new Expert Advisor file named "SimpleStringConcatenateFunction."
Preparing the MQL5 Code (00:37 - 00:51)

Steps to delete unnecessary lines above the "OnTick" function and prepare the MQL5 code.
Creating MqlDateTime Structure (00:51 - 01:10)

Explanation of creating a structure named "mqlTime" to store the local time using the "TimeLocal" function.
Formatting Local Time into a String (01:10 - 01:32)

Demonstrating how to format the local time into a string using "StringConcatenate" and "IntegerToString" functions.
Outputting Formatted Time on the Chart (01:32 - 01:41)

Using the "Comment" function to display the formatted time on the chart.
Compiling and Testing the Expert Advisor (01:41 - 02:09)

Instructions for compiling the code and testing the Expert Advisor in the Strategy Tester of MetaTrader.
Conclusion and Next Steps (02:09 - 02:09)

Concluding remarks and anticipation for the next video.

In this video, we are talking about a simple string concatenation function that we have created in MQL5. You can see the output here on the chart, we have the date and time in a certain format, which is the local time displayed here in the Strategy Tester. Now we will find out how we can create a custom string concatenation function that returns the date and time in this readable format. To do that, please click on the small button here or press F4 on your keyboard.

You should now see the MetaEditor, and here you want to go to: "File , New , Expert Advisor (Template)" from the template, click "Next". I will call this file "SimpleStringConcatenateFunction", click "Next", "Next" 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 structure MqlDateTime to store the local time. We call it "mqlTime". With the "TimeLocal" function we get the local time and store it in the mqlTime structure.

Now we create a string variable named "localTimeStr" to store the formatted local time. The formatting of the local time is done using the "StringConcatenate()" and "IntegerToString()" functions.

Here comes the interesting part: We link the different parts of the local time, like year, month, day, hour, minute, and second, using the "StringConcatenate()" function and thus create a readable string.

With the "Comment()" function, we then output the local time on the chart.

Now you can click on the "Compile" button, this should now work without errors and if this is the case, you can click on the small button here to go back to MetaTrader.

In MetaTrader, you want to go to "View / Strategy Tester" or press CTRL and R, and now you should see the Strategy Tester here, please select the "SimpleStringConcatenateFunction", highlight the visualization option here and start your test.

We have the date and 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 did it with a few lines of MQL5 code.

Thank you for watching and I will see you in the next video.


Watch video MQL5 TUTORIAL - SIMPLE STRING CONCATENATION FUNCTION online without registration, duration hours minute second in high quality. This video was added by user MQL5 Tutorial 09 July 2023, don't forget to share it with your friends and acquaintances, it has been viewed on our site 391 once and liked it 9 people.