Multiple Time frame AFL

Hi,
I am testing multiple time frame AFL with the example given in the below link, but with timeframes 5min and 15min:
https://www.amibroker.com/guide/h_timeframe.html

//Source: https://www.amibroker.com/guide/h_timeframe.html
TimeFrameSet( in5Minute ); // switch to 5 minute frame

/* MA now operates on 5 minute data, ma5_13 holds time-compressed 13 bar MA of 5min bars */

ma5_13 = MA( C, 13 );

TimeFrameRestore(); // restore time frame to original

TimeFrameSet( in15Minute ); // switch now to 15min

mah_9 = EMA( C, 9 ); // 9 bar moving average from 15min data

TimeFrameRestore(); // restore time frame to original

Plot( Close, "Price", colorGold, styleCandle );

// plot expanded average

Plot( TimeFrameExpand( ma5_13, in5Minute), "13 bar moving average from 5 min bars", colorBlue );
Plot( TimeFrameExpand( mah_9, in15Minute), "9 bar moving average from 15min bars", colorGrey50 );
// I have added the below code to generate buy and sell signal and to plot uparrow for Buy and downarrow for sell:
Buy01 = Cross(ma5_13, mah_9);
Buy = Ref(Buy01, -1);
Sell01 = Cross (mah_9, ma5_13);
Sell = Ref(Sell01, -1);

// visualize signals with yellow arrows
PlotShapes(Buy*shapeUpArrow, colorBlue, 0, L);
PlotShapes(Sell *shapedownArrow, colorGold , 0,H);

Setting for backtesting is as below:
Backtesting%20Settings

Chart

image

Please help in fixing the code for the code which I added for buy and sell signal and for plotting the arrows.

1 Like

You plotted the expanded versions of ma5_13 and mah_9, but in your Buy and Sell logic you used the compressed versions of those variables.