Trace function skips sometimes

I have multiple AFLs running on multiple charts with real time data, I use trace function to identify when a certain conditions meets on a chart, but randomly I see that condition was met and still there was no trace and if I bar replay same day then that trace works. Sometimes it works correctly for weeks with no missing trace. So, I want to understand what might cause these random skips in the trace function? Thanks in advance.

This missing on traces happens on non-active charts only whenever it happens, and I use "RequestTimedRefresh( 1, onlyvisible = False );" function in each of my AFL so that non-active charts are also updated every second.

@harshitsinghal, I suggest to review this past thread - in particular - the @Tomasz's answers that highlight the fact that real-time updates frequency is set in the preferences so normally no RequestTimedRefresh is needed for RT-fed charts (via a correctly written plug-in...)

Since I do not do any RT-intraday trading I'm not aware what happens to "minimized" (RT connected) windows.
Anyway, as explained in the RequestTimedRefresh documentation (and in the last messages of the above linked thread), you can try to set the refresh to 0.1 second creating a specific key in the registry and see if this will solve your problem.

More in general, this KB article is also good to better understand When and how often afl code is executed

@beppe , Thanks for your reply, I referred to the past thread you mentioned, but my main query is regarding getting traces on non-active windows without miss, I only use RequestTimedRefresh to keep non visible windows active, I am not aware if there is any other better way to do this, if there is then please do let me know.

First to clear up some naming misconceptions. It is not about window being "active" but about "visible". In Windows ONE window is active (has focus), while multiple Windows can be visible. All visible windows are repainted automatically. Windows OS itself does not repaint windows that are totally invisible (minimized, hidden). This is done to save resources as generally constantly repainting something that you don't see makes no sense. RequestTimedRefresh is provided to force timed updates even if window is obscured/minimized.

_TRACE() is never skipped. If it is called from your formula that it always appears. Most likely it is your condition that you think is met is not really met.

To get better understanding of what is happening in your code and how functions work, use advice given here: How do I debug my formula?

@Tomasz , Condition is met for sure as the same AFL is running on multiple machine on same data at same time on same internet, and trace works when I replay the bar that means the condition was met. What I think is that it has something to do with repainting the minimized or hidden window. I have been running this AFL for like more than a year and this missing of trace has occurred only 10-15 times. So please help me understand if there is a way to force repaint the windows using some function or some setting?

@harshitsinghal, did you attempt to set the refresh rate to 0.1 seconds as suggested to see if this mitigates the issue or if the result is the same as before?
(Without the registry setting you are refreshing only at approximal one full second rate.)

What happens on the "other machine" is not really proving or disproving anything.
You don't know if condition is met or not UNLESS you can verify it by using UNCONDITIONAL _TRACE() output. Add unconditional _TRACE to really know what happens on the machine you have problems with.

Also I would strongly advise AGAINST using 0.1 second refresh for all hidden windows as it would put extreme load on your computer if you have many hidden windows and your AFL is not written in optimum way. Quite easily with 10 windows and your single AFL taking 0.1 second you end up having 100% CPU usage for those hidden windows. It is really bad idea.

Im using 16 charts for running a portfolio trading strategy and not every chart are active hence forced to use

RequestTimedRefresh(1, False);

That is spiking the load factor beyond 100% what is the recommended optimal way for portfolio algo traders who run multiple charts at the same time for Automated trading?

1 Like

Fix your AFL code. Properly written formula should execute well below 10ms.
Use "Check Code and Profile" in AFL Editor to find out what you can do better.

Alternatively you can use Analysis window (scan/exploration) for auto-trading. It is better suited for large number of symbols.

After Implementing a sub-second refresh the load factor got down drastically as suggested by @beppa

Exploration-based automated trading I'm using 3-sec refresh. However, I'm afraid will that creates any delay in the trade execution.

image

The main problem on your end is the 3rd party data source that you are using. This "GDFL" plugin for data access alone uses MORE TIME (79ms) than ALL your formulas combined (66ms).

Also those windows are VISIBLE, not hidden, so you don't need timed refreshes at all.
Third thing is that time needed to refresh charts does NOT depend on arguments that you pass to RequestTimedRefresh.

Fourth thing is that "Load factor" is not relevant anymore if you have multi-threading chart enabled (chart refreshes don't use main UI thread).

1 Like

If sometimes accidentally Amibroker goes to minimized state orders are not getting fired. And hence used requesttimerefresh to send orders even if Amibroker is minimized.

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.