Alera Forum

Full Version: Using Cron for Scheduling
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Cron Scheduling
Scheduling your strategies, email notifications, and external programs in APM can be done using the cron (also crontab) syntax.
Please refer to this guide for another explanation (and some more advanced uses) of the cron syntax used in APM.
You can also find a useful cron converter here.

The cron syntax that APM is slightly different than the classic Unix cron syntax:

* * * * * * *
| | | | | | |
| | | | | | +-- Year              (range: 1900-3000)
| | | | | +---- Day of the Week   (range: 1-7 or SUN - SAT)
| | | | +------ Month of the Year (range: 1-12)
| | | +-------- Day of the Month  (range: 1-31)
| | +---------- Hour              (range: 0-23)
| +------------ Minute            (range: 0-59)
+-------------- Second            (range: 0-59)

Some notes about this format:
  • The year is optional and does not have to be included
  • The week starts on Sunday
  • You cannot put a day of the week and a day of the month. Put a ? for one of the options.
  • This format includes the second to run at, which is a mandatory field
The idea behind this format is that each cron string is 6 (or 7) numbers (or special characters) that define a schedule.

Special Characters
* : means all possible values. For example, putting * for hours would mean every hour.
? : means no value. This is used for conflicting values, such as putting a number for both the day of month and day of week. One of those values must be ?
- : is used to specify a range of numbers, i.e. 5-7 for hours would mean at 5,6, and 7am.
, : is used to specify a set of numbers, i.e. 5,7 for hours would mean at 5am and at 7am.

Here are some example cron schedules:

* * * ? * *                 Runs every second
0 * * ? * *                 Runs every minute
0 30 15 ? * *               Runs at 3:30pm every day
0 30 15 ? * MON-FRI         Runs at 3:30pm, Monday through Friday
0 30 10,15 ? * MON-FRI      Runs at 10:30am and 3:30pm, Monday through Friday
0 10 * ? * *                Runs every hour at 10 past the hour

If you are unsure about using cron, we suggest to copy one of the above schedules into APM and modify the second, minute, and/or hour fields to your needs.
Note that APM will tell you the schedule your cron string represents if you hover over the Run Strategy text.
Hi, regarding Setting - Strategy - Use External Program and Enable Scheduler, does Alera support sequence setting: first, execute an external program, and then run strategy?

if not, how can I use DOS batch file to do it?
further more, could strategy scheduler be trigered by the completion of running exteral program?

Work flow: running exteral program - run strategy - running exteral program - run strategy until forever
(09-28-2020, 11:15 AM)C0101 Wrote: [ -> ]further more, could strategy scheduler  be trigered by the completion of running exteral program?

Work flow: running exteral program - run strategy - running exteral program - run strategy until forever

Currently, the external program and strategy are run separately. If you know that your external program will take up to 10 minutes to run, then you can set the strategy to run 15 minutes after the external program runs using cron scheduling.

If your signals are time sensitive, then I recommend using the Alera API to tell Alera to run the strategy after your external program runs.
https://aleratrading.com/forum/showthread.php?tid=89

Once you enable the Alera API, you can add the following to your external program batch file (replace <port> with the Alera API port and <id> with your strategy id) in order to tell Alera to run the strategy
curl -X POST -d '' http://localhost:<port>/api/strategies/<id>?cmd=run

Note that you may need to tell the batch file to wait for your signal generation exe to complete before telling the Alera API to run your strategy.
See https://aleratrading.com/forum/showthread.php?tid=7

Also, if you are using Amibroker, see https://www.systematic-investors.com/sen...alera-apm/
How to enable API?
(09-29-2020, 09:56 PM)C0101 Wrote: [ -> ]How to enable API?

There is a checkbox in the Account Settings (bottom right of your screen)
it works now. thank you
I found this Cron maker useful at this link here:
http://www.cronmaker.com/
Also I found this website helpful for trying to figure out the correct cron expression:
https://www.freeformatter.com/cron-expre...uartz.html

I wanted to figure out 06:00 on the 1st day of the month that's a weekday for a monthly system and this works:
0 0 6 1W * ? *
(12-22-2021, 03:48 PM)Marcel Wrote: [ -> ]Also I found this website helpful for trying to figure out the correct cron expression:
https://www.freeformatter.com/cron-expre...uartz.html

I wanted to figure out 06:00 on the 1st day of the month that's a weekday for a monthly system and this works:
0 0 6 1W * ? *

Thanks I've added a link to it above.