Applies a specific template from a specified file to the chart. The command is added to chart message queue and executed only after all previous commands have been processed. Returns true if the command has been added to chart queue, otherwise false. To get error details use the GetLastError function. The Expert Advisor will be unloaded and will not be able to continue operating in case of successful loading of a new template to the chart it is attached to.
Users can allow or forbid the following actions for an mql4 program launched on a chart:. The terminal allows saving the configured chart as a template with all indicators and Expert Advisors launched on it. Thus, it is possible to quickly apply template settings to all other charts. When saving the template, permissions of the launched programs live trading and DLL imports are also saved.
When applying the template to the chart, these permissions may be limited due to security reasons:. Live trading and DLL imports permissions cannot be extended for the Expert Advisors launched by applying the template using ChartApplyTemplate function. If the mql4 program calling ChartApplyTemplate function has no permission to trade, the Expert Advisor launched via the template will also not be able to trade regardless of the template settings.
If the mql4 program calling ChartApplyTemplate function has permission to trade, while there is no such permission in the template settings, the Expert Advisor launched via the template will not be able to trade.
The resources of the MQL4 language allow setting multiple chart properties, including colors using the ChartSetInteger function:. Besides, there can be multiple graphical objects and indicators on a chart. You may set up a chart with all the necessary indicators once and then save it as a template.
Such a template can be applied to any chart. The ChartApplyTemplate function is intended for using a previously saved template, and it can be used in any mql4 program.
The path to the file that stores the template is passed as the second parameter to ChartApplyTemplate. The template file is searched according to the following rules:. Normally they are different folders, but in some cases they may coincide. Templates are not resources, they cannot be included into an executable EX4 file. Chart Operations ChartSaveTemplate.
ChartApplyTemplate Applies a specific template from a specified file to the chart.Find us on Facebook!
Join our fan page. The largest library features codes of free trading Expert Advisors, technical indicators and scripts. With the available applications you can trade in automated mode and analyze price dynamics. Use the library of codes to learn more about financial market sentiments.
If anybody wants to translate it to MQL5, it would be great. I still do not know MQL5.MQL4 TUTORIAL BASICS - 37 HOW TO IMPORT EXTERNAL SOURCECODE
If you do, please, let me know. Most traders keep losing money because they focus on money rather than planning their trades based on Percentage risk. Are you tired and lost when it comes to creating an attractive market watch list? Well we will guide you step by step to create your own attractive market watch list for potential entries. Three mooving average of WPR indicator, you can set the indicator period, the mooving average period and the mooving average method.
It is very useful if you are very busy in which you don't have time, you want to trade the London session while you are sleeping in USA, etc. This expert shows the maximum profit level that touched by price line for your first position on chart window.
Please vote this program to help know this program how much helpful. Thanks for your vote stars. This indicator draws a trend-line directly on a chart. It uses the Theil Sen Estimation method to calculate the slope of the trend-line.
Theil—Sen estimation is a method for robustly fitting a line to sample points in the plane simple linear regression by choosing the median of the slopes of all lines through pairs of points. Please test in Demo Account first. Short description: This Script will draw a line from the open to the close for each order in you account history. An oscillator that duplicates the chart of a selected asset in a separate window in three ways: line, bars and candles.
This is essentially an indicator Bollinger bands, displayed in a separate window. In my opinion, it will be useful for beginners as a way to look at various technical signals from a different angle.The distinctive feature of programs intended for operation in the client terminal MetaTrader 4 is their work with constantly updated information in real time.
In MQL4 language, this peculiarity is reflected in the form of the three special functions: initstartand deinit. Special functions are functions with predefined names initstart and deiniteach possessing its own special properties. The main property of all special functions is their execution in a program under certain conditions without using a special function call from within the program. Special functions are called for execution by the client terminal.
MQL4 TUTORIAL BASICS – 36 SIMPLE MOUSE CLICK EVENT
If a program contains the description of a special function, it will be called and executed in accordance with the calling conditions and its own properties. The distinct property of the special init function is its execution at the program initialization. If a program contains the description of the special init function, it will be called and executed at the moment the program starts. If there is no special init function in a program, no actions will be performed at the program's start. In scriptsinit is also called and executed immediately after it is attached to a chart.
The distinct properties of the special start function differ depending on the executable program type. In EAsstart is called and executed immediately after a new tick comes. If a new tick has come during the execution of startthis tick will be ignored, that is start will not be called for execution when such a tick comes. All quotes received during the execution of start will be ignored.
The commencement of start for execution is performed by the client terminal only, provided the previous operation session has been completed, the control has been returned to the client terminal, and start is waiting for a new tick.
If this button is in the state of disabling EAs, the client terminal will not call for execution start irrespective of whether new quotes come or not. However, changing the button state from enabled to disabled does not terminate the current operation session of start. The client terminal does not call start if the EA properties window is open. The EA properties window can be opened only when start is waiting for a new tick.
This window cannot be opened during the execution session of the EA's start function. In scriptsstart is called and executed only once, immediately after program initialization by init. In custom indicatorsstart is called and executed immediately after a new tick comes, immediately after being attached to a chart, when changing a security window size, when switching from one security to another, when starting the client terminal if during the previous session an indicator was attached to a chartand after changing a symbol and period of a current chart irrespective of the fact whether new quotes come or not.
If start was executed during the shutdown command, time available for the terminal to complete execution of the function is 2. If after the shutdown command start continues its operation for more than the indicated time limit, it will be forcibly terminated by the client terminal. The distinct function of the special deinit function is its execution at program termination deinitialization.In this article, we will consider an example of developing a user interface with button controls.
To convey the idea of interactivity to the user, buttons will change their colors when the cursor hovers over them. With the cursor being over a button, the button color will be slightly darkened, getting significantly darker when the button is clicked.
Furthermore, we will add tooltips to each button, thus creating an intuitive interface. The article will also cover some events: mouse move event, state of the left mouse button, left-click on an object and the event of modifying chart properties. We are going to create a button panel that will take up the entire space of the indicator subwindow.
For illustrative purposes, the buttons will be arranged in three rows, with four buttons in each row. Objects of this type can be made Read Only. They are also useful in that they can display text you specify. Furthermore, you can make the object's corners sharp, while keeping its border.
So, let's create an indicator using the MQL5 Wizard. Slightly reworked, the source code of the indicator will be as follows:. What we have right now is an empty window with zero plotting series. The need for a timer will be discussed a bit later.
Let's now add constants, variables and arrays that will be used in creating functions. All arrays are two-dimensional. The first dimension indicates the number of buttons across the window height and the second dimension indicates the number of buttons across the window width:.
While loading the indicator to the chart, the arrays should be initialized to object properties in the OnInit function, after calculating the coordinates and sizes. We should also enable cursor tracking. And finally, we need to add buttons to the indicator subwindow. For convenience, these actions will be performed in separate functions that we are going to look into one by one further below.
As a result, the OnInit function code will look as follows:. In the AddPrefix function, the prefix, i. Chart properties required for calculations will be initialized in the SetSubwindowProperties function:. After getting the chart properties, we can make to calculations for determining button colors, coordinate values and sizes.
All these actions are performed in three separate functions provided below:. Please note the last parameter of the CreateButton function: it is responsible for the tooltip when the mouse cursor goes over a graphical object.
You can create a separate array with more detailed descriptions, if desired. Buttons added to the indicator subwindow. At the moment, these are mere objects arranged in the indicator subwindow.
Interaction with the user is not yet implemented. Let's now "breathe life" into these objects. First of all, we will implement the possibility of adjusting button sizes according to the size of the subwindow when the latter is resized. They will set button coordinates and sizes:.
Below you can see the code you need to add to the OnChartEvent function body:. If we add the indicator to the chart now or recompile the code if the indicator is already on the chartthe buttons will automatically be resized and repositioned as soon as the chart window or the indicator subwindow is resized.The MQL4 language provides processing of some predefined events. Functions for handling these events must be defined in a MQL4 program; function name, return type, composition of parameters if there are any and their types must strictly conform to the description of the event handler function.
The event handler of the client terminal identifies functions, handling this or that event, by the type of return value and type of parameters. If other parameters, not corresponding to below descriptions, are specified for a corresponding function, or another return type is indicated for it, such a function will not be used as an event handler.
The OnStart function is the Start event handler, which is automatically generated only for running scripts. It must be of void type, with no parameters:.
For the OnStart function, the int return type can be specified. The OnInit function is the Init event handler. It must be of void or int type, with no parameters:. The Init event is generated immediately after an Expert Advisor or an indicator is downloaded; The OnInit function is used for initialization. OnInit function execution result is analyzed by the terminal's runtime subsystem only if the program has been compiled using property strict.
Download MetaTrader 5 – the trading platform for the future!
During initialization of an Expert Advisor before the start of testing you can request information about the configuration and resources using the TerminalInfoInteger function. Successful initialization, testing of the Expert Advisor can be continued. Initialization failed; there is no point in continuing testing because of fatal errors. For example, failed to create an indicator that is required for the work of the Expert Advisor. This return value means the same as a value other than zero - initialization of the Expert Advisor in the tester failed.
This value means the incorrect set of input parameters. The result string containing this return code is highlighted in red in the general optimization table. Testing for the given set of parameters of the Expert Advisor will not be executed. The OnInit function of the void type always denotes successful initialization. The OnDeinit function is called during deinitialization and is the Deinit event handler.
It must be declared as the void type and should have one parameter of the const int type, which contains the code of deinitialization reason.
If a different type is declared, the compiler will generate a warning, but the function will not be called. The Deinit event is generated for Expert Advisors and indicators in the following cases:. The NewTick event is generated for Expert Advisors only when a new tick for a symbol is received, to the chart of which the Expert Advisor is attached.
It's useless to define the OnTick function in a custom indicator or script, because the NewTick event is not generated for them. It must be declared as the void type, with no parameters:.I will 0 replies. Exit Attachments. Does anyone have or is aware of a free simple buy and sell button EA not script with mql file so that it can be edited with own MM Thanks in advance Post 2 Quote Feb 17, am Feb 17, am.
Joined Jun Status: Member 1, Posts. Had one on my hard drive I have not tested it Attached File. Post 3 Quote Feb 23, am Feb 23, am. Quoting Gvc. Post 4 Quote Feb 25, am Feb 25, am. Joined Oct Status: Member 1, Posts. Hello, This is the code that I use when I have to open trades manually when testing in the strategy tester. Post 5 Quote Feb 25, pm Feb 25, pm. Quoting Pipologist. I should have mentioned that I'm also looking for an mql file it since I plan to modify the MM and lot sizing per order.
Just need to buttons to work and send the trades, the rest I plan to modify. Thanks anyway. Regard, Ding Dong. Post 6 Quote Feb 25, pm Feb 25, pm. Joined Dec Status: Member Posts.
Post 7 Quote Feb 28, pm Feb 28, pm. Joined Jun Status: Member 40 Posts. Post 8 Quote Feb 29, am Feb 29, am. Quoting tiong No Button, but a dropdown order type list. Have fun bro. Post 9 Quote Aug 1, pm Aug 1, pm.In this video I wanted to talk to you about something that is called an event.
Maybe you know about events, they are pretty common in object-oriented programming. It also tells me the X and the Y value. For example if I click in the upper left corner here you will see that the X value is 1 and Y value is This is the X direction and this is the Y direction. So, if you know how to code an event you can use the information where somebody clicked to do something on your chart like placing a trade or setting a stop loss.
Now how can we create an Expert Advisor that is looking for chart events? Click on continue. Continue and finish. In our case we want to check for a chart event when a mouse is clicked. One event for example would be the key down event when you press a key. There are also events to change objects, and there even is an event to find out if you drag something on the chart.
You could also check for other events like: mouse move and you could even create a custom event, but for this simple example we want to check if somebody clicked on the chart. If that is the case for you please click on the little button here or press F4 to go back to Metatrader.
Now you know how to create an Expert Advisor that will output the coordinates of your mouse click on the chart and you have coded it yourself with a few lines of MQL4 code.