Risk warning

All articles, strategies and indicators are just reflecting a single traders opinion and should be viewed as that.
I advice everybody to trade with a DEMO account!

Sunday, May 1, 2011

Bollingerbands of Relative strength: indicator and strategy.

Their are many articles about the bollinger bands and the relative strength indicator. They both got their strengths and weaknesses. In this post we are going to combine both. We are going to write an indicator and  a strategy.

The bollinger bands can be used in many ways but basically their are 2 main ways they can be traded. The first way is to use them as an overbought and oversold indicator. See below how most traders make their trades when they are using the bands as an oversold and overbought indicator:

Level of risk when used as an ranging indicator:
High risk entry:
sell when pair above upper band (see A)
buy when pair below lower band
Medium risk entry:
sell when pair crosses upper band downwards (see B)
buy when pair crosses lower band upwards
Low risk entry:
sell when pair crosses upper band downwards and close is lower than previous bar opening (see C)
buy when pair crosses lower band upwards and close is higher than previous bar opening



The second way to use the bollinger bands is as an trend indicator. See below how most traders are trading in this case.

Level of risk when used as an trend indicator:
High risk entry:
buy when pair crosses the upper band upwards (see A)
sell when the pair crosses the lower band downwards
Medium risk entry:
buy when 2 consecutive bars are closing above the upper bands (see B)
sell when 2 consecutive bars are closing below the lower bands
Low risk entry:
buy when pair has crossed the upper band upwards before and the pair bounces of the middle band (see C)
sell when pair has crossed the lower band downwards before and pair bounces of the middle band


















The relative strength indicator can also be used in 2 ways. The first way is also as an overbought and oversold indicator. See below how most traders are using the indicator.

Level of risk when used as an ranging indicator:
High risk entry:
sell when the RSI indicator goes above the upper level line
buy when the RSI indicator goes below the lower level line
Medium risk entry
sell when the RSI crosses the upper level line downwards
buy when the RSI crosser the lower level line upwards
Low risk entry:
buy when the RSI has crossed the lower level line upwards and the pair closes above the previous bar opening
sell when the RSI has crossed the upper level line downwards and the pair closes below the previous bar opening

Level of risk when used as an trend indicator:
High risk entry:
buy when the RSI indicator goes above the zero line
sell when the RSI indicator goes below the zero line
Medium risk entry
buy when the RSI indicator goes above the zero line and previous rsi was also above zero line
sell when the RSI indicator goes below the zero line and previous rsi was also below zero line
Low risk entry:
buy when the RSI indicator has crossed the zero line upwards
and close of currentbar > close of previous bar
sell when the RSI indicator has crossed the zero line downwards
and close of currentbar < close of previous bar

Let see what we get if we use the bollinger bands on the RSI indicator. Below you can see an image and the code of the indicator.

indicator Bollinger_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_rsi = 14, period_bbs = 20;
draw rsi("rsi",solid_line,green,2),
     line_mid("mid",solid_line,red,1),
     line_upper("upper",solid_line,purple,1),
     line_lower("lower",solid_line,blue,1);
begin

number dif;
integer i,f;
series u,d,au,ad,tmp;

  f := front(close);
  u[f] := 0;
  d[f] := 0;
  for i := f + 1 to back(close) do begin
    dif := ((close[i]+close[i]+high[i]+low[i])/4) - ((close[i - 1]+close[i - 1]+high[i - 1]+low[i - 1])/4);
    if dif > 0 then begin
      u[i] := dif;
      d[i] := 0;
    end else begin
      u[i] := 0;
      d[i] := -dif;
    end;
  end;
  au := mma(u, period_rsi);
  ad := mma(d, period_rsi);
  rsi := 100 * au / (au + ad);
  line_mid := displace(sma(rsi, period_bbs), 0);
  tmp := displace(2 * stddev(rsi, period_bbs), 0);
  line_upper := line_mid + tmp;
  line_lower := line_mid - tmp;
end.

Again this new indicator can be used in 2 ways. The first way is ideal in an ranging market as an oversold and overbought indicator. The second way is better when the pair is trending. Lets write a strategy that can be used in both cases. You will find the code below.

strategy BBSRSI_v1;

/*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 periodbbs = 20,periodrsi=14,ranging=true,rsi_high_level=75,rsi_low_level=25,lots = 1;

begin
  integer currentbar;
  if back(close) <  front(close) + max(periodbbs,periodrsi) + 1 then return;
  Bollinger_RSI(periodrsi,periodbbs);
  currentbar := back(close);

{entry conditions ranging market} 
if ranging=true and crossup(Bollinger_RSI.rsi,Bollinger_RSI.line_upper) and Bollinger_RSI.rsi[currentbar]>rsi_high_level and
   not long() and not short() then sell(lots);
  
if ranging=true and crossdown(Bollinger_RSI.rsi,Bollinger_RSI.line_lower) and Bollinger_RSI.rsi[currentbar]<rsi_low_level and
   not long() and not short() then buy(lots);

 {entry conditions trending market} 
if ranging=false and crossup(Bollinger_RSI.rsi,Bollinger_RSI.line_upper) and
   not long() and not short() then buy(lots);
  
if ranging=false and crossdown(Bollinger_RSI.rsi,Bollinger_RSI.line_lower) and
   not long() and not short() then sell(lots);
 
{exit conditions trending market}
if ranging=false and long() and crossdown(Bollinger_RSI.rsi,Bollinger_RSI.line_mid) then sell(lots);
if ranging=false and short() and crossup(Bollinger_RSI.rsi,Bollinger_RSI.line_mid) then buy(lots);

{exit conditions ranging market}
if ranging=true and short() and crossdown(Bollinger_RSI.rsi,Bollinger_RSI.line_lower) then buy(lots);
if ranging=true and long() and crossup(Bollinger_RSI.rsi,Bollinger_RSI.line_upper) then sell(lots); 
 
end.

How do you use this strategy? It has the following inputs.

periodbbs = 20 => you can play with this, 20 is default value
periodrsi=14 => you can play with this, 14 is default value
ranging=true => change this to false if you expect trending
rsi_high_level=80 => only important when ranging = true
rsi_low_level=20 => only important when ranging = true
lots = 1 => number of lots the strategy should trade

Some back test results:
eur/usd 1 hour chart, trending, 2 months back test, 1 lot =>  + 233 pips
eur/usd 1 hour chart, ranging, 2 months back test,rsi_high_level=65, rsi_low_level=35,1 lot => +94 pips


3 comments:

  1. Bonjour,
    Hello,
    I can not load this indicator Bollingerbands Relative strength of the platform because ChartStudio gives me several errors:
    line 12 col 1: unexpected error NUMBER
    line 13 col 9: error unexpected IDENTIFIER
    line 14 col 1: unexpected error SERIES
    I would be very grateful if you could communicate this revised code ..
    With my hopes,
    Best Regards
    vicbergeron@orange.fr

    ReplyDelete
    Replies
    1. indicator Bollinger_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_rsi = 14, period_bbs = 20;

      draw rsi("rsi",solid_line,green,2),
      line_mid("mid",solid_line,red,1),
      line_upper("upper",solid_line,green,1),
      line_lower("lower",solid_line,blue,1);
      vars dif(number),i(number),f(number),u(series),d(series),au(series),ad(series),tmp(series);
      begin
      f := front(close);
      u[f] := 0;
      d[f] := 0;
      for i := f + 1 to back(close) do begin
      dif := ((close[i]+close[i]+high[i]+low[i])/4) - ((close[i - 1]+close[i - 1]+high[i - 1]+low[i - 1])/4);
      if dif > 0 then begin
      u[i] := dif;
      d[i] := 0;
      end else begin
      u[i] := 0;
      d[i] := -dif;
      end;
      end;
      au := mma(u, period_rsi);
      ad := mma(d, period_rsi);
      rsi := 100 * au / (au + ad);
      line_mid := displace(sma(rsi, period_bbs), 0);
      tmp := displace(2 * stddev(rsi, period_bbs), 0);
      line_upper := line_mid + tmp;
      line_lower := line_mid - tmp;
      end.

      Delete
    2. Thank you very much, it's great! I could install it without worries ..
      Faced with such kindness I dare ask if it's possible to do the same with the RegressiveForcast as chart studio said:
      line 8 col 9: error unexpected IDENTIFIER
      Pass line 9 9: error unexpected IDENTIFIER
      line 10 col 1: unexpected error SERIES
      With many thanks again
      Bests regards
      PS : I also post on the Forcast page..

      Delete