1) As an overbought and oversold indicator. If the indicator is used like this you sell when the indicator line is above a certain level. This can be 80 for example. You buy when the indicator line is below the oversold level. This can be 20 for example.
2) As a trend indicator. If the indicator is above 50 then we are in a bullish trend. If the indicator is below 50 we are in a bearish trend.
In this strategy the relative strength indicator (also called RSI) is used as an trend indicator. Profit taking is based on overbought and oversold principe.
This strategy will go long when the RSI goes above 50 and will go short when it drops below 50. The next imagine shows the trades we want to "filter" out.
If you at the example you see that the most dangerous entries are the ones where the relative strength just crossed the level 50. If the RSI has been a while above or under the 50 level the risk is a lot smaller. So this
strategy checks how long the RSI has been above or under that level. You can choose yourself how long this must be. With the "filter" input. If you run some back test you will see for yourself that a small "filter" results in more bad entries. If you make the "filter" to big than you are screwed too because then you will be entering to late when the RSI goes back to the level 50.
The strategy lets you choose between 2 types of money management:
The first one ==> Use_Max_loss_and_Profit_target=false
If long() and fpl()>0 and rsi[currentbar]>60 and rsi[currentbar-1]>rsi[currentbar] then exitlong();
If short() and fpl()>0 and rsi[currentbar]<40 and rsi[currentbar-1]<rsi[currentbar] then exitshort();
If short() and fpl()>0 and rsi[currentbar]<40 and rsi[currentbar-1]<rsi[currentbar] then exitshort();
==> this works as a kind of profit locking mechanisme
if long() and rsi[currentbar]<50 then exitlong();
if short() and rsi[currentbar]>50 then exitshort();
if long() and rsi[currentbar]<50 then exitlong();
if short() and rsi[currentbar]>50 then exitshort();
==> this closed the position when the trade really goes the wrong way
The seconf one==> Use_Max_loss_and_Profit_target=true
if long() and fpl()>Profit_target then exitlong();
if short() and fpl()>Profit_target then exitshort();
==> profit taking
if long() and fpl()<-Max_loss then exitlong();
if short() and fpl()<-Max_loss then exitshort();
==> loss to big so close positions
if long() and rsi[currentbar]<50 then exitlong();
if short() and rsi[currentbar]>50 then exitshort();
==> profit taking
if long() and fpl()<-Max_loss then exitlong();
if short() and fpl()<-Max_loss then exitshort();
==> loss to big so close positions
if long() and rsi[currentbar]<50 then exitlong();
if short() and rsi[currentbar]>50 then exitshort();
==> trade goes the wrong way
For information, this strategy was written using a 1 hour EUR/USD chart. RSI trend trading doen't perform well in small time frames!
The code for those that are using an old version of dealbook or prostation:
strategy Filtered_RSI;
/*written by ctlprogrammer*/
/*Warning for demonstration purpose only, no live trading please*/
/*you can freely copy the code but plz leave this header*/
/*http://ctltrading.blogspot.com*/
input period = 20, lots = 1,filter=10,Max_loss=50,Profit_target=50,Use_Max_loss_and_Profit_target=true;
vars currentbar = 1,rsi(series),i(number),j(number),countup(number),countdown(number);
begin
/*written by ctlprogrammer*/
/*Warning for demonstration purpose only, no live trading please*/
/*you can freely copy the code but plz leave this header*/
/*http://ctltrading.blogspot.com*/
input period = 20, lots = 1,filter=10,Max_loss=50,Profit_target=50,Use_Max_loss_and_Profit_target=true;
vars currentbar = 1,rsi(series),i(number),j(number),countup(number),countdown(number);
begin
currentbar := back(close);
if currentbar < front(close) - 1 + period+filter then return;
relative_strength(close, period);
rsi:=Relative_Strength.line;
{*************filter**********}
if rsi[currentbar]>50 then
begin
for i:=1 to filter do
begin
if rsi[currentbar-i]>50 then countup:=countup+1;
if rsi[currentbar-i]<50 then break;
end;
end;
if rsi[currentbar]<50 then
begin
for j:=1 to filter do
begin
if rsi[currentbar-j]<50 then countdown:=countdown+1;
if rsi[currentbar-j]>50 then break;
end;
end;
{*************entries**********}
if countup=filter and rsi[currentbar]>50 and not long() and not short() then buy(lots);
if countdown=filter and rsi[currentbar]<50 and not long() and not short() then sell(lots);
{*************exits************}
if Use_Max_loss_and_Profit_target=true then
begin
if long() and fpl()>Profit_target then exitlong();
if short() and fpl()>Profit_target then exitshort();
if long() and fpl()<-Max_loss then exitlong();
if short() and fpl()<-Max_loss then exitshort();
if long() and rsi[currentbar]<50 then exitlong();
if short() and rsi[currentbar]>50 then exitshort();
end;
if Use_Max_loss_and_Profit_target=false then
begin
If long() and fpl()>0 and rsi[currentbar]>60 and rsi[currentbar-1]>rsi[currentbar] then exitlong();
If short() and fpl()>0 and rsi[currentbar]<40 and rsi[currentbar-1]<rsi[currentbar] then exitshort();
if long() and rsi[currentbar]<50 then exitlong();
if short() and rsi[currentbar]>50 then exitshort();
end;
end.
if currentbar < front(close) - 1 + period+filter then return;
relative_strength(close, period);
rsi:=Relative_Strength.line;
{*************filter**********}
if rsi[currentbar]>50 then
begin
for i:=1 to filter do
begin
if rsi[currentbar-i]>50 then countup:=countup+1;
if rsi[currentbar-i]<50 then break;
end;
end;
if rsi[currentbar]<50 then
begin
for j:=1 to filter do
begin
if rsi[currentbar-j]<50 then countdown:=countdown+1;
if rsi[currentbar-j]>50 then break;
end;
end;
{*************entries**********}
if countup=filter and rsi[currentbar]>50 and not long() and not short() then buy(lots);
if countdown=filter and rsi[currentbar]<50 and not long() and not short() then sell(lots);
{*************exits************}
if Use_Max_loss_and_Profit_target=true then
begin
if long() and fpl()>Profit_target then exitlong();
if short() and fpl()>Profit_target then exitshort();
if long() and fpl()<-Max_loss then exitlong();
if short() and fpl()<-Max_loss then exitshort();
if long() and rsi[currentbar]<50 then exitlong();
if short() and rsi[currentbar]>50 then exitshort();
end;
if Use_Max_loss_and_Profit_target=false then
begin
If long() and fpl()>0 and rsi[currentbar]>60 and rsi[currentbar-1]>rsi[currentbar] then exitlong();
If short() and fpl()>0 and rsi[currentbar]<40 and rsi[currentbar-1]<rsi[currentbar] then exitshort();
if long() and rsi[currentbar]<50 then exitlong();
if short() and rsi[currentbar]>50 then exitshort();
end;
end.
The code for those that are using a new version of dealbook or prostation.
strategy Filtered_RSI;
/*written by ctlprogrammer*/
/*Warning for demonstration purpose only, no live trading please*/
/*you can freely copy the code but plz leave this header*/
/*http://ctltrading.blogspot.com*/
input period = 20, lots = 1,filter=10,Max_loss=50,Profit_target=50,Use_Max_loss_and_Profit_target=true;
/*written by ctlprogrammer*/
/*Warning for demonstration purpose only, no live trading please*/
/*you can freely copy the code but plz leave this header*/
/*http://ctltrading.blogspot.com*/
input period = 20, lots = 1,filter=10,Max_loss=50,Profit_target=50,Use_Max_loss_and_Profit_target=true;
begin
number countup,countdown;
integer i,j,currentbar,filter_integer;
series rsi;
currentbar := back(close);
if currentbar < front(close) - 1 + period+filter then return;
filter_integer:=filter;
relative_strength(close, period);
rsi:=Relative_Strength.line;
{*************filter**********}
if rsi[currentbar]>50 then
begin
for i:=1 to filter_integer do
begin
if rsi[currentbar-i]>50 then countup:=countup+1;
if rsi[currentbar-i]<50 then break;
end;
end;
if rsi[currentbar]<50 then
begin
for j:=1 to filter_integer do
begin
if rsi[currentbar-j]<50 then countdown:=countdown+1;
if rsi[currentbar-j]>50 then break;
end;
end;
{*************entries**********}
if countup=filter_integer and rsi[currentbar]>50 and not long() and not short() then buy(lots);
if countdown=filter_integer and rsi[currentbar]<50 and not long() and not short() then sell(lots);
{*************exits************}
if Use_Max_loss_and_Profit_target=true then
begin
if long() and fpl()>Profit_target then exitlong();
if short() and fpl()>Profit_target then exitshort();
if long() and fpl()<-Max_loss then exitlong();
if short() and fpl()<-Max_loss then exitshort();
if long() and rsi[currentbar]<50 then exitlong();
if short() and rsi[currentbar]>50 then exitshort();
end;
if Use_Max_loss_and_Profit_target=false then
begin
If long() and fpl()>0 and rsi[currentbar]>60 and rsi[currentbar-1]>rsi[currentbar] then exitlong();
If short() and fpl()>0 and rsi[currentbar]<40 and rsi[currentbar-1]<rsi[currentbar] then exitshort();
if long() and rsi[currentbar]<50 then exitlong();
if short() and rsi[currentbar]>50 then exitshort();
end;
end.
number countup,countdown;
integer i,j,currentbar,filter_integer;
series rsi;
currentbar := back(close);
if currentbar < front(close) - 1 + period+filter then return;
filter_integer:=filter;
relative_strength(close, period);
rsi:=Relative_Strength.line;
{*************filter**********}
if rsi[currentbar]>50 then
begin
for i:=1 to filter_integer do
begin
if rsi[currentbar-i]>50 then countup:=countup+1;
if rsi[currentbar-i]<50 then break;
end;
end;
if rsi[currentbar]<50 then
begin
for j:=1 to filter_integer do
begin
if rsi[currentbar-j]<50 then countdown:=countdown+1;
if rsi[currentbar-j]>50 then break;
end;
end;
{*************entries**********}
if countup=filter_integer and rsi[currentbar]>50 and not long() and not short() then buy(lots);
if countdown=filter_integer and rsi[currentbar]<50 and not long() and not short() then sell(lots);
{*************exits************}
if Use_Max_loss_and_Profit_target=true then
begin
if long() and fpl()>Profit_target then exitlong();
if short() and fpl()>Profit_target then exitshort();
if long() and fpl()<-Max_loss then exitlong();
if short() and fpl()<-Max_loss then exitshort();
if long() and rsi[currentbar]<50 then exitlong();
if short() and rsi[currentbar]>50 then exitshort();
end;
if Use_Max_loss_and_Profit_target=false then
begin
If long() and fpl()>0 and rsi[currentbar]>60 and rsi[currentbar-1]>rsi[currentbar] then exitlong();
If short() and fpl()>0 and rsi[currentbar]<40 and rsi[currentbar-1]<rsi[currentbar] then exitshort();
if long() and rsi[currentbar]<50 then exitlong();
if short() and rsi[currentbar]>50 then exitshort();
end;
end.
No comments:
Post a Comment