// http://www.amibroker.com/docs/MTFIndicators.html
// First 'Scan' on 1-minute time frame
// Then click 'Backtest'
// Then right-click result list and choose "Show arrows for actual trades"
// mod. by trash
// http://www.traderji.com/amibroker/90119-simple-coding-help-no-promise-349.html#post1087794
SetOption( "FuturesMode", False );
// etc.
SetPositionSize( 1, spsShares );
// calling stored custom MACD line
// It is dependent on the Symbol is was created with!
nm = Name(); // insert the name of the symbol the composite was created with
x = StaticVarGet( "~MACD" + nm ); //Foreign( "~MACD" + Name(), "C" );
// create buy sell signal
Buy = Cross( x, -0.5 ); // buy when x crosses ABOVE -0.5
Sell = Cross( 0.5, x ); // sell when x crosses BELOW 0.5
Short = Cover = 0;
// create custom MACD composite via Scan
if( Status( "action" ) == actionScan ) {
Count = 0;
result = 0;
for( i = 10; i <= 300; i++ ) {
TimeFrameSet( i * in1Minute );
m = MACD( 12, 26 );
TimeFrameRestore();
m = IIf( TimeFrameExpand( m, i * in1Minute ) > 0, 1, -1 );
result += m;
Count++;
}
// storing result to static variable.
// It is dependent on the Symbol is was created with!
StaticVarSet( "~MACD" + Name(), result / Count, persistent = true );
//AddToComposite( result / Count, "~MACD" + Name(), "X" );
Buy = 0;
}
// for insertion to separate indicator pane, NOT for price pane!
if( Status( "action" ) == actionIndicator ) {
// plot stored MTMACD
Plot( x, "MTMACD", colorBlue, styleThick );
// two grid lines
PlotGrid( 0.5, colorRed );
PlotGrid( -0.5, colorGreen );
// removing excessive signals in indicator pane
Buy = ExRem( Buy, Sell );
Sell = ExRem( Sell, Buy );
Short = ExRem( Short, Cover );
Cover = ExRem( Cover, Short );
// plotting buy and sell shapes
PlotShapes( Buy * shapeUpArrow + Sell * shapeDownArrow,
IIf( Buy, colorGreen, colorRed ), layer = 0,
y = x, dist = -12 );
PlotShapes( Buy * shapeHollowUpArrow + Sell * shapeHollowDownArrow,
colorLightGrey, layer, y, dist );
}