No Signals when uring multiple time frame analysis

I am developing a simple forex trend following system using the MACD. Its a simple macd crossover system which uses the 5 minute macd crossover, provided that the price is above the 5 minute 200ma.
Looking at the report, there is a significant drawdown in the system when price is below the 200 DAILY MA, so I want to create a filter to switch the system off when price falls below the 200 daily MA. Here's a screenshot when the system started to drawdown in the 3rd week of August

and here's the chart. The yellow MA is the 200 daily close (from Tradingview) ;

However, if I include the timeframeset and timeframe restore functions, I generate no signals at all, even when above the 200 daily MA.

movAv = MA(C,200);

r1 = Param( "Fast avg", 12, 2, 200, 1 );
r2 = Param( "Slow avg", 26, 2, 200, 1 );
r3 = Param( "Signal avg", 9, 2, 200, 1 );
ml = MACD(r1, r2);
sl = Signal(r1,r2,r3);
hist = ml-sl;


TimeFrameSet(inDaily);
maD_200 = MA(C,200);
maDFilter = (C > maD_200);
TimeFrameRestore();
Plot(TimeFrameExpand(maD_200,inDaily),"200 Daily MA",colorGold,styleLine);


Buy = (Close > movAv) AND Cross(sl,ml) AND hist <0 AND maDFilter;
Sell = Cross(ml,sl);
Buy = ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy); 

In case I have used the wrong function, I also tried;

movAv = MA(C,200);

r1 = Param( "Fast avg", 12, 2, 200, 1 );
r2 = Param( "Slow avg", 26, 2, 200, 1 );
r3 = Param( "Signal avg", 9, 2, 200, 1 );
ml = MACD(r1, r2);
sl = Signal(r1,r2,r3);
hist = ml-sl;

dc=TimeFrameCompress(C,inDaily);
dma200=TimeFrameCompress(MA(C,200),inDaily);
dmaFilt= dc>dma200;

Buy = (Close > movAv) AND Cross(sl,ml) AND hist <0 AND dmaFilt;
Sell = Cross(ml,sl);
Buy = ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy); 

and I have even tried

movAv = MA(C,200);

r1 = Param( "Fast avg", 12, 2, 200, 1 );
r2 = Param( "Slow avg", 26, 2, 200, 1 );
r3 = Param( "Signal avg", 9, 2, 200, 1 );
ml = MACD(r1, r2);
sl = Signal(r1,r2,r3);
hist = ml-sl;

dc=TimeFrameCompress(C,inDaily);
dma200=TimeFrameCompress(MA(C,200),inDaily);
dmaFilt= dc>dma200;
dailyma = TimeFrameExpand( dma200, inDaily);
TimeFrameRestore();


Buy = (Close > movAv) AND Cross(sl,ml) AND hist <0 AND dmaFilt;
Sell = Cross(ml,sl);
Buy = ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy); 

but I am not generating signals. I have read the manual but it's not broght me closer to generating signals.

Any ideas?

The first piece of code is ok, you have not "Expanded" all the variables from daily to 5min

Expand all of them after TF restore.

//... rest of your code
TimeFrameSet(inDaily);
maD_200 = MA(C,200);
maDFilter = (C > maD_200);
TimeFrameRestore();
maD_200_exp = TimeFrameExpand(maD_200,inDaily);
maDFilter_exp = TimeFrameExpand(maDFilter,inDaily);

//now use these
Plot(maD_200_exp ...
Buy = ... AND maDFilter_exp;
2 Likes

Thanks for that.
Its really strange. I have done exactly what you said and unfortunately did not fetch any results.
I have tried to see if I am getting any values for the expanded arrays by doing an exploration and I don't seem to be returning any arrays;

movAv = MA(C,200);

r1 = Param( "Fast avg", 12, 2, 200, 1 );
r2 = Param( "Slow avg", 26, 2, 200, 1 );
r3 = Param( "Signal avg", 9, 2, 200, 1 );
ml = MACD(r1, r2);
sl = Signal(r1,r2,r3);
hist = ml-sl;


TimeFrameSet(inDaily);
maD_200 = MA(C,200);
dayClose = C;
TimeFrameRestore();
maD_200_exp = TimeFrameExpand(maD_200,inDaily);
dayClose_exp = TimeFrameExpand(dayClose,inDaily);


Buy = (Close > movAv) AND Cross(sl,ml) AND hist <0;
Sell = Cross(ml,sl);
Buy = ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy); 

AddColumn(maD_200_exp,"maD_200_exp",1.4);
AddColumn(dayClose_exp,"dayClose_exp",1.4);


Even if I remove the buy and sell conditions and then run an exploration, just by having the timeframe functions there I don't seem to get any values returned.

@SpandexMan, in you last post you should add:

Filter = 1;

to see any result in the exploration.

In any case, since you are calculating a MA for 200 days the question is: does you intraday database have enough data to calculate the 200 daily bars?
If your base interval is 1-minute, and you have 24 hours of data per day, you need at least 24 * 60 * 200 1-minute bars = 288000 bars - otherwise your daily MA will be all empty.

1 Like

Ah, yes, of course. I think that must be it! That’s really insightful. Thank you.

I’m using the Interactive Brokers data plug in and if my base is 5 minute bars, I’m not sure I can import enough data at that granularity to generate a 200 daily MA.

Can I simply import daily data (e.g via ASCII) prior to when the 5 minute data starts, in order to generate a 200 Day SMA?

Thanks Beppe.

@SpandexMan please see this previous thread for @Tomasz answer (applies if database is set to allow intraday/EOD mix) and a potential workaround suggested by @travick.

2 Likes

Thanks Beppe. You were bang on the money, that was exactly the issue.
I grabbed some historical daily data using the IBKR API and used the ASCII importer wizard to patch up the database for the purpose of the backtest and it worked.

This was really useful, thanks. I’m a lot clear on how to use the timeframe functions now.

1 Like

Reference Document: Multiple Time Frame support in AFL.

2 Likes

The document mentioned earlier Multiple Time Frame support contains ORANGE BOXES that are meant to catch people's attention and are absolutely must-read. I don't understand why people still don't see those orange highlighted boxes.

Our brains are all wired differently and we all have different fluency and proficiency. While 1 person can read a document like that and it instantly make sense to them, for other people, it doesn’t matter how much they read it, they won’t understand it until they’ve been shown how to use it.
When I read something that I am unfamiliar with, I have a kind of fuzzy logic on what is meant. Computers don’t like fuzzy logic, however. They need good old fashioned “meat ‘n potato” hard logic. That’s surprisingly difficult for people to achieve without a pre-existing knowledge base although as time moves forward, and I gain experience with the software, my questions are further apart in time although when they do come up, they’re undoubtedly just as absurd.
The Kruger-Dunning effect works in both directions, I.e, given your experience and intelligence, you can’t possibly see how there are people as dumb as me in the world. :sweat_smile:

1 Like

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