1min_ema_crossover


//This 70/1030 EMA Crossover with trailing Stoploss in a 1 Minute Timeframe will generate good results.
_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("Volume");
Plot( Volume, _DEFAULT_NAME(), ParamColor("Color", colorBlueGrey ), ParamStyle( "Style", styleHistogram | styleOwnScale | styleThick, maskHistogram ), 2 );
_SECTION_END();

_SECTION_BEGIN("EMA1");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 1050, 1, 10 );
Plot( EMA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();

_SECTION_BEGIN("EMA2");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
Plot( EMA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();

//USE THIS WITH 1 MINUTE TIMEFRAME

Range1=Optimize("range1",70,50,80,5);
Range2=Optimize("range2",970,500,1050,5);

StopLevel = Param("trailing stop %", 0.7, 0.1, 10, 0.1 );

SetTradeDelays(0,0,0,0);

Buy = Cross( EMA(Close,Range1), EMA(Close,Range2));
Sell = 0;
ApplyStop( stopTypeTrailing, stopModePercent, StopLevel, True );

Equity( 1, 0 ); // evaluate stops, all quotes

InTrade = Flip( Buy, Sell );

SetOption("EveryBarNullCheck", True );
stopline = IIf( InTrade, HighestSince( Buy, High ) * ( 1 - 0.01 * StopLevel ), Null );

PlotShapes(Buy*shapeUpArrow,colorGreen,0,Low);

PlotShapes(Sell*shapeDownArrow,colorRed,0,High);

//Plot( Close,"Price",colorBlack,styleBar);
Plot( stopline, "trailing stop line", colorRed );

Short = Cross( EMA(Close,Range2), EMA(Close,Range1));
Cover = 0;
ApplyStop( stopTypeTrailing, stopModePercent, StopLevel, True );

Equity( 1, 0 ); // evaluate stops, all quotes

InTrade1 = Flip( Short, Cover );

SetOption("EveryBarNullCheck", True );
stopline = IIf( InTrade1, LowestSince( Short, Low ) * ( 1 + 0.01 * StopLevel ), Null );

PlotShapes(Short*shapeDownArrow,colorRed,0,High);
PlotShapes(Cover*shapeUpArrow,colorGreen,0,High);

//Plot( Close,"Price",colorBlack,styleBar);
Plot( stopline, "trailing stop line", colorRed );



Posted in: AFL Amibroker

Leave a Comment