Reputation: 11
In Amibroker, I want to scan a strategy (from an indicator that gives Buy/Short signals) in multiple (6 different) timeframes (intraday). I want to have it all in one scan, with each timeframe having its own Alert text output. So I have to use the Timeframeset function. Unfortunately, I can't get it working. Any help wil be appreciated.
What I tried so far: After looking into several places on the web, here is the best I could put together from posts discussing similar problems:
//the 1min scan (this is the basis scan, which seems allright):
scanbuy1min = Buycond1 OR Buycond2;
scanshort1min = Shortcond1 OR Shortcond2;
barcomplete = BarIndex() < LastValue(BarIndex());
AlertIf( barcomplete AND scanbuy1min, "SOUND C:\\Sounds\\alarm2.wav" , "LS_1m_up", 1, 13 );
AlertIf( barcomplete AND scanshort1min, "SOUND C:\\Sounds\\alarm2.wav" , "LS_1m_DOWN", 3, 13 );
//The 3min scan, here's where I'm probably doing something wrong:
TimeFrameSet( 3*in1Minute);
scanbuy3min = BuyCond1 OR Buycond2;
scanshort3min = Shortcond1 OR Shortcond2;
TimeFrameRestore();
buyExp3minTo1min = TimeFrameExpand( scanbuy3min, 3*in1Minute);
shortExp3minTo1min = TimeFrameExpand( scanshort3min, 3*in1Minute);
AlertIf( barcomplete AND buyExp3minTo1min , "SOUND C:\\Sounds\\alarm2.wav" , "LS_3m_up", 1, 13 );
AlertIf( barcomplete AND shortExp3minTo1min , "SOUND C:\\Sounds\\alarm2.wav" , "LS_3m_down", 1, 13 );
Buy = (scanbuy1min OR buyExp3minTo1min) AND barcomplete;
Short = (scanshort1min OR shortExp3minTo1min) AND barcomplete;
//and so on for other timeframes
The debugger gives no errors.
I have periodicity set at 1min. When I run this scan (with a 50 bars lookback) it does not give any 3min. signals in the results list (where it should), whereas it gives false signals that do not exist on the 1 nor 3min indicator. When I run the same scan with the 3min. part deleted (so only 1min.), the scan results are correct and match the indicator signals; so there's no error in the original 1min scan, and the 3min. part apparently messes up the 1min. part.
I assume the problem is with TimeframeExpand, as I do not really understand this function, I just tried to mimick what I found elsewhere.
My understanding of AFL is rather basic. So pls keep it simple if you can. Thanks for your help!
Upvotes: 1
Views: 545
Reputation: 51
Your TimeFrameExpand() is expanding the signals correctly to the original timeframe, but the issue should be with the AlertIf() function. The AlertIf() function takes a condition in case it is true then triggers an alert. Your code used barcomplete AND buyExp3minTo1min and barcomplete AND shortExp3minTo1min as the conditons, which will be true at the last bar of 1-minute timeframe, but not 3-minute timeframe.
I have updated your code for 3 mins scan
TimeFrameSet( 3*in1Minute);
scanbuy3min = BuyCond1 OR Buycond2;
scanshort3min = Shortcond1 OR Shortcond2;
barcomplete3min = BarIndex() < LastValue(BarIndex()); // Create a barcomplete for 3-min timeframe
TimeFrameRestore();
buyExp3minTo1min = TimeFrameExpand( scanbuy3min, 3*in1Minute);
shortExp3minTo1min = TimeFrameExpand( scanshort3min, 3*in1Minute);
buyExp3minTo1minBarComplete = TimeFrameExpand( barcomplete3min, 3*in1Minute); // Expand barcomplete3min to 1-min timeframe
AlertIf( buyExp3minTo1minBarComplete AND buyExp3minTo1min , "SOUND C:\\Sounds\\alarm2.wav" , "LS_3m_up", 1, 13 );
AlertIf( buyExp3minTo1minBarComplete AND shortExp3minTo1min , "SOUND C:\\Sounds\\alarm2.wav" , "LS_3m_down", 1, 13 );
Buy = (scanbuy1min OR buyExp3minTo1min) AND barcomplete;
Short = (scanshort1min OR shortExp3minTo1min) AND barcomplete;
Upvotes: 0