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!

Monday, April 4, 2011

Highs and lows.

When do we have an uptrend and when do we have an downtrend? One of the many definitions we hear is that for an uptrend we need to have higher highs and higher lows. The inverse for an downtrend : lower highs and lower lows. If you want to program something using highs and lows you need to define what exactly a high or a low is.

You can't write anything without a definition so here it comes : a level 1 high is when the candle on the left and the right are lower. A level 2 high is when we have 2 lower candles on the left and the right. Some images will make everything clear.

Now lets make an indicator that can be used in various strategies. It is pretty complicated so i am not going into detail. Here is the code. This works only in the new versions of dealbook or prostation. An less functional indicator can be written for the old version of dealbook or prostation.

indicator highlow;
/*written by ctlprogrammer*/
input level=5;
draw highs("high"),lows("low"),lasthigh("lasthigh"),lastlow("lastlow");
begin
integer i,j;
integer counter;
integer f := front(close)+1;
integer b := back(close);
bool highdetect;

for j:=0 to level do
begin
lows[i]:=0; highs[i]:=0; lasthigh[i]:=0; lastlow[i]:=0;
end;

for i:=f+level to b-level do
begin
  counter:=0;
  for j:=level downto 1 do
  begin
  if high[i-j]<=high[i] and high[i+j]<=high[i] then counter:=counter+1;
  end;
  if counter=level then
    begin
    highs[i]:=high[i];
    lasthigh[i]:=high[i];
    end
  else
    begin
    highs[i]:=0;
    lasthigh[i]:=lasthigh[i-1];
    end;

counter:=0;
  for j:=level downto 1 do
  begin
  if low[i-j]>=low[i] and low[i+j]>=low[i] then counter:=counter+1;
  end;
  if counter=level then
    begin
    lows[i]:=low[i];
    lastlow[i]:=low[i];
    end
  else
    begin
    lows[i]:=0;
    lastlow[i]:=lastlow[i-1];
    end;

end;
end.


This indicator has 1 input and that's the level we talked about. It has the following outputs.
1) it graphically shows you the highs and lows.
2) it gives you the previous high and lows (very handy to use in all kind of strategies)

A screen shot of the indicator.


Lets go a little bit further with this. Lets make an indicator that shows us when we have higher highs and higher lows. When we have lower highs and lower lows. And when the highs and lows are not pointing in the same direction. Here is the code. Sorry works only with the new version of dealbook or prostation.

number phigh,pphigh,plow,pplow;
indicator highlow_advisor;
/*written by ctlprogrammer*/
input level=5;
draw trendadvise("trendadvise"),trendadvise5("trendadvise5");
begin
highlow(level);
series temp,atr;
integer i;
integer f := front(close);
integer b := back(close);

trendadvise[0]:=0;
for i:=f+1 to b do
begin
trendadvise[i]:=0;
if highlow.highs[i]>0 then
                  begin
                  pphigh:=phigh;
                  phigh:=highlow.highs[i];
                  end;
if highlow.lows[i]>0 then
                  begin
                  pplow:=plow;
                  plow:=highlow.lows[i];
                  end;
                 
if highlow.highs[i]=0 and highlow.lows[i]=0 then trendadvise[i]:=trendadvise[i-1];

if pphigh<phigh and pplow<plow then trendadvise[i]:= 1;
if pphigh>phigh and pplow>plow then trendadvise[i]:= -1;
if pplow<plow and low[i]<plow then trendadvise[i]:=0; {lower upgoing trendline trendline break}
if pphigh>phigh and high[i]>phigh then trendadvise[i]:=0; {descending upper trendline break}

if i<level then trendadvise5[i]:=0;
if i>=level then trendadvise5[i]:=trendadvise[i-level];

end;

end.

A screenshot of this indicator:



How do you use this indicator.

- when 1 means => we have higher highs and higher lows => go long
- when -1 means => we have lower highs and lower lows => go short
- when 0 => lower highs and higher lows or higher highs and lower lows => no trend => prepare for breakout

Important:

1) trend lines can give misleading information in a ranging market! So the indicator can give misleading information when market is ranging!

2) a level n high is only a level n high after we have n lower candles after the high! This means the higher the level the more the indicator will lag. But the higher the level the more important the information given by this indicator is.

The code above is the basic for a pattern detection strategy. To be written....



9 comments:

  1. hello

    What is the last version of Prostation or Chart Studio?

    thanks

    ReplyDelete
  2. You can download the latest version.
    http://www.gftforex.com/Software/360-Download/Default.aspx
    Thats version 2.21.73

    A recent version that can use global variables should be enough.

    ReplyDelete
  3. Hello,

    nice idea. I did something similar in my backtesting to filter out entries in the opposite direction of the short-term trend (indicated by this type of trend recognition). The results were dramatically worse with such a filter. As i see in your screenshots, immediatelly after the indicator goes to 1 or -1 then there are a lot of short-term trend changes. Same as i saw in my backtesting. Do you had better results based on filtering with this indicator?

    ReplyDelete
  4. I wrote a strategy based on this indicator. The result varied from very good to terrible. All depending on the market conditions. I must say this is very hard to optimize. But make no mistake: it's lethal in a ranging market !!

    ReplyDelete
  5. Hallo,

    it´s a interesting indicator. Would it be possible to program the Larry Williams swing-high-lows?

    ReplyDelete
  6. Hallo,

    Do you mean the Greatest Swing Value ( GSV) ?

    ReplyDelete
  7. Hi,
    Larry Williams describe Swing High lows in his book "secrets of short time trading". A a swing high is, if the highs on the left and on the right site of a high is lower. The some like in your code. The different is that the highs of the following right candels have to be lower and the first candle wich the low is lower as low of highest candle confirm the swing. (insidebars).
    I hope you will understand, what I mean. my english is not so perfect.

    ReplyDelete
  8. An indicator for the Larry Williams highs and lows is easy to write. I found a definition on a website but i don't know if it is reliable. I need to be sure of the definition. I don't want to "rape" his definition by writing something that doesn't reflect what he meant.

    ReplyDelete
  9. Hallo,

    it would be great if you have an idea, how to programm it. I was starting to programm it, but got problems with counting the inside days and how ctl remember the swing points so it is able to draw the lines in the chart.

    ReplyDelete