Период расчета скрипта Амиброкера

Опубликовано в AmiBroker

Известная проблема - скрипт Амиброкера перестает работать, если он (Amibroker) неактивен (свернут в трей). Проблема легко решаема.

REQUESTTIMEDREFRESH
- forces periodical refresh of indicator pane

 

 

SYNTAX RequestTimedRefresh( interval, onlyvisible = True )
RETURNS NOTHING
FUNCTION The function causes given indicator window to refresh automatically everyseconds regardless of data source used or connection state.

interval parameter defines timeout in seconds between refreshes. AmiBroker attempts to align refreshes to second boundaryso if you call it RequestTimedRefresh( 5 ) you should get refreshes at 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50 and 55 second of the minute.Due to the way how regular (low overhead) timers are implemented in Windows they have accurracy of +/-55ms providedthat CPU is not very busy. Don't expect to get first line of your code to execute exactly at .000 milliseconds. This varies depending on machine load, number of quotes, system time slice and tens of other factors.Usually (on my testing machines) the first line of the code executes anywhere in the first 100 ms of the second, provided that other processes do not interfere. Windows is not real-time operating system and it does not guarantee any fixed execution/reaction times.

onlyvisible parameter set to True (default value) means that refreshes are triggered only for visible and not minimised windows. This applies also to main AmiBroker window - when it is minimised charts are NOT refreshed by default. To force refreshes when window is minimised you need to set this parameter to False. Note that this visibility applies to mostly to 'minimised' state or the situation when you move chart outside the boundary of physical screen so it is not visible to an eye but still open. It does not apply to chart windows that are on placed on inactive sheets, as they do not really exist until they are shown (this way AmiBroker conserves memory and CPU) and as non-existing, can not be refreshed.

Hint: to detect whenever given refresh comes from timer or user action you can use Status("redrawaction") function. It returns 0 for regular refresh (user action) and 1 for timer-refresh

Starting from version 5.30.3 RequestTimedRefresh supports sub-second (down to 0.1 sec) resolution, when enabled via registry setting (HKCU/Software/Broker/Settings/EnableHiresRTR, DWORD value = 1 ) 

 

Одним словом, 

RequestTimedRefresh(1,False);

запускает скрипт каждую секунду, даже в минимизированном и свернутом в трей Амиброкере.

Можно ли запускать его чаще? Ответ - в последней фразе хелпа. Можно, но нужно установить ключ в реестре.

Устанавливаем значение ключа прямо самим скриптом:

 

if (IsNull(StaticVarGet("EnableHiresRTR")))
{ WSHShell = CreateObject("WScript.Shell");
WSHShell.RegWrite("HKEY_CURRENT_USER\\Software\\Broker\\Settings\\EnableHiresRTR", 1,"REG_DWORD");
StaticVarSet("EnableHiresRTR",1);
}

Также имеет смысл обратить внимание на настройку Tools-Preferences-Intraday-Realtime chart refresh interval. вот что говорит хелп о ней:

 

  • Realtime chart refresh interval - defines interval between automatic chart refreshes in real-time mode. By default charts are refreshed every 3 seconds but in very volatile market you may prefer to set it to 1, so charts are refreshed every second in real-time mode.

    New in 4.90: To enable 'every tick' chart refresh in ProfessionalEdition, go to Tools->Preferences, Intraday tab and enter ZERO (0) into "Intraday chart refresh interval" field. (note Standard Edition won't allow to do that).

    Once you enter zero, AmiBroker will refresh all charts with every new trade arriving provided that the formulasyou use execute fast enough. If not, it will dynamically adjust refresh rate to maintain maximum possible refresh rate without consuming more than 50% of CPU (on average). So for example if your charts take 0.2 sec to execute AmiBroker will refresh them on average 2.5 times per second.

В очень вольном переводе: можно указать значение периода пересчета графика (и формулы) по умолчанию в секундах. Можно указать 0, и Амиброкер будет пробовать делать пересчет с той скоростью, на которую способно ваше оборудование. Но версия должна быть Professional и не ниже 4.90.

См. также Увеличение производительности Амиброкера

Комментарии   

# admin 23.04.2012 12:02
Не могу найти способ заставить работать скрипт, если он на неактивной вкладке. Понятно, что Амиброкер таким образом разгружает процессор. Если кто подскажет - буду признателен. В общем, никто не мешает держать робота на активной вкладке чарта, но... :-*

Недостаточно прав для комментирования