Need help in building RMI scanner for backtesting

Hello Experts,
I am looking for some help in building a scanner to backtest my trading idea. This code is based on RMI indicator & it has 3 components -

  1. RMI
  2. Relative Momentum Index
  3. Weighted MA of Relative Momentum Index

I need to backtest my results with the following conditions -
Buy - When RMI(3,15) is above 60 AND Relative Momentum Index crosses above 50 along with Weighted MA of Relative Momentum Index
Sell/Exit : Weighted MA of Relative Momentum Index closes below 50

Short - When RMI(3,15) is below 40 AND Relative Momentum Index crosses below 50 along with Weighted MA of Relative Momentum Index
Cover/Exit : Weighted MA of Relative Momentum Index closes above 50

Here is the code I use for your reference. Thanks a ton in advance.

Length=Param("Length?",1,2,60,1);//default =14 or 20
mom=Param("Momentum?",1,2,15,1);//default = 4 or 5
xRMI = RMI(Length,mom);
Plot(xRMI, " Relative Momentum Index ("+WriteVal(Length,1.0)+")", colorDarkBlue, 1 + styleThick);
_SECTION_END();

Plot(50,"",colorCustom11,styleLine, styleThick|styleNoLabel);//midline

Buy  = Ref(xRMI,-1)<50 AND xRMI > Ref(xRMI,-1);
Sell = Ref(xRMI,-1)>50 AND xRMI < Ref(xRMI,-1);
Buy  = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
PlotShapes( shapeUpArrow * Buy + shapeDownArrow * Sell, IIf( Buy, colorGreen, colorRed ) );

/*End Buy and Sell Conditions*/

_SECTION_BEGIN("RMI1");
periods = Param( "Periods", 20, 1, 200, 1 );
momentum = Param( "Momentum", 5, 1, 200, 1 );
Plot( RMI(periods, momentum)  , _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();

//XXXXXXXXXXXXXXXXXXX EXPLORE XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
_SECTION_BEGIN("Weighted MA Color");

//SetChartBkColor( ColorHSB( 86, 36, 126 ) );
P = ParamField("Field");
Type = ParamList("Type", "Weighted,Lagless-21,Hull-26,Linear Regression-45,Exponential,Double Exponential,Tripple Exponential,Wilders,Simple");
Periods = Param("Periods", 9, 2, 100 );
Displacement = Param("Displacement", 1, -50, 50 );
m = 0;

if( Type == "Weighted" )             m=  WMA( P, Periods );
if( Type == "Lagless-21"  )            m=  2*EMA(P, Periods)-EMA(EMA(P, Periods), Periods);
if( Type == "Hull-26"  )            m=  WMA(2*(WMA(P, Periods/2))-WMA(P, Periods) ,4 );
if( Type == "Linear Regression-45"  ) m=  LinearReg( P, Periods );
if( Type == "Exponential" )          m = EMA( P, Periods );
if( Type == "Double Exponential" )    m = DEMA( P, Periods );
if( Type == "Tripple Exponential" )    m = TEMA( P, Periods );
if( Type == "Wilders" )             m = Wilders( P, Periods );
if( Type == "Simple" )                m = MA( P, Periods );


Linecolor = IIf( m > Ref( m, -1), ParamColor("UPColor", colorGreen), ParamColor("DOWNColor", colorRed) );

Plot( m, _DEFAULT_NAME(),Linecolor  , styleThick, 0, 0, Displacement );
_SECTION_END();

Regards
Vihaan

1 Like

Dear Experts,

Any help to fine tune this AFL would be greatly appreciated. If any additional info is required to solve this query, please let me know.

Thanks in advance.

Regards
Abhinav