Forex Factory (https://www.forexfactory.com/forum.php)
-   Platform Tech (https://www.forexfactory.com/forumdisplay.php?f=69)
-   -   Is it possible to create a new symbol in MT4 (https://www.forexfactory.com/showthread.php?t=208577)

xecret Nov 27, 2009 1:39am | Post# 1

Is it possible to create a new symbol in MT4
 
For example, I want to create JPY index by some formula. I dont want it to be displayed in subwindow, but in the main chart window. Is this possible?
Thanks.

7bit Nov 27, 2009 6:05am | Post# 2

For example, I want to create JPY index by some formula. I dont want it to be displayed in subwindow, but in the main chart window. Is this possible?
Thanks.
Yes. Goto http://codebase.mql4.com/6217 and download and install offline_charts.mqh. Although i primarily wrote this library for creating realtime equity curves it mainly consists of generic functions for dealing with offline charts. It contains a function

updateOfflineChart()

Call this function on every tick with the current value of the index. If you want to create multiple timeframes then just call it once per timeframe (with a different period parameter for each timeframe).

symbol is the name for your offline chart. It can be up to 12 characters long, this is a limitation of the file format.
period accepts the period in minutes (just use metatrader's PERIOD_* constants for it)
digits is the number of digits and volume can be set to 0 if you dont have volume.

if you enable "allow dll" for your code then it will also update the offline chart window on every tick via the PostMessage() trick.

xecret Nov 29, 2009 10:14pm | Post# 3

Yes. Goto http://codebase.mql4.com/6217 and download and install offline_charts.mqh. Although i primarily wrote this library for creating realtime equity curves it mainly consists of generic functions for dealing with offline charts. It contains a function

updateOfflineChart()

Call this function on every tick with the current value of the index. If you want to create multiple timeframes then just call it once per timeframe (with a different period parameter for each timeframe).

symbol...
You genius! Thanks a lot!

omaramir Dec 8, 2019 12:29pm | Post# 4

7bit ,

I see it is old thread , but I hope to get an answer.

I downloaded you library , and write very small EA to call updateOfflineChart() with the necessary 5 parameters.
I was sure that the call is completed with the correct parameters, but nothing happened , offline chart is not opened automatically.

I manually open an offline chat and tried to make a call for the already opened offline chart , also nothing happened.

can you give detailed step how to do that ? or what mistake may be i was doing ?

thanx in advance
Omar

emmzett Dec 8, 2019 2:37pm | Post# 5

...but nothing happened , offline chart is not opened automatically...I manually open an offline chat and tried to make a call for the already opened offline chart , also nothing happened...
can you give detailed step how to do that?
Please specify what you expect to happen. Or in other words: what is it you are trying to achive?

The library provided by 7bit doesn't really do what the thread opener asked for, i.e. it doesn't create new MT4 symbols. It can create custom price histories, in this case a history of your equity curve. The resulting artefact is the price history of a single timeframe which then can be opened as an offline chart. This price history (and the chart) will have a symbol, but that's not a regular MT4 symbol.

There are ways to create real custom symbols in MT4 (what the thread opener asked for) but my gut tells me that's not what you want. So, give more information please.

omaramir Dec 8, 2019 9:50pm | Post# 6

Thank you emmzett for your reply.
I am trying to create a custom symbol for the dollar index like the one in liteforex platform or the custom symbol that can be created in mt5.
it seems the same request as of the thread opener.
after reading the 7bit reply and reading details how to call updateOfflineChart(), I expected to have offline chart , that can be updated by a call with dollar index value and the offline chart will be updated accordingly , as update will by using EA on every tick.

please tell if my understanding to 7bit reply is correct or give another way how to create custom symbl in mt4, or any other helpful information about this topic.
Thanks and regards,
Omar

emmzett Dec 9, 2019 5:14am | Post# 7

2 Attachment(s)
...I am trying to create a custom symbol for the dollar index like the one in liteforex platform or the custom symbol that can be created in mt5. it seems the same request as of the thread opener...
You are right and my gut wasn't :-)

...after reading the 7bit reply and reading details how to call updateOfflineChart(), I expected to have offline chart , that can be updated by a call with dollar index value and the offline chart will be updated accordingly...
In general it's possible with 7bit's library to calculate and record the USDLFX. However, his library creates offline charts and you would have to create all nine timeframe histories seperately. The result would be nine separate chart windows (one per timeframe) which again would need to be updated separately.

A better and less complex approach would be to create one real custom symbol with one real chart (not offline) capable of switching timeframes (which is not possible with offline charts). Something like this Click to Enlarge

Name: 29356689-b4a1e94a-827d-11e7-9fb8-38b322a56291.png
Size: 33 KB recorded by this Click to Enlarge

Name: 29356848-478fdb5e-827e-11e7-9c23-2c7a77eec287.png
Size: 71 KB

Both images are copied from here: https://github.com/rosasurfer/mt4-expander/issues/2 (the issue is only slightly related).
Formulas for the indexes can be found here: https://github.com/rosasurfer/mt4-to.../lib/synthetic

For an updatable custom MT4 symbol you need to follow these steps:

  1. disconnect one terminal
  2. create a custom symbol in this terminal (without disconnection MT4 will delete your custom symbol on the next connect)
  3. write an indicator or EA which calculates and records the history of your custom symbols in real-time (you may use 7bit's library)
  4. use the disconnected terminal for charting
  5. make sure the charting terminal automatically updates the charts with the custom symbol

If all this doesn't sound to complicated I would go in more detail (you will need some programming knowledge in MQL). The result would be two running terminals, one recording (the second screenshot), the other charting (the first screenshot). Be aware that you will never be able to trade a custom symbol from such a chart, neither in MT4 nor in MT5.


omaramir Dec 9, 2019 11:28am | Post# 8

Dear emmzet

I really appreciate every letter you typed on your keyboard to help me.

I don't see things complicated. also I have very good to excellent knowledge in MQL Programming , more than 100 EAs were written by me ( all lose money ) hahaha
but I can write code.
If you don't mind , I will follow your instruction one by one until I finish this job , in case I face some problems , I'll come back and ask for details. just please follow up with me.

but as strart I have one question.
when I open new chat , chart automatically take default symbol from the platform , how can I use other symbol not available in the platform like ( usdidx ) for example ?

sure I prefere this option
"A better and less complex approach would be to create one real custom symbol with one real chart (not offline) capable of switching timeframes (which is not possible with offline charts). Something like this "
give me please the start point

Thanks again,
Omar

emmzett Dec 9, 2019 12:31pm | Post# 9

OK, I'm going to start a new thread for it to have a main post which I'm allowed to update constantly.

omaramir Dec 9, 2019 3:53pm | Post# 10

OK , please send the link after opening the new thread

thanks ,

emmzett Dec 10, 2019 4:20pm | Post# 11

4 Attachment(s)
OK , please send the link after opening the new thread thanks ,
It turns out that right now I cannot afford the time to start and maintain a full new thread. A single post has to make it and will hopefully give you a start in the right direction.

To the main question: How to create a custom symbol in MT4?

All known terminal symbols are stored in
Inserted Code
<mt4data-dir>/history/<broker-dir>/symbols.raw
Symbols are organized in groups. Groups are stored in
Inserted Code
<mt4data-dir>/history/<broker-dir>/symgroups.raw
On every reconnect the terminal downloads the list of symbols and groups from the trade server and overwrites both files. We are going to modify those files, and that explains the need for a disconnected terminal.

Teaser: Here is a terminal's "Symbols" dialog with only custom groups and symbols. Click to Enlarge

Name: symbols-groups.png
Size: 59 KB

Once the terminal is disconnected we can edit/update the above as we wish. The format of "symbols.raw" is documented here: Symbol.h, the format of the group file is documented here: SymbolGroup.h. There are two ways to edit/modify the files, programatically or manually. I will explain both, and the way to go depends on how often one wants to create a new symbol.

The manual way:
If you want to create just a symbol for a synthetic index (a one-time task) it's overkill to implement an automated solution. Manual creation takes just a few minutes. You need a hex editor and the above format description. I recommend WinHex because it understands scriptable form templates.
A template for a basic symbol editor is here: Symbol Form Click to Enlarge

Name: symbol-form.png
Size: 36 KB

A template for a simple group editor is here: Symbol Group Form Click to Enlarge

Name: group-form.png
Size: 35 KB

You can edit and create your own groups and symbols as long as you stick to the format and know what you do. If I manually edit symbols I first split "symbols.raw" in single raw files per symbol, then I edit the single symbols, finally I copy the pieces together to the final file. Splitting/merging is done on the command line with standard shell tools. Today we use Git everywhere, so every developer is familiar with Bash. Even Microsoft gave in and ships Windows TeT (Windows for Teletubbies) with a Linux shell.
Of course you can remove whatever symbol you want and create a final file - let's say - with just one or two symbols. To simplify the process further I have templates for the most common symbol types (Forex, indexes) here: Raw Example Symbols. With those raw symbol templates I just need to change the actual symbol and the symbol description. There are some rules to follow with sorting and ids and I will extend on that if there is interest.

The automated way:
In all my EAs I have an input parameter to enable recording of the tester's equity curve (the chart generated by the tester is as useless as it can get). For this feature I use the automated way to create custom groups and symbols, directly as part of the test. Looks like that:Click to Enlarge

Name: equity-symbols.png
Size: 37 KB

For this I have a MQL library which is capable of managing custom symbols, custom symbol groups, single history files and complete history sets. The library header is here: include/rsfHistory.mqh, the implementation here: libraries/rsfHistory.mq4. Finally CreateSymbol() is used here: include/core/expert.mqh (line 609).


I guess that's plenty of material to digest for the moment. Only oddity for many will be that it's written in MQL version 4 (up to build 509) but that's the language I prefer. It's easy to convert.

So far for custom symbol creation. Recording history of a custom symbol may be the topic of another day (and you already know most of it), turning it into a seemless self-updating "online" chart is material for another one.

Enjoy :-)

omaramir Dec 14, 2019 9:58am | Post# 12

emmzett,


Wow.
interesting , I just read the details , I like the way you implement this solution. but I didn't give it a try .
I will give it a try , as it need some time , and will give you my feedback.
big thanks to you , appreciate your help.

regards, omar.

shiva Jan 12, 2020 8:27am | Post# 13

{quote} It turns out that right now I cannot afford the time to start and maintain a full new thread. A single post has to make it and will hopefully give you a start in the right direction. To the main question: How to create a custom symbol in MT4? All known terminal symbols are stored in <mt4data-dir>/history/<broker-dir>/symbols.raw Symbols are organized in groups. Groups are stored in <mt4data-dir>/history/<broker-dir>/symgroups.raw On every reconnect the terminal downloads the list of symbols and groups from the trade...
Hi @Emmzett is this something that can be added to market-watch if the broker is willing? Can you do this as a paid project?

emmzett Jan 12, 2020 9:21am | Post# 14

{quote} Hi @Emmzett is this something that can be added to market-watch if the broker is willing? Can you do this as a paid project?
"Yes" for the first part of your question. After creation such a custom symbol is automatically added to the "MarketWatch" and to the "Symbols" window. To MetaTrader it is a regular symbol without any differences. But as soon as you reconnect the terminal it will be overridden. There is a regular broker use case for this, especially for brokers which offer CFDs for futures. The symbols a broker offers may constantly change. For example the current futures contract for Brent or Crude is added and after 6 months it expires. With the mechanism of overwriting unsupported symbols the expired symbol is automatically deleted as soon as the broker deletes it on the server side - no clutter on the client side. ps: I did not experiment with write protecting the symbols file.

For the 2nd part "...if the broker is willing". "Willing" in this context means the broker has to officially offer the symbol to all customers, something which most probably will not happen. If your real question is whether custom created symbols and broker offered symbols can coexist in MT4 then it's a "no". It's for that reason that a disconnected terminal is required.

Is this a show stopper? No. Once you did it a few times you realize that the advantages outweigth the disadvantages. A real custom symbol you will create only rarely, a few indexes maybe. But the real advantage is in testing where it opens countless ways to create and analyze test results. You can literrally chart everything you want: real equity curves, drawdown, regression analysis for preventing curve fitting during optimization etc. Options are limitless.

ps: Internally MetaTrader uses a FIX dialect when communicating with the trade server. After a successful connection the first thing it does is requesting the list of currently supported symbols. After receiving that list the terminal stores the received symbols in "symbols.raw", always overwriting the former state. The "MarketWatch" window is merely a list of symbols you are - in FIX terms - subscribed to. Again that list is stored on terminal shutdown in "symbols.sel", format here: SymbolsSelected.h

shiva Jan 12, 2020 12:34pm | Post# 15

{quote} "Yes" for the first part of your question. After creation such a custom symbol is automatically added to the "MarketWatch" and to the "Symbols" window. To MetaTrader it is a regular symbol without any differences. But as soon as you reconnect the terminal it will be overridden. There is a regular broker use case for this, especially for brokers which offer CFDs for futures. The symbols a broker offers may constantly change. For example the current futures contract for Brent or Crude is added and after 6 months it expires. With the mechanism...
Hi Emmzett thank you for the very detailed and informative reply. In this case, the broker is willing to offer the new synthetic symbol (for example "C5" from the basket trading thread) to all customers.
Looking forward to your reply.
Regards

emmzett Jan 13, 2020 5:49am | Post# 16

{quote} Hi Emmzett thank you for the very detailed and informative reply. In this case, the broker is willing to offer the new synthetic symbol (for example "C5" from the basket trading thread) to all customers. Looking forward to your reply. Regards
It seems to me we talk different subjects. If a broker is willing to offer a symbol to all customers he just adds it - and that's it. In this case there is no need to do anything on the client-side, especially nothing in regard to "custom symbols". You may want to continue in PMs and not here if I mis-understood you.

ps: I don't yet know..."C5 from the basket trading thread" :-)

emmzett Jan 13, 2020 5:59am | Post# 17

...for example "C5" from the basket trading thread...
OK, now I know what C5 is. Adding this as a custom symbol in MT4 is easy, essentially a basket is an index similar to a standard currency index. I do use such indexes by myself as custom MT4 symbols. Already posted the Synthetic indexes link above, all of those I have in MT4.

If the broker is willing to offer such a basket symbol he needs to setup the price feed for it. Means he has to calculate the basket and publish prices. If the basket is not constantly rebalanced it would be a static formula and the broker shouldn't have problems. If the broker offers such a symbol nothing needs to be done on the client-side in regard to "custom symbols". If the basket needs constant rebalancing the broker will most probably reject from the idea.

If you want to setup your own price feed for C5 (without broker support) you have to calculate the basket by yourself, and feed your custom symbol by yourself. That would be the use case of the second screenshot in this link where I calculate and update custom indexes on the fly. I didn't yet go deeper into the "custom price feed" details as there was not yet interest for it in this thread.


© Forex Factory