Rsi swing divergense in afl code

I need RSI Swing divergence afl with the following validations Buy: if rsi (14) 60 it should check for rsi (14) and price divergence should be checked Sell: if rsi (14) > 60 it should check for rsi (14) and price divergence should be checked Please help me in coding this in Afl

1 Like

RSI SWING DIVERGENCE  AFL CODE

_SECTION_BEGIN("350Swing"); 

nRSILen = Param("RSI Length", 3, 2, 50 ); 
nMALen = Param("MA Length", 3 ); 
UpColor = ParamColor("UpColor", colorGreen ); 
DnColor = ParamColor("DnColor", colorRed ); 

r = RSI( nRSILen ); 
rma = MA( r, nMALen ); 
Color = IIf( r > 50, UpColor, DnColor ); 

mode =  ParamList("Display", "RSI|RSIMA|Price"); 

switch( mode ) 
{ 
case "RSI":  
         Plot( r, _DEFAULT_NAME(), Color ); 
         break; 
case "RSIMA":   
         Plot( rma,  "RSI MA" + _PARAM_VALUES(), colorBlue ); 
         PlotOHLC( 50, rma, 50, rma, "", colorLightBlue , styleCloud | styleClipMinMax, 20, 80 ); 
         break; 
case "Price": 
         SetBarFillColor( Color ); 
         Plot( C, "Price", Color, styleCandle ); 
         PlotShapes( ( rma < 20 ) * shapeSmallCircle, colorGreen, 0, L, -20 ); 
         PlotShapes( ( rma > 80 ) * shapeSmallCircle, colorRed, 0, H, 20 ); 
         Plot( HHV( H, 20 ), "", colorLightBlue ); 
         Plot( LLV( L, 20 ), "", colorLightBlue ); 
         break; 
} 
_SECTION_END();

_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”, colorDefault ), styleNoTitle | ParamStyle(“Style”) | GetPriceStyle() );
a=RSI(14)<40 AND L<Ref(L,-1) AND RSI(14)>Ref(RSI(14),-1);
b=RSI(14)>60 AND H>Ref(H,-1) AND RSI(14)<Ref(RSI(14),-1);
Buy=a;
Sell=b;
shape = Buy * shapeUpArrow + Sell * shapeDownArrow;
//PlotShapes(shape, IIf(Buy,colorWhite,colorWhite), 0, IIf(Buy,Low,High));
Plot( HHV(H,20), “HHV”, ParamColor(“HHV”,colorBlue),
ParamStyle(“HHV Style”, styleStaircase));
Plot(LLV(L,20), “LLV”,ParamColor(“LLV
Color”,colorred), ParamStyle(“LLV Style”, stylestaircase));
Plot(SelectedValue( TimeFrameGetPrice( “H”, inDaily, -1 ) ), “PH”, ParamColor(“PH”,colorBlue),
ParamStyle(“PH Style”, styleDashed));
Plot(SelectedValue( TimeFrameGetPrice( “L”, inDaily, -1 ) ), “PL”, ParamColor(“PL”,colorRed),
ParamStyle(“PL Style”, styleDashed));
PlotShapes(shapeUpArrowBuy,colorBlue);
PlotShapes(shapeDownArrow
Sell,colorBlue);
AlertIf( Buy, “SOUND C:\Windows\Media\notify.wav”, “Audio alert”, 2 );
AlertIf( Sell, “SOUND C:\Windows\Media\chord.wav”, “Audio alert”, 2 );
_SECTION_END();
_SECTION_BEGIN( “RAJA” );
/RAJA/
"========";
H1 = SelectedValue( TimeFrameGetPrice( “H”, inDaily, -1 ) );
L1 = SelectedValue( TimeFrameGetPrice( “L”, inDaily, -1 ) );
C1 = SelectedValue( TimeFrameGetPrice( “C”, inDaily, -1 ) );
H2 = SelectedValue( TimeFrameGetPrice( “H”, inDaily, 0 ) );
L2 = SelectedValue( TimeFrameGetPrice( “L”, inDaily, 0 ) );
O1 = SelectedValue( TimeFrameGetPrice( “open”, inDaily, 0 ) );
/PIVOT Calculation/
D1 = ( H1 - L1 );
D2 = ( H2 - L2 );
F1 = D1 * 0.433;
F2 = D1 * 0.766;
F3 = D1 * 1.35;
F4 = 0;
if ( D2 <= F1 )
F4 = F1;
else
if ( D2 <= F2 )
F4 = F2;
else
F4 = F3;
p = ( H1 + L1 + C1 ) / 3;
s1 = ( H1 );
r1 = ( L1 );
r2 = SelectedValue( L2 );
s2 = SelectedValue( H2 );
//CONDITION
S = ( C > p );
SS = ( C < P );
//Plot
/*
Plot ( p , “PIVOT”, 25, 1 );PlotText( “PIVOT” , BarCount-25, p+0, 25 );
Plot ( r1, “PRE_LOW”, 28, 1 );PlotText( “PreDay LOW” , BarCount-25, r1+0, 28 );
Plot ( s1, “PRE_HIGH”, 28, 1 );PlotText( “PreDay HIGH” , BarCount-25, s1+0, 28 );
Plot ( s2, “DAY_HIGH”, 42, 1 );PlotText( “Day HIGH” , BarCount-25, s2+0, 42 );
Plot ( r2, “DAY_LOW”, 42, 1 );PlotText( “Day LOW” , BarCount-25, r2+0, 42 );
Plot ( O1, “DAY_Open”, 15, 1 );PlotText( “Day Open” , BarCount-25, O1+0, 15 );
*/
pxHeight = Status( “pxchartheight” ) ;
xx = Status( “pxchartwidth”);
Left = 1100;
width = 310;
x = 5;
x2 = 290;
y = pxHeight;
_SECTION_END();
please help me in editing code woith above condition

The above code is not relevant i need I need RSI Swing divergence afl with the following validations Buy: if rsi (14) 60 it should check for rsi (14) and price divergence should be checked Sell: if rsi (14) > 60 it should check for rsi (14) and price divergence should be checked Please help me in coding this in Afl

ok…let me check