implementing multiple time frame analysis in AmiBroker

#1
This is a follow-up post to http://www.traderji.com/amibroker/71499-need-help-following-janeczkoimplementing-multiple-time-frame-analysis-amibroker.html

I am having trouble getting this to work AmiBroker 5.6. I used the following steps:

1) Set up a 1-min chart and analysis
2) Coded up the multithreaded versions of the MTMACD indicator as posed by Trash (see p2 of the above post)
3) Ran the scan, and inserted the indicator.
4) Switched to daily bars

A couple of problems.

1) The scan shows lots of buys/sells but I don't see any buy/sell arrows on my chart

2) I can only see to get the MTMACD indicator to work on daily bars

To explain the second point:
If I adjust the code to aggregate over 1-minute intervals up to, say, 5 mins, instead of 300 mins, as in the original code. I would expect that indicator to work for, say, hourly bar charts (as well as daily). I make the following adjustment:

for( i = 1; i <= 5; i++ )

This works fine on a daily bar chart, but for anything less than daily the MTMACD indicator remains stuck at 1.0, even though I am only aggregating bars up to a total of 5 mins.

Thanks.
 

trash

Well-Known Member
#2
1) The scan shows lots of buys/sells but I don't see any buy/sell arrows on my chart

2) I can only see to get the MTMACD indicator to work on daily bars
In regards to 1) you need to use PlotShapes on a price chart

2) Don't know what you are doing.



Instead of AddToComposite you can use Static Variables alternatively and it's multi-threading friendly.

Scan on 1-minute
Code:
Count = 0;
result = 0;
for ( i = 10; i <= 300; i++ )// 10-minute to 300-minute
{
    TimeFrameSet( i * in1Minute );
    m = MACD( 12, 26 );
    TimeFrameRestore();
    m = IIf( TimeFrameExpand( m, i * in1Minute ) > 0, 1, -1 );
    result = result + m;
    Count++;
}

StaticVarSet( "~MACD_" + Name(), result / Count );
Buy = 1;
MACD Plot
Code:
RequestTimedRefresh( 1 );

x = StaticVarGet( "~MACD_" + Name() );

Plot( x, "MTF MACD", colorBlue , styleThick );
PlotGrid( 0.5, colorRed );
PlotGrid( -0.5, colorGreen );

Signals on Price plot
Code:
RequestTimedRefresh( 1 );

x = StaticVarGet( "~MACD_" + Name() );

Buy = Cross( x, -0.5 );
Sell = Cross( 0.5, x );
BuyPrice = SellPrice = Close;

SetChartOptions( 0, chartShowDates );
SetBarFillColor( IIf( C > O, ColorRGB( 0, 75, 0 ), IIf( C <= O, ColorRGB( 75, 0, 0 ), colorLightGrey ) ) );
Plot( C, "Price", IIf( C > O, ColorRGB( 0, 255, 0 ), IIf( C <= O, ColorRGB( 255, 0, 0 ), colorLightGrey ) ), 64, 0, 0, 0, 0 );

Buycolor = colorGreen;
Sellcolor = colorOrange;
Colorborder = colorLightGrey;

PlotShapes( Buy*shapeSmallUpTriangle, Buycolor, 0, L, -15 );
PlotShapes( Buy*shapeHollowSmallUpTriangle, Colorborder, 0, L, -15 );
PlotShapes( Buy*shapeHollowSmallCircle, Buycolor, 0, BuyPrice, 0 );

PlotShapes( Sell*shapeDownArrow, Sellcolor, 0, H, -15 );
PlotShapes( Sell*shapeHollowDownArrow, Colorborder, 0, H, -15 );
PlotShapes( Sell*shapeHollowSmallCircle, Sellcolor, 0, SellPrice, 0 );
 
#3
Thanks Trash - this version worked first time.

for ( i = 10; i <= 300; i++ )// 10-minute to 300-minute
Ok suppose I change it to:

for ( i = 1; i <= 5; i++ )// 1-minute to 5-minute

I install as before and now try to plot the new 5-min MTMACD. It will do it for a daily bar chart, but if I reduce the frequency to anything less, say hourly, the MTMACD indicator wont plot, even though I am only aggregating 5 1-minute bars.
 

Similar threads

Broker Special Offers

Intraday Higher Leverage

Save up to 90% in brokerage and get higher leverage for intraday trades.

Name:Phone:
Email:City:
State:
Are you a day trader?