A Simple Multi Timeframe Trading Strategy with Exploration AFL

Multi Timeframe analysis a a key to improve your accuracy in speculating Stock prices. It generally involves taking clues from higher timeframe charts while trading on lower timeframes. The major benefit of multi timeframe analysis is that it considerably reduces whipsaws, however it reduces the number of signals too. Generally the support and resistance levels on higher time frames are more significant than lower ones, also trends on higher time frames are long lasting. Hence it is very important to validate your signals on lower time frames with the ones on higher time frame. In this post, we will go through a simple multi timeframe trading strategy which looks up weekly charts for confirming the trend while trading on daily timeframe. Also, we will see Amibroker exploration AFL for the same strategy.

Please visit Trading Tuitions Academy to learn AFL coding and create your own Trading systems.

Multi Timeframe Trading Strategy – Overview

Parameter Value
Preferred Time-frame
  • Daily
Indicators Used
  • EMA, ADX
Buy Condition
  • Fast EMA crosses over slow EMA on Daily TF
  • ADX is above 30 on Weekly TF (for confirming the trend)
Short Condition
  • Fast EMA crosses below slow EMA on Daily TF
  • ADX is above 30 on Weekly TF (for confirming the trend)
Sell Condition
  • Same as Short
Cover Condition
  • Same as Buy

Multi Timeframe Trading Strategy – AFL Exploration Code

//------------------------------------------------------
//
//  Formula Name:    Multi Timeframe Exploration
//  Author/Uploader: Trading Tuitions
//  E-mail:          support@tradingtuitions.com
//  Website:         www.tradingtuitions.com
//------------------------------------------------------

_SECTION_BEGIN("Multi Timeframe Exploration");

SetBarsRequired( sbrAll );
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C ));

Plot( Close, "Price",colorWhite, styleCandle );
FastEMA = Param("FastEMA",18,3,21,3);
SlowEMA = Param("SlowEMA",35,20,50,5);
ADXParam=Param("ADXParam",14,5,5,30);

/* switch to weekly time frame */
TimeFrameSet( inWeekly );
wADX = ADX(ADXParam);
TimeFrameRestore();

/* expand calculated MACD to daily so we can use it with daily signals */
wADX = TimeFrameExpand( wADX, inWeekly );


FastEMADaily = EMA(C,FastEMA);
SlowEMADaily = EMA(C,SlowEMA);
BuyDaily = Cross(FastEMADaily,SlowEMADaily);
ShortDaily = Cross(SlowEMADaily,FastEMADaily);

Buy = BuyDaily AND wADX>30;

Short = ShortDaily AND wADX>30;

Sell=Short;
Cover=Buy; 

Trade_Signal = WriteIf( Buy, "Buy", "Short" );

Filter = Buy OR Short;

AddColumn(C,"Close",1.2,IIf(C>Ref(C,-1),colorGreen,colorRed));
AddColumn(wADX,"Weekly ADX");
AddColumn(FastEMADaily,"Fast EMA");
AddColumn(SlowEMADaily,"Slow EMA");
AddTextColumn(Trade_Signal,"Trade_Signal",1,fgcolor = colorDefault, bkcolor=IIf(Buy,colorGreen,colorRed));


_SECTION_END();


How to use this Code?

Step 1: Open Amibroker, Click on File–>New–>Formula and Copy Paste the above exploration code

Step 2: Click on File–>New–>Analysis. Set time frame to Daily.

Step 3: In the Apply to dropdown select ‘All symbols’. In the range dropdown select ‘From- To dates’. And finally in both the dates select today’s date

Multi Timeframe Trading Startegy

Step 4: Click on Explore Button. You will see the list of stocks that meet the strategy rules. See ‘Trade_Signal’ column for Buy or Short signal. The symbols listed are the possible candidates to take position on next day.

Multi Timeframe Trading Strategy

Step 5: You may run this exploration on a subset of stocks by selecting Filter option on ‘Apply To’ dropdown.

Please note that the assumption behind these steps is that you already have imported EOD stock prices in Amibroker.

Also Read: Trending Stocks Screener: Amibroker Exploration AFL

Understanding the Exploration Code

Basically the code does two things:

  1. It calculates ADX value on Weekly timeframe
  2. It calculates Fast and Slow EMA values on Daily timeframe

Buy signal is generated when ADX is above 30 in weekly timeframe and Fast EMA crosses over slow EMA in daily timeframe. Short signal is generated when ADX is above 30 in weekly timeframe and Fast EMA crosses below slow EMA in daily timeframe. ADX values help to confirm the trade by looking up on a higher timeframe.

Below are some of the important multi timeframe related functions used in the 1st half of the code:

TimeFrameSet( inWeekly ): Switches current timeframe to Weekly from Daily

TimeFrameRestore(): Restores timeframe back to Daily

TimeFrameExpand( wADX, inWeekly ): expands time-compressed array wADX from weekly timeframe to daily timeframe

Disclaimer:

All the AFL’s posted in this section are for learning purpose. Trading Tuitions does not necessarily own these AFL’s and we don’t have any intellectual property rights on them. We might copy useful AFL’s from public forums and post it in this section in a presentable format. The intent is not to copy anybody’s work but to share knowledge. If you find any misleading or non-reproducible content then please inform us at support@tradingtuitions.com

5 Comments

  1. your formula is error
    _N(Title = StrFormat(“{{NAME}} – {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}”, O, H, L, C ));

  2. why I have *short* for one item on green background and for other item on red background? I do not have any buy’s.

  3. I mean I got an output without Buy and Short has two colours (green, red). Strange.

  4. _N(Title = StrFormat(“{{NAME}} – {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}”, O, H, L, C ));

Leave a Reply

Your email address will not be published. Required fields are marked *