Idea: AFLs not associated with a chart

I've been through many different charting packages and all of them seem to have one central theme. You write a script, set the timeframe and that script is associated with a chart where your calculations are plotted.

But I've always wondered why. Why can't a script just run on any timeframe you want, not associated with a chart window then any information from it can be communicated via static variables to another script which IS attached to a chart? In this way, you can run the same (unaltered) script in multiple timeframes and on multiple CPU cores.

The utliity of this is that I can easily show multiple timeframe data on a chart centered in any base timeframe I want (for plotting). For example, I can calculate the same formula for determining support/resistance in multiple timeframes and send the upper/lower ranges from each script not attached to a chart and have a script that receives their calculated values via static variables do all of the plotting,

I would envision a dialog window where you select the AFL and timeframes you want it to run on in the background. Any plotting functions within them (e.g., plot, Gfx, Gui) would be skipped over since there's no chart attached to the AFL. I could basically suspend any background AFL from taking up any appreciable CPU time on a core by wrapping the script in a big IF statement associated with a static variable that another AFL script running could change the value of.

I know there's the TimeFrame series of function calls in AFL but the above is a different concept and utliity. And I have no idea of whether Amibroker is architected in a way already to easily apply this kind of runtime model. But I won't know unless I ask.

First of all, formula does NOT need to have chart attached.

In Analysis there is no chart attached at all. Scan, Exploration, Backtest, Optimization, Walk forward - they don't use any attached charts.

With regards to charts, they have separate formulas because it makes it USER FRIENDLY and multi-threading friendly (you don't have to be programmer and you don't need to care about anything like synchronization). To plot a chart you just need single line Plot( C, "name", colorDefault )
and you just don't care about data, communication, synchronization, anything.

AmiBroker uses multiple cores automatically per EACH chart pane. You don't need to do ANYTHING. AmiBroker takes care that every formula runs in separate thread and does not need to care what other threads are doing.

Multithreading in AmiBroker just works, like iPod - you have just Play button and it plays music. You get multithreading hassle-free in AmiBroker.

Last but not least - multiple charts CAN SHARE single formula including charts using different timeframes. It is what "Insert Linked" does. Read the How to use 'drag and drop' charting interface (scroll down to "Frequently asked questions" section)

This is a mockup of a dialog to communicate my idea better I think than my original textual description.

I envisioned a dialog window where the user could select multiple symbols, formulas and timeframes to launch into the background. [The selection process could be the standard Windows rules related to Shift-Left Click and Ctrl-Left Click mouse selections so the user wouldn't have to perform repetitive Adds or Removes] So the Add is related to the combinations of the selections from the top 3 list boxes in order to launch the <symbol, formula, timeframe> combinations into a background running state and the Remove button is related to terminating the user selected currently running background AFL scripts.

The use case is to have a script that's associated with a chart be able to receive or send information from the scripts running in the background via static variables. The AFL file associated with the chart (i.e., the foreground script) could be completely different (in most cases) from the background ones it is drawing higher or lower timeframe information from.

Also, I can change the timeframe of the chart window to anything I want and it won't matter. It controls what it wants to display on the chart based on the timeframe it knows it's in relative to the background ones.

There's a lot of possibilities here I'm sure that I haven't thought of. And something like this is fast and easy for the user to launch or remove background AFL scripts running on multiple timeframes. Exciting times are ahead now that 8 and 12 core CPUs are coming into a reasonable price range.

AFL Script Launcher mockup

Oh, forgot to add this in the mockup dialog.

There could also be a column, in the bottom grid, telling the user how fast in milliseconds each script in the background is running.

All AFLs run in multiple threads and they are all running in "background" ALREADY (i.e. parallel to main UI thread that is NOT doing any AFL work). All charts and all analysis windows run AFLs in separate worker threads already and they are NOT using UI (main) thread. This is all asynchronous already.


What you're describing is all fine.

But there is no current user interface to select a bunch of symbols, formulas and timeframes in any combination a user would want, all in a simple dialog, and launch them onto independent threads and manage them (i.e., remove selected background scripts running a respective symbol, formula, timeframe tuple) Something like the above dialog could do that within 15 seconds of user interaction. It would be a very valuable capability and it is all completely independent of a chart or analysis window.

The use case is to have these background scripts communicate with a script that is associated with a chart through static variables. The script running in the chart is completely different than the functionality that the background running scripts provide.

You can have AFL execution without charts if you just use Analysis window.

UI is needed to make people aware that they are running AFL threads and to provide visual output / feedback and ability to interact (for example stop the thread, display error messages).

Generally speaking, sorry, but I don't like that idea (of running dozens of hidden threads). Threads are not lightweight. Each thread has minimum amount of 1MB of stack and private memory for all variables. Each thread consumes CPU. As soon as number of threads exceeds number of cores, things may slow down because preemptive scheduling. That would be opening can of worms.

Hello SteveH,

i see you are using Visual Studio or some other compiler to design your workflow. As written it is possible to queue parameters via file i/o using OLE and oldschool tech semaphores to monitor "inter-threading communication". It is an important task monitoring running APXs are finished and did not deadlock themself using file i/o or stress up your cpu too much. Additional it would be helpful to time schedule these Analysis tasks or starting additional external tools. Using your individual parameters "xml parse" and rewrite your AB Analysis template. I followed this approach in the past and commit with Tomasz it is not easy, but when it works you have every morning your Analysis, Top-Flop, auto import to AB watchlist ... this is ongoing process and force you to create your smarter world. For many years ago AB is smart enough to provide these features so we can use :wink: My approach is to manage Excel Sheets like "task lists", export it and communicate with AB by OLE. Thinking about using "AB Batch" is also a great way to automate something ...

Best regards, Peter


1 Like

Yes, nowadays, most of the stuff can be done using Batch (Using Batch window) without any OLE programming. Batch takes care of sequencing processes very easily and hassle-free.


Well, you know, they're not really hidden. That's why you have the metaphor of a Windows Task Manager included in the dialog that launches new threads. You could always see what's running, time and memory consumption stats. Each line item in the running thread list could also be associated with an error log. And on and on.

And I totally get that you don't want to do it.

All I asked for is my idea to be understood...mission accomplished.

I guess now I have to open up bunches of blank charts for different timeframes and apply the same tiny script (only takes 2-4ms to run) to 8 higher level timeframes (2, 3, 5, 10, 15, 30, 60 and 240 min) and, at the top of the script, have a RequestTimedRefresh(1). I have 8 symbols at a time that I follow. It gets the job done but now I've had to create 64 tabbed blank windows.

It looks like the Batch window can't run its tasks on a 1 sec refresh rate and I don't see how to apply a script to run in a specific timeframe. I don't think it was ever designed for real-time day trading use. Also, the Analysis Window was not designed to run something once every second (not that it would be any improvement over applying a script to blank windows in this type of usage).

I'll get by. It's better than nothing.

I think there might be another time-comsuming process I have to do at the start of each day. I only had 1 set of 8 setup from yesterday and I'm pretty sure I had to visit each one to get the scripts running and assigning their static vars for the 1 min chart to read. If this is true then I have to do this for 64 tabbed blank charts off of the main Amibroker windows. I'll find out when I have all 64 blank charts setup, exit Amibroker and then launch again.

@Steve, probably I do not properly understand your workflow, but I wonder why you have to set 64 windows?
Is not possible to do it using only 8 (to scan/explore/save to static vars) using a single watchlist with all your 8 symbols?

Analysis definitely CAN run scan or exploration every one second ("Run every..." setting)

beppe, you're right. Thanks.

Tomasz, my mistake. Thanks for the correction.

I have setup 8 Analysis Windows, each with the same script running (scanning) on different timeframes and the update rate is 3 seconds on auto-repeat.

The weird thing is this. The mouse pointer is constantly flipping back and forth between the standard pointer and a light blue circle, regardless of which chart window I'm in. I understand that that circle is signifying that a scan is running but is there a way to turn this mouse cursor effect off? I looked in the general settings tabs and the analysis settings tabs and couldn't find an option.

For what it is worth, wait cursor is used only for very brief time (typically milliseconds) when GUI is being prepared for action (such as setting up columns in list view and showing up progress bar). There is currently no option to turn that off.

If you're running 8 Analyzer Windows in 8 different timeframes, each one auto-running in under 5 secs, the mouse cursor flashes between pointer and the wait icon rapidly, all of the time. But I'm sure this wasn't your original intention.

Makes things (for me) unusable to be able to place discretionary real-time trades on a chart with the mouse pointer. Just no way I can maintain my concentration level with that much money on the line. I don't think anyone could. If you have no plans to give the user the option to turn this behavior off then it's back to 64 blank charts running at RequestTimedRefresh() rates instead of 8 Analyzer Windows for me.

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