Need AFL for EMA Cross over Daily by Intraday

#1
Hi Seniors and Others,

I use Amibroker with 5 /15 mins intraday data . I need the following .

1. Plotting of EMA 15 ( 5 mins time frame )

2. Plotting of EMA 12 ( Daily time frame... it is constant )

3. Cross over buy and sell signal of the above


I tried plotting the above . I m getting the values ... But i am not getting the Crossover buy and selll...its plotting wrong buy and sell signals ...


The AFL IS AS BELOW :

_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();


_SECTION_BEGIN("EMA");

Range1=Optimize("range1",15,1,20,1);

// plot expanded average
Plot(EMA(Close,range1), "", colorRed,styleDots );

_SECTION_END();

_SECTION_BEGIN("day");
TimeFrameSet( inDaily-1 ); // switch now to daily

ek=EMA(C,12);

Plot( TimeFrameExpand( ek, inDaily),"Powe", colorBrightGreen,10+30+4| styleNoRescale|styleNoTitle);

_SECTION_END();

Range1=Optimize("range1",15,1,20,1);

Buy = Cross((EMA(Close,range1)),(ek));
Sell = Cross((ek),(EMA(Close,range1)));
Short = Sell;
Cover = Buy;




// plot arrows
shape = Buy * shapeUpTriangle + Sell * shapeDownTriangle;
PlotShapes( shape, IIf( Buy, colorWhite, colorYellow ), 0, IIf( Buy, Low, High ) );


dist = 3.5*ATR(5);
for( i = 0; i < BarCount; i++ )
{
if( Buy ) PlotText( "Buy\n@" + C[ i ], i, L[ i ]-dist,2, colorGreen );
if( Sell ) PlotText( "Sell\n@" + C[ i ], i, H[ i ]+dist, colorWhite,colorRed );
}

AFL IS CORRECT ... PLOTTING ALSO IS CORRECT ..... BUT PROBLEM IS I AM GETTING BUY / SELL SIGNAL WRONGLY


PLZ SOLVE THIS PROBLEM of MINE..



Check the Images for Understanding the issue



Need a BUY/SELL signal For the RED LINE CROSSING OVER THE GREEN LINE[/SIZE]


Thanks in advance.

Regards,
Kumar
 

Attachments

Last edited:

hitesh

Active Member
#2
Hope will be useful...

//http://www.traderji.com/amibroker/91864-need-afl-ema-cross-over-daily-intraday.html
_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();


_SECTION_BEGIN("EMA");

Range1=Optimize("range12",15,1,20,1);

// plot expanded average
EMA15=EMA(Close,range1);
Plot(EMA15, "EMA-15", colorRed,styleDots );

_SECTION_END();

_SECTION_BEGIN("day");
TimeFrameSet(inDaily);

ek1=EMA(C,12);
//ek = TimeFrameExpand( ek1, inDaily);
//Plot( ek,"Dly-12", colorBrightGreen,10+30+4| styleNoRescale|styleNoTitle);
TimeFrameRestore();
ek = TimeFrameExpand( ek1, inDaily);
Plot( ek,"Dly-12", colorBrightGreen,10+30+4| styleNoRescale|styleNoTitle);

_SECTION_END();

Buy = Cross(EMA15,ek);
Sell = Cross(ek,EMA15);
Short = Sell;
Cover = Buy;




// plot arrows
shape = Buy * shapeUpTriangle + Sell * shapeDownTriangle;
PlotShapes( shape, IIf( Buy, colorWhite, colorYellow ), 0, IIf( Buy, Low, High ) );


dist = 3.5*ATR(5);
for( i = 0; i < BarCount; i++ )
{
if( Buy ) PlotText( "Buy\n@" + C[ i ], i, L[ i ]-dist,2, colorGreen );
if( Sell ) PlotText( "Sell\n@" + C[ i ], i, H[ i ]+dist, colorWhite,colorRed );
}
 

Similar threads