Dear friend houmansat,
this code will buy when
1) rsi touches support line
2) rsi crosses below the support line
this code will sell when
1) rsi touches the resistance line
2) rsi crosses above the resistance line
i have shown white arrows on chart for buy n sell conditions
this code can be used to scan, explore n backtest too
here is the code
this code will buy when
1) rsi touches support line
2) rsi crosses below the support line
this code will sell when
1) rsi touches the resistance line
2) rsi crosses above the resistance line
i have shown white arrows on chart for buy n sell conditions
this code can be used to scan, explore n backtest too
here is the code
Code:
_SECTION_BEGIN("RSI ");
SetChartOptions(0,0,chartGrid30|chartGrid70);
periods = Param( "Periods", 14, 1, 200, 1 );
a = RSI(periods);
Plot( a, _DEFAULT_NAME(), ParamColor( "Color", colorYellow ), ParamStyle("Style",styleThick) );
/*RSI Trendlines and Wedges*/
G=0;// set G=1, 2, 3, ... to see previous Resistance trendlines
GG=0;// set G=1, 2, 3, ... to see previous Support trendlines
x = Cum(1);
per = Param("Sensitivity",30,1,1000,1); // sensitivity calibration
s1=a;
s11=a;
pS = TroughBars( s1, per, 1 ) == 0;
endt= LastValue(ValueWhen( pS, x, 1+GG ));
startt=LastValue(ValueWhen( pS, x, 2+GG ));
dtS =endt-startt;
endS = LastValue(ValueWhen( pS, s1, 1+GG ) );
startS = LastValue( ValueWhen( pS, s1, 2+GG ));
aS = (endS-startS)/dtS;
bS = endS;
trendlineS = aS * ( x -endt ) + bS;// the Support trendline equation
Plot(IIf(x>startt-6 AND TRENDLINES>0 AND TRENDLINES<100,trendlineS,null),"Support",IIf(as>0,5,4),8);
pR = PeakBars( s11, per, 1 ) == 0;
endt1= LastValue(ValueWhen( pR, x, 1+G ));
startt1=LastValue(ValueWhen( pR, x, 2+G ));
dtR =endt1-startt1;
endR = LastValue(ValueWhen( pR, s11, 1+G ) );
startR = LastValue( ValueWhen( pR, s11, 2 +G ));
aR = (endR-startR)/dtR;
bR = endR;
trendlineR = aR * ( x -endt1 ) + bR;// the Resistance trendline equation
Plot(IIf(x>startT1-6 AND TRENDLINER>0 AND TRENDLINER<100,trendlineR,null),"Resistance",IIf(Ar>0,5,4),8);
Ascwedge=Ar>0.5 AND As>sqrt(2)*Ar AND trendlineR>trendlineS;
Descwedge= As<-0.5 AND As>Ar/sqrt(2) AND trendlineR>trendlineS;
Sell=Short=x>startT1-1 AND TRENDLINER>0 AND TRENDLINER<100 AND Cross(a,trendliner) OR a==trendliner;
Buy=Cover=x>startt-1 AND TRENDLINES>0 AND TRENDLINES<100 AND Cross(trendlines,a) OR a==trendlines;
Filter= Buy OR Sell;
Plotshapes(Buy*shapeUpArrow,colorwhite,0,a,-12);
Plotshapes(Sell*shapedownArrow,colorwhite,0,a,-12);
AddColumn(IIf(Buy,BuyPrice,Null)," RSI Buy Signal ", 1.2,colorblack,IIf(Buy,colorGreen,-1));
AddColumn(IIf(Sell,SellPrice,Null)," RSI Sell Signal ",1.2,colorblack,IIf(Sell,colorred,-1));
Last edited: