Change chart interval every 20 seconds

hi all
is there a function which can help to code the change interval in the afl
automatically every 15 secs to 1 min , 5 min , 60 min, daily
in a loop of 15 seconds

how to get the sleep or timeout in a loop so that interval can be changed every 15 secs automatically

thanks in advance

1 Like

Why you would want to do that? (Describe the goal)

i have a set of charts which are tiled in the layout

i keep checking the different timeframes for all symbols in the layout as intervals are synced

i will give a button trigger for interval to change every x minutes or seconds

this will be for display

i am a scalper and trader so need to chk one min and 5 min charts both
while i am busy trding on one terminal
the charts on the other desktop ( which are on display) can automatically change interval at a particular timegap

this is the whole idea

and if a understand how to use sleep or timeout
may be some more ideas would popup in my head ,
for making other regular activities on amibroker automated
thanks in advance

The only way to change the interval programmatically is using OLE automation. Below is the example code that shows how to do that correctly (without sleep and without busy waiting).

The code automatically switches current chart between daily/weekly/monthly every second.

Plot( C, "Price", colorDefault, styleCandle );

TimeBetweenSwitches = 1; // change to 20 to get 20 seconds

RequestTimedRefresh( TimeBetweenSwitches );

if( Status("redrawaction") == 1 )
	// if timed refresh - change the interval
	counter = Nz( StaticVarGet("counter") );
	switch( ++counter ) 
		case 1:
				in = inWeekly;
		case 2:
				in = inMonthly;
				in = inDaily;
				counter = 0; // reset counter
	StaticVarSet("counter", counter );
	AB = CreateObject("Broker.Application");
	doc = AB.ActiveDocument;
	doc.Interval = in; // change the interval

hi tomasz

is the whole code including plot for .js file ?

as i made a js file with this code , but its not working , its giving error

nitin bagadia

@n_bagadia this is AFL code and it works very well.

This is AmiBroker forum and most of the codes which you can find here were written in AFL and intended to be run in AmiBroker. You've received a ready to use solution from Tomasz meeting your criteria.

It really surprises me that you didn't even try to run this code in AmiBroker...


As @Milosz wrote, the code I gave you is AFL code to be copy-pasted to AFL Code Editor.
Similar code can be written in JScript to be run externally, but that is left as exercise to the reader.


sorry to have not tried in afl

will take detailed care and testing before replying henceforth
nitin bagadia

:+1: This is the solution that I am looking for.

Thank you so much!