Mql4 draw line on chart

Graphical object is an image in the symbol window; it can be selected, moved, modified or deleted. Graphical objects include, for example, horizontal and vertical lines, linear regression channel, Fibonacci levels, rectangle, text mark, etc.

Such images as indicator lines, indicator levels, candlesticks, comments written by the Comment function and others cannot be selected and deleted, that is why they do not belong to graphical objects.

Graphical object are drawn by the client terminal in a security window in accordance with preset coordinates. Each graphical object depending on its type has one, two or three coordinates and other adjustable parameters. Any graphical object can be placed in a chart window manually from the toolbar of a system menuand also as a result of the execution of an application program started in the same window, including an Expert Advisor, script or custom indicator.

Type and location of a graphical object can be modified manually or by a program sending new values of coordinates and other parameters to a graphical object. There are two ways of positioning objects accepted in MQL4: relative to a chart and relative to a security window. We can use A and T buttons from the toolbar of the client terminal. Let us set the window size so that it is equal to half of screen size Fig. Let us see how these graphical objects will react to the window size changes as well as to the horizontal and vertical scaling of the price chart.

Graphical objects with different methods of positioning in a security window. But if the window size is changed by shifting its upper or lower border, the object will be also shifted, though the position of the object relative to these borders will remain unchanged. In this case the reference point of the graphical object to a security window is the upper left corner of a chart6 window.

Coordinates of the object relative to the indicated point are set in pixels - and 48 Fig. The reference point of the object coordinates in this case is the upper left corner of a cursor frame visible when selected by a mouse.

In the upper left corner of the cursor frame you can see a small point indicating the settings of this graphical object. If another reference point is indicated, the point in the cursor frame will be indicated in another corner. Using of this object is convenient if it is necessary to display text information of general character, for example, information about termination of trading, value of a limiting distance changed by a broker, etc. The reference point of such an object is the middle of the upper line of a cursor frame, its X coordinate is time, Y coordinate is a security price Fig.

This or that method of positioning the own property of a certain object type and cannot be changed by a user, even in a program way. The majority of graphical objects is positioned relative to a chart, i.

To create a graphical object means to place in a chart window one of objects of predefined types see Types and Properties of Graphical Objects. For object creation the following function is used:. The function creates an object of an indicated type with a preset name and coordinates in the indicated chart subwindow.

Can an EA draw lines on a chart?

Number of the object coordinates can be from 1 to 3 depending on the object type.By using our site, you acknowledge that you have read and understand our Cookie PolicyPrivacy Policyand our Terms of Service.

The dark mode beta is finally here. Change your preferences any time. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. One may create one's own Symbol -name so as to avoid name-colliding cases in the History Center database. Graph to process directly objects, related with FTSE. Yes, if asked to, one may implement a few add-ons and develop a sofisticated distributed processing model to make this work "accross" the said context-binding borders.

This way, once the MT4 session starts, the pre-fabricated files are pilot-tape auto-loaded and displayed as one wishes to, Q. Learn more. Ask Question. Asked 4 years, 2 months ago. Active 4 years, 2 months ago. Viewed 1k times. If that's the case, how can I do it in the simplest way?

Bryan Horna Bryan Horna 1 1 silver badge 11 11 bronze badges. Active Oldest Votes. Please do not use comments to badger askers into accepting your answer. They are free to accept whatever answers they want, whenever they want. All of these comments have been removed. Brad, what reason do you have for such a proposed asymmetry? A bit Orwelish equality, isn't it? Quo bono pro? Nagging is gauche. If you're gonna comment, be educational not demanding. Sign up or log in Sign up using Google. Sign up using Facebook.

Sign up using Email and Password.

Horizontal Line, MQL4, How to draw Horizontal Line

Post as a guest Name.When accessing certain properties, it's necessary to specify an additional parameter-modifier modifierwhich serves to indicate the number of chart subwindows.

Scrolling the chart horizontally using the left mouse button. Mode of price chart indent from the right border. Mode of automatic moving to the right border of the chart. Allow the chart to intercept Space and Enter key strokes to activate the quick navigation bar. It allows you to quickly change a symbol, timeframe and first visible bar date. Display Bid values as a horizontal line in a chart.

Display Ask values as a horizontal line in a chart. Display Last values as a horizontal line in a chart. Display vertical separators between adjacent periods.

Display textual descriptions of objects not available for all objects. The number of bars on the chart that can be displayed. The total number of chart windows, including indicator subwindows.

mql4 draw line on chart

The distance between the upper frame of the indicator subwindow and the upper frame of the main chart window, along the vertical Y axis, in pixels. In case of a mouse event, the cursor coordinates are passed in terms of the coordinates of the main chart window, while the coordinates of graphical objects in an indicator subwindow are set relative to the upper left corner of the subwindow.

Number of the first visible bar in the chart. Indexing of bars is the same as for timeseries. Color for the up bar, shadows and body borders of bull candlesticks.

mql4 draw line on chart

Color for the down bar, shadows and body borders of bear candlesticks. Line chart color and color of "Doji" Japanese candlesticks. Line color of the last executed deal price Last. Color of stop order levels Stop Loss and Take Profit.Forex trading is all about history ,in fact technical analysis is entirely based on market history data so taking account of your trading activities on the past is essential for your future success in trading.

MT4 provides account history which shows you a table of your previous trading positions with green and red colors indicating if the position was successful or not or if the position hit the take profit or the stop loss targets. While account history table is a such helpful feature of MT4 ,it is still not presented on the most useful way for traders i.

A technical analysis trader use charts to take actions and use charts to spot opportunities so the best way for him to learn from his past mistakes or successful experiences should be also through the charts.

Therefor we need a way to plot past taken positions both winners and losers on the chart ,this is the subject of this article. Download the script from this link. Next open your MT4 Scripts folder then copy the script there. Now you can easily learn from your winners and losers positions by putting them in front of your eyes. You can spot weaknesses of your trading plans for things such as bad take profit and stop loss targets.

You can also make sure if you have entered the previous trade with a good trading setup or it was just an emotional action. Let's start by the first easy way to show a past position Drag and drop position to chart Newer versions of MT4 allows you to show a past position on chart ,all you need to do is to Go to your MT4 account history tab Look for the trade you want to show on the chart Drag the position and drop it on the chart That is it ,you should now be able to see three indicators The blue arrow indicates the entry of the position.

The blue underscore indicates the target of the position. The red shape indicates the stop loss which was hit. Use OrderHistory. To use it ,just follow the steps below Download the script from this link Next open your MT4 Scripts folder then copy the script there. Sponsored Links. Let's stay connected!I have left out the code to draw the vertical part of the cross for ease. You can see that the line to the right of centre is not the same length as the line to the left due to 'Weekend' time bars - i.

This is on the 4 hour chart. If the 30M chart is chosen there is no problem because the scale becomes more linear relative to the time being added to create the new line although this also could be better - see below.

ObjectCreate

The vertical line is easy and consistent because the time scale is linear. My code above calculates a 20 bar random time span to the left and adds the same time span in seconds to form the right hand side of the cross. Anyway, the reason it doesn't work with the code I am using is because the bars are drawn as 4 hours bars but at weekends there is a 2 day gap between bars. This does not work if the line projects beyond Time[0] - you get an error " array out of range " because you cannot have Time[-1].

The 20 bars is arbitrary it can be anything depending on how long you want the line to be. I work out the line length to the left in seconds difference in time between centre of cross and 20 bars away and add the same amount of seconds to the right side.

Bars do have a weekend gap! It' useful to know there is a PeriodSeconds function I don't think this was available previously!

mql4 draw line on chart

I'm not sure you are completely correct but you have given me an idea which I will need to try. We have to ignore the fact that I have drawn a 'cross' - as I mentioned it is just for emphasis and in fact forget completely about the vertical line. The starting point is literally a 'point' i. The challenge is to draw a short horizontal line that extends either side of that point equally for all timeframes for aesthetic effect. If you count 'X' seconds to the left even using PeriodSeconds all it does is convert 'X' Bars to seconds.

If there is a weekend in the time span being calculated but there isn't on the right hand side of the starting point the whole thing becomes. I think I understand what you are saying which is to check how many weekends weekend Bars there are either side of the starting point and compensate accordingly.

This might work but is a real drag for just drawing a line!! Why isn't there a function that allows you to draw a line like this using coordinates? Completely independent of time? I still have to ask the question why MQL can't do this but for just a simple line? Drawing Short Horizontal Lines. To add comments, please log in or register. Any ideas please? Vertical Line Problem. Carl Schreiber Keith Watford You have to reset the 2nd time value at every new bar Use iBarShift to find the center of the cross if you find that eg.

Vline 50 bars after Get Values of Channel's numbers of bars since. If there is a weekend in the time span being calculated but there isn't on the right hand side of the starting point the whole thing becomes non-linear.

Alain Verleyen The function creates an object with the specified name, type, and the initial coordinates in the specified chart subwindow of the specified chart.

There are two variants of the function:. The function creates an object with the specified name, type, and the initial coordinates in the specified chart subwindow:. The name must be unique within a chart, including its subwindows.

The specified subwindow must exist window index must be greater or equal to 0 and less than WindowsTotalotherwise the function returns false. When the function is used on the current chart, the chart is accessed directly a usual behavior in MQL4and the return of true means a successful creation of an object; otherwise false is returned.

In this case, you should call GetLastError for further information about the error. To create objects on a different size, an asynchronous function call is used, and ObjectCreate only returns the result of command adding to the chart queue. In this case true means that the object creation command has been successfully enqueued, while the command execution result is unknown. To check the command execution result, you can use the ObjectFind function or any other function that request object properties, such as ObjectGetXXX.

However, you should keep in mind that such functions are added to the end of the queue of that chart, and they wait for the execution result due to the synchronous calland can therefore be time consuming.

An object name should not exceed 63 characters. Characters not belonging to the current code page are not allowed characters that cannot be converted from Unicode to ANSI are replaced with '?

If programs are to be distributed among users with different code pages, we strongly recommend using Latin characters in object names. The chart sub-windows if there are sub-windows with indicators in the chart are numbered starting from 1.

The chart main window always exists and has the 0 index. Coordinates must be passed in pairs: time and price. Object types. Object Functions ObjectName. ObjectCreate The function creates an object with the specified name, type, and the initial coordinates in the specified chart subwindow of the specified chart.These are functions for working with charts.

All chart operations are allowed in Expert Advisors and scripts only. The functions defining the chart properties are actually used for sending change commands to the chart. If these functions are executed successfully, the command is included in the common queue of the chart events. The changes are implemented to the chart when handling the queue of the chart events. Thus, do not expect an immediate visual update of the chart after calling these functions.

Generally, the chart is updated automatically by the terminal following the change events - a new quote arrival, resizing the chart window, etc. Use ChartRedraw function to forcefully update the chart. Applies a specific template from a specified file to the chart. Saves current chart settings in a template with a specified name. Returns the number of a subwindow where an indicator is drawn. Converts the X and Y coordinates on a chart to the time and price values.

Opens a new chart with the specified symbol and period. Returns the ID of the first chart of the client terminal. Returns the chart ID of the chart next to the specified one. Returns the symbol name of the specified chart. Returns the period value of the specified chart. Sets the double value for a corresponding property of the specified chart.

Sets the integer value datetime, int, color, bool or char for a corresponding property of the specified chart. Sets the string value for a corresponding property of the specified chart. Returns the double value property of the specified chart. Returns the integer value property of the specified chart. Returns the string value property of the specified chart. Performs shift of the specified chart by the specified number of bars relative to the specified position in the chart.

Removes an indicator with a specified name from the specified chart window. Returns the short name of the indicator by the number in the indicators list on the specified chart window. Returns the number of all indicators applied to the specified chart window. Returns the number index of the chart subwindow the Expert Advisor or script has been dropped to. Returns the price coordinate of the chart point the Expert Advisor or script has been dropped to.

Returns the time coordinate of the chart point the Expert Advisor or script has been dropped to. Returns the X coordinate of the chart point the Expert Advisor or script has been dropped to. Returns the Y coordinate of the chart point the Expert Advisor or script has been dropped to.

mql4 draw line on chart

Changes the symbol value and a period of the specified chart. Provides a screenshot of the chart of its current state in a gif format. Returns a text string with the name of the current financial instrument. Returns the amount of bars visible on the chart. Returns the name of the executed Expert Advisor, script, custom indicator, or library.

Returns the window index containing this specified indicator.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *