MQL5 Reference: https://www.mql5.com/en/docs
MQL5 Codebase: https://www.mql5.com/en/code
MQL5 Articles: https://www.mql5.com/en/articles
And if those don't work for you, I'm confident you can get your project completed by using this: https://www.mql5.com/en/job
- Jack
- www.mql5.com
The article you mentioned is the right place to start. What's not clear for you? I'd suggest to create an expert advisor, since you need to use WebRequest to poll new data from your feed provider. Then create bars and ticks according to the data.
To simplify the task a bit you can use the library Symbol (available in Russian only yet, but downloadable).
To create a brand new custom symbol write something like this:
SYMBOL Symb(CustomSymbolName);
Symb.CloneProperties(_Symbol);
SYMBOL here is a class from the library. CustomSymbolName is a string variable with your custom symbol name.
The method CloneProperties copies all properties from current chart _Symbol (so you have no need to call many functions to setup the custom symbol properly, but I'm not sure if you can find an existing symbol which can be used a template for your custom symbol). If you need to alter some of inherited properties, use Symb.SetProperty(...). Don't forget to select new symbol to the market watch - Symb.On() or standard SymbolSelect().
Then use CustomRatesUpdate, CustomTicksAdd as appropriate. The last one makes your custom symbol tradeable online, that is expert advisers, placed on such charts will receive OnTick event and can execute orders if you wish - just don't forget that the custom symbol should be replaced with something other available on MT server.
NB: Be patient. This is a new functional. You will most likely encounter some bugs.The article you mentioned is the right place to start. What's not clear for you? I'd suggest to create an expert advisor, since you need to use WebRequest to poll new data from your feed provider. Then create bars and ticks according to the data.
To simplify the task a bit you can use the library Symbol (available in Russian only yet, but downloadable).
To create a brand new custom symbol write something like this:
SYMBOL here is a class from the library. CustomSymbolName is a string variable with your custom symbol name.
The method CloneProperties copies all properties from current chart _Symbol (so you have no need to call many functions to setup the custom symbol properly, but I'm not sure if you can find an existing symbol which can be used a template for your custom symbol). If you need to alter some of inherited properties, use Symb.SetProperty(...). Don't forget to select new symbol to the market watch - Symb.On() or standard SymbolSelect().
Then use CustomRatesUpdate, CustomTicksAdd as appropriate. The last one makes your custom symbol tradeable online, that is expert advisers, placed on such charts will receive OnTick event and can execute orders if you wish - just don't forget that the custom symbol should be replaced with something other available on MT server.
NB: Be patient. This is a new functional. You will most likely encounter some bugs.Thanks a lot Stanislav,
I've created a EA as you suggested to create the symbols and update the charts, it's working great with some random data I provided!
For now, the EA creates and select a symbol on OnInit function, I also set a timer on that function so I can use OnTimer function to update the chart.
So far this works great, but there are some caveats, Do I need to obligatory assign my EA to a symbol? When I run it from MetaEditor it is automatically assigned to EURUSD,1H, since I want it to create all my custom symbols and manage then, I don't want the EA to be assigned to a specific symbol, is that possible?
Also, on the OnTimer function, I use the CustomRatesUpdate function to update my custom symbol rates data. That's works great, but if I open a chart for that symbol before the update, it will not redraw the chart automatically.
My somewhat solution now is to iterate through all the opened charts after CustomRatesUpdate call on OnTimer function, find which ones are from my custom symbol and call ChartRedraw manually, this works, but it seems very "hacky", and possibly a bottleneck. Is there a better way?
Thanks again for the help!
For now, the EA creates and select a symbol on OnInit function, I also set a timer on that function so I can use OnTimer function to update the chart.
So far this works great, but there are some caveats, Do I need to obligatory assign my EA to a symbol? When I run it from MetaEditor it is automatically assigned to EURUSD,1H, since I want it to create all my custom symbols and manage then, I don't want the EA to be assigned to a specific symbol, is that possible?
Also, on the OnTimer function, I use the CustomRatesUpdate function to update my custom symbol rates data. That's works great, but if I open a chart for that symbol before the update, it will not redraw the chart automatically.
My somewhat solution now is to iterate through all the opened charts after CustomRatesUpdate call on OnTimer function, find which ones are from my custom symbol and call ChartRedraw manually, this works, but it seems very "hacky", and possibly a bottleneck. Is there a better way?
It seems you make it right. EA runs on a specific symbol by design (MQ is about to release some other kind of MQL programs called services, then it'll probably better suite your needs), but you can manipulate with any symbols taken from input parameters, or market watch, or by other means.
I think it's normal that a chart is not redrawn until update. After the call to CustomRatesUpdate the chart is updated automatically for me. I'm not sure why this should work in some other way.
It seems you make it right. EA runs on a specific symbol by design (MQ is about to release some other kind of MQL programs called services, then it'll probably better suite your needs), but you can manipulate with any symbols taken from input parameters, or market watch, or by other means.
I think it's normal that a chart is not redrawn until update. After the call to CustomRatesUpdate the chart is updated automatically for me. I'm not sure why this should work in some other wayhi
hi
can you share how you achieved chart drawing because i always get "invalid bars removed" message
here is my function i used
void test(){
MqlRates rates[6] ;
rates[5].tick_volume = 30;
rates[5].open = 8195;
rates[5].high= 8225;
rates[5].low = 8170.00000012;
rates[5].close = 8218;
// rates[5].real_volume = 18.17088531;
rates[5].time = StringToTime("2018-05-18T20:30:00");
//============================================
rates[4].open = 8253.999;
rates[4].high= 8279.8;
rates[4].low = 8185.42;
rates[4].close = 8195;
rates[4].tick_volume = 30;
// rates[4].real_volume = 38.07927949;
rates[4].time = StringToTime("2018-05-18T20:00:00");
//============================================
rates[3].open = 8184.2914175;
rates[3].high= 8256;
rates[3].low = 8168.89957407;
rates[3].close = 8200.05;
rates[3].real_volume = 28.03767055;
rates[3].time = StringToTime("2018-05-18T19:30:00");
//============================================
rates[2].open = 8200;
rates[2].high= 8280;
rates[2].low = 8191.37100003;
rates[2].close = 8191.37100011;
rates[2].tick_volume = 30;
// rates[2].real_volume = 63.14678309;
rates[2].time = StringToTime("2018-05-18T19:00:00");
//============================================
rates[1].open = 8072.49417662;
rates[1].high= 8232;
rates[1].low = 8072.49417662;
rates[1].close = 8200;
rates[1].tick_volume = 30;
// rates[1].real_volume = 103.66347596;
rates[1].time = StringToTime("2018-05-18T18:30:00");
//============================================
rates[0].open = 8067.06000002;
rates[0].high= 8123.06000002;
rates[0].low = 8067.06000002;
rates[0].close = 8072.49417619;
rates[0].tick_volume = 30;
//rates[0].real_volume = 19.286082;
rates[0].time = StringToTime("2018-05-18T18:00:00");
ArrayGetAsSeries(rates);
CustomRatesUpdate(Symbol(),rates);
}
the result :
2018.05.19 00:10:01.647 History 'USDT-BTC' invalid bar 2018.05.19 00:10 (0), high price 8123.06000002 is much bigger than open price 8067.06000002 [delta: 5600000000]
2018.05.19 00:10:01.647 History 'USDT-BTC' invalid bar 2018.05.19 00:10 (0), high price 8232.00000000 is much bigger than open price 8072.49417662 [delta: 15950582338]
2018.05.19 00:10:01.647 History 'USDT-BTC' invalid bar 2018.05.19 00:10 (0), high price 8280.00000000 is much bigger than open price 8200.00000000 [delta: 8000000000]
2018.05.19 00:10:01.647 History 'USDT-BTC' invalid bar 2018.05.19 00:10 (0), high price 8256.00000000 is much bigger than open price 8184.29141750 [delta: 7170858250]
2018.05.19 00:10:01.647 History 'USDT-BTC' invalid bar 2018.05.19 00:10 (0), low price 8185.42000000 is much lower than open price 8253.99900000 [delta: 6857900000]
2018.05.19 00:10:01.647 History 'USDT-BTC' invalid bar 2018.05.19 00:10 (0), close price 8218.00000000 is much bigger than open price 8195.00000000 [delta: 2300000000]
2018.05.19 00:10:01.647 History 'USDT-BTC' 6 invalid bars removed
i am searching for days but not found any solution so if you can guid to solve the issue, i will be very grateful ;
@cvb255
Try creating M1, on success all other TimeFrames will be created automatically. The Terminal complains because it detects very big difference in the values, measured in points. In M1 the difference between High, Low, etc will be the minimum possible. If this not working again, the only thing you can do is decreasing the price precision. From the main menu -> Vew -> Symbols -> Custom -> Right click on your custom symbol "USDT-USD" and choose Custom Symbol Change. Then change the property "Digits" to 5 or even lower if still not working. This is the price in USD, so I believe you don`t need more precision than 3 (cents and fraction of a cent).
Also remove the row 'ArrayGetAsSeries(rates)', it`s useless. And modify 'CustomRatesUpdate(Symbol(),rates)' to 'CustomRatesUpdate("USDT-USD",rates)'.
It`s good idea to use NormalizeDouble() when applying values for Open,High, Low, Close using variable, to set the desired precision.
The Time format must look like this: StringToTime("2018-05-18 18:00:00");
Hope this will help.
@cvb255
Try creating M1, on success all other TimeFrames will be created automatically. The Terminal complains because it detects very big difference in the values, measured in points. In M1 the difference between High, Low, etc will be the minimum possible. If this not working again, the only thing you can do is decreasing the price precision. From the main menu -> Vew -> Symbols -> Custom -> Right click on your custom symbol "USDT-USD" and choose Custom Symbol Change. Then change the property "Digits" to 5 or even lower if still not working. This is the price in USD, so I believe you don`t need more precision than 3 (cents and fraction of a cent).
Also remove the row 'ArrayGetAsSeries(rates)', it`s useless. And modify 'CustomRatesUpdate(Symbol(),rates)' to 'CustomRatesUpdate("USDT-USD",rates)'.
It`s good idea to use NormalizeDouble() when applying values for Open,High, Low, Close using variable, to set the desired precision.
The Time format must look like this: StringToTime("2018-05-18 18:00:00");
Hope this will help.
thank you for help , the issue was in time format i replaced this dashes to dots and removed milseconds like (yyyy.mm.dd hh:mi)
Thanks a lot Stanislav,
I've created a EA as you suggested to create the symbols and update the charts, it's working great with some random data I provided!
For now, the EA creates and select a symbol on OnInit function, I also set a timer on that function so I can use OnTimer function to update the chart.
So far this works great, but there are some caveats, Do I need to obligatory assign my EA to a symbol? When I run it from MetaEditor it is automatically assigned to EURUSD,1H, since I want it to create all my custom symbols and manage then, I don't want the EA to be assigned to a specific symbol, is that possible?
Also, on the OnTimer function, I use the CustomRatesUpdate function to update my custom symbol rates data. That's works great, but if I open a chart for that symbol before the update, it will not redraw the chart automatically.
My somewhat solution now is to iterate through all the opened charts after CustomRatesUpdate call on OnTimer function, find which ones are from my custom symbol and call ChartRedraw manually, this works, but it seems very "hacky", and possibly a bottleneck. Is there a better way?
Thanks again for the help!
Hi, I am currently trying to do the same thing, to build custom price chart by retrieving data from Binance, do you mind to share you code for this? Really appreciate your kindness :)
Thank you
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello there,
I'm trying to learn how to create a MQL5 library for MT5 (I think it should be a library, but not so sure) to create new symbols and feed these symbols chart data from public exchanges APIs in real time.
I tried searching for some tutorial or example of something in these lines, but the best I could found was this https://www.mql5.com/en/articles/3540. Maybe I'm not search with the correct keywords.
I'm not asking for a complete tutorial or example code to do just that, but maybe some simpler examples so I can have a direction on how to accomplish it.
So, in a nutshell, is there some example codes, tutorials or documentation on how to programmatically create new custom symbols, retrieve chart data from the web, add these data to the custom symbol chart and update it's data in real time (or near real time)?
Any help in this regard will be much appreciated!