Refreshing offline charts - background, performance and solution ideas - page 2

To add comments, please log in or register
Stanislav Korotky
31694
Stanislav Korotky  
alphatrading:

Because (1) the DLL ensures more strict error checking and (2) the signature

is much easier to understand and to use then memmove/memset. I don't want to put system calls and potentially dangerous pointer arythmetics into MQL code. Last but not least, maintenance is an important factor, too.

Of course you are free to run a loop in MQL and skip the DLL alltogether. This is just one of many possibilities to do it.

From the maitenance (and development) point of view the excessive DLL is a minus, not a plus IMHO. Also, many people here do not have means to edit cpp sources (when required) and compile a DLL. The signature of the function will remain the same if you implement it in pure MQL using system calls inside. No loops needed. But I see your point.

I'll post my solution of the problem below.

Stanislav Korotky
31694
Stanislav Korotky  
JHawk:

I have to digest it.... and it will surely help.

German: Vielen vielen Dank :-) Ich muss das erst mal verdauen. Aber es hilft massiv, selbst wenn ich nicht den gleichen Weg gehe. Aber ich verstehe das Ganze jetzt viel besser. Und es hilft auch zu wissen, dass ich mit meiner Anforderung nicht alleine bin. 

Hi, JHawk! I have another solution for you. I think it's more effecient, simple, and based on native features of MetaTrader. Below I'm attaching a test indicator which demonstrates this approach by showing a line of close prices on an offline chart.

As I wrote before, you can distinguish real refresh from the simulated refresh by analyzing solely number of bars and timestamp of the last bar (since IndicatorCounted is not reliable after our "soft refresh" and should not be used). As for automatic shifting of bars with indicator data, which is missing on offline charts, MT4 provides a function SetIndexShift. Using this function you can dynamically adjust indexing of bars in the indicator, so there is no need to move data on every new bar.

The only drawback of the method is that you need to reserve a predefined number of spare bars which you can use to shift data. When this limit is reached, the indicator will throw the full refresh. For example, if you reserve 100 bars, you'll get full recalculation on every 100-th bar, but on other 99 bars you'll not have any overheads.

It works for me, but it would be interested to test it in your environment.

Files:
Offline.mq4 3 kb
Stanislav Korotky
31694
Stanislav Korotky  
Should we probably ask a moderator to edit the title of this thread to something more applicable? I find current wording (especially "reloading", shouldn't be "refreshing"?) a bit inappropriate for underlying problem. Also "offline charts" are not mentioned at all, but this is essential.
JHawk
63
JHawk  
Stanislav Korotky:
Should we probably ask a moderator to edit the title of this thread to something more applicable? I find current wording (especially "reloading", shouldn't be "refreshing"?) a bit inappropriate for underlying problem. Also "offline charts" are not mentioned at all, but this is essential.

Hello Stanislav,

yes you may do this as you like. Meanwhile this discussion becomes more and mor interessting for many people I think.

How is this: "Refreshing offline charts - background, performance and solution ideas"


Sorry - I looked - but haven't found a link to inform a moderator. Mail to mql5-website? If you like, you can change the title and please tell me how this is done.

Stanislav Korotky
31694
Stanislav Korotky  
JHawk:

yes you may do this as you like. Meanwhile this discussion becomes more and mor interessting for many people I think.

How is this: "Refreshing offline charts - background, performance and solution ideas"

Sorry - I looked - but haven't found a link to inform a moderator. Mail to mql5-website? If you like, you can change the title and please tell me how this is done.

I'm not a moderator, but they read the thread as well. The updated title suggestion is ok.

alphatrading
100
alphatrading  
Now the thread title is really mis-leading.  It is in no way about refreshing offline charts. It is about shifting indicator buffers to re-use data stored in it.
William Roeder
19857
William Roeder  
int onTick() {
   // original Valid/ChangedBars values for regular charts (might be modified in offline charts)
   int ValidBars   = IndicatorCounted();
Makes no sense. Indicators use IndicatorCounted (old way) or OnCalculate (new way.) EAs use OnTick (new way.) There is no onTick(). Start using the new Event Handling Functions.
          Event Handling Functions - Functions - Language Basics - MQL4 Reference
Stanislav Korotky
31694
Stanislav Korotky  
whroeder1:
Makes no sense. Indicators use IndicatorCounted (old way) or OnCalculate (new way.) EAs use OnTick (new way.) There is no onTick(). Start using the new Event Handling Functions.
          Event Handling Functions - Functions - Language Basics - MQL4 Reference

You did not understand. This is a part of a large MQL library - available via presented links on GitHub - where its own "events" are defined for all types of MQL programs. onTick is not MetaTrader's function (otherwise it would be capitalized) but a special library function called from oldfashioned start (see here for example).

12
To add comments, please log in or register