MA & RSI AFL Code

#1
Hi AFL Experts

I want the code including the buy/sell variables for the following:

Buy if Simple MA 5 days Cross Simple MA 25 Days and RSI(9)> 50
Sell if Simple MA 5 days Cross Simple MA 25 Days and RSI(9)< 50

Thanks in advance:D
 
Last edited:
#2
Hi intool,

Hope this will help.

TC

//*************************************************************
_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, RSI(9),SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();


_SECTION_BEGIN("Short MA");
P = ParamField("Price field",-1);
Periods = Param("Periods", 5, 2, 200, 1, 10 );
Plot( MA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorYellow ), ParamStyle("Style", styleThick | styleDashed|styleDots) );
_SECTION_END();

_SECTION_BEGIN("Long MA");
P = ParamField("Price field",-1);
Periods = Param("Periods", 25, 2, 200, 1, 10 );
Plot( MA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorTeal ), ParamStyle("Style", styleThick | styleDashed|styleDots) );
_SECTION_END();

Buy=Cross(MA( Close,5 ),MA( Close,25 )) AND RSI(9)>50;
Sell=Cross(MA( Close,25 ),MA( Close,5 )) AND RSI(9)<50;

PlotShapes(shapeUpArrow * Buy, ParamColor("Buy Arrow", colorBrightGreen),0,Low, - 20);
PlotShapes(shapeDownArrow * Sell, ParamColor("Sell Arrow", colorRed),0,High, - 20);

_SECTION_BEGIN("RSI");
periods = Param( "Periods", 9, 1, 200, 1 );
Plot( RSI( periods), _DEFAULT_NAME(), ParamColor( "Color", colorWhite ), ParamStyle("Style",styleLine|Stylehidden,maskAll) );
_SECTION_END();
 

ping

New Member
#4
Hello,

What if the conditions are like this?


Buy if PRICE is above the Simple MA50 days and RSI(14)> 50
Sell if PRICE is below the Simple MA50 days (deviation 0.2) and RSI(14)< 50


Thanks.


I also added this for scanning


Filter = Buy OR Sell;
AddColumn( Buy, "Buy", 1);
AddColumn(Sell, "Sell", 1);
AddColumn(Close,"Close",1.2);
AddColumn(Volume,"Volume",1.0);
 
#5
Hello guys....I HV new strategy...can any1 make it...really it's great...I tried but can't make multi timeframe scanner..... strategy is 4 hr price above 8EMA & RSI over 60 or below 40 for trend setup...then..15 min 5/13 email crossover with RSI over 60 or below 40...for signal....then..5min for again 5/13 ema crossover for low stop-loss entry...... target is ..again 15 min 5/13 ema crossover.....
 
#7
//*************************************************************
_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, RSI(9),SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();


_SECTION_BEGIN("Short MA");
P = ParamField("Price field",-1);
Periods = Param("Periods", 5, 2, 200, 1, 10 );
Plot( MA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorYellow ), ParamStyle("Style", styleThick | styleDashed|styleDots) );
_SECTION_END();

_SECTION_BEGIN("Long MA");
P = ParamField("Price field",-1);
Periods = Param("Periods", 25, 2, 200, 1, 10 );
Plot( MA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorTeal ), ParamStyle("Style", styleThick | styleDashed|styleDots) );
_SECTION_END();

Buy=Cross(MA( Close,5 ),MA( Close,25 )) AND RSI(9)>50;
Sell=Cross(MA( Close,25 ),MA( Close,5 )) AND RSI(9)<50;

PlotShapes(shapeUpArrow * Buy, ParamColor("Buy Arrow", colorBrightGreen),0,Low, - 20);
PlotShapes(shapeDownArrow * Sell, ParamColor("Sell Arrow", colorRed),0,High, - 20);

_SECTION_BEGIN("RSI");
periods = Param( "Periods", 9, 1, 200, 1 );
Plot( RSI( periods), _DEFAULT_NAME(), ParamColor( "Color", colorWhite ), ParamStyle("Style",styleLine|Stylehidden,maskAll) );
_SECTION_END();

Have Message:
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, RSI(9),SelectedValue( ROC( C, 1 ) ) ));
Error 61. The number of format specifier(s) (%) does not match the number of arguments passed.
How could repair when I use Amibroker 6.2 ?
Great Tks
 

Similar threads