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.
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.
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....
hello
ReplyDeleteWhat is the last version of Prostation or Chart Studio?
thanks
You can download the latest version.
ReplyDeletehttp://www.gftforex.com/Software/360-Download/Default.aspx
Thats version 2.21.73
A recent version that can use global variables should be enough.
Hello,
ReplyDeletenice 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?
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 !!
ReplyDeleteHallo,
ReplyDeleteit´s a interesting indicator. Would it be possible to program the Larry Williams swing-high-lows?
Hallo,
ReplyDeleteDo you mean the Greatest Swing Value ( GSV) ?
Hi,
ReplyDeleteLarry 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.
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.
ReplyDeleteHallo,
ReplyDeleteit 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.