Hey guys.
Today I am going to share a simple function used to get a daily unique value in function of a symbol and a timeFrame.
This is useful when you want to know if you got a new bar on your chart, this is useful to avoid useless computation.
You can basically use the Bars function like that :
The Bars function isn't really efficient, that's why I developed my own function :
The way to use this function is the same, there is just an additional parameter to avoid useless call to CopyTime function (TimeCurrent call is just here to get an approximation of the result, you can't be sure to get a new bar with it, but it's really more efficient than CopyTime).
In some cases you may not have a precedent value (first call for example), so just pass -1 as the 3rd parameter.
After a basic profiling I get the following results :
62000 calls to Bars = 630 000 time units.
62000 calls to decomposeTimeFrame = 46 000 time units.
This function gives you unique results per days for every time frame between M1 to H12.
Very good job and good idea to check second before using CopyTime. Thank you for sharing.
Please note though that using Bars() isn't reliable to check new bar. As the bar count on a chart is limited by setting, once this limit is reached you don't get a new bar. Only reliable way it to work with time in all case.
Very good job and good idea to check second before using CopyTime. Thank you for sharing.
Please note though that using Bars() isn't reliable to check new bar. As the bar count on a chart is limited by setting, once this limit is reached you don't get a new bar. Only reliable way it to work with time in all case.
In fact, it's possible to get a unique value with Bars function, but to do it, you have to set unlimited MaxBars (in Graphic/MetaTrader options). This is obviously why the Bars call isn't efficient in term of Time/Space complexity.
Thank's for your feedback Ange ;)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hey guys.
Today I am going to share a simple function used to get a daily unique value in function of a symbol and a timeFrame.
This is useful when you want to know if you got a new bar on your chart, this is useful to avoid useless computation.
You can basically use the Bars function like that :
The Bars function isn't really efficient, that's why I developed my own function :
The way to use this function is the same, there is just an additional parameter to avoid useless call to CopyTime function (TimeCurrent call is just here to get an approximation of the result, you can't be sure to get a new bar with it, but it's really more efficient than CopyTime).
In some cases you may not have a precedent value (first call for example), so just pass -1 as the 3rd parameter.
After a basic profiling I get the following results :
62000 calls to Bars = 630 000 time units.
62000 calls to decomposeTimeFrame = 46 000 time units.
This function gives you unique results per days for every time frame between M1 to H12.