I'm new to forum, having played around with powerlanguage for the past month.
One thing I've been looking for but haven't found anywhere, is an effective way of plotting DT's and DB's. I wanted something dynamic, letting me see what I might over look. After some trial and error and 5 or 6 or maybe 10 itterations I've come up with the following code, which is solid, adaptable and rather compact.
Since I've drawn on so much that has been done before me I felt a good way of giving back, is to share the code. It is usable on any timeframe and market, one just to adjust the offset taking into acount the ticksize of the makret it is applied to.
What it will do, is to plot a new horizontal trend line whenever there is a pivotpoint, and then extend the line until it is either broken or forms a DB/DT with the set offset margins.
I would love any feedback on the quality of code and experiences, as I am trying to imporve my powerlanguage understanding.
With no further delay here are the 2 indicators.
Code for DT
Code: Select all
inputs:
Price(H), LeftStrength(3), RightStrength(3), Offset(0.2);
array:
tl_id[](0), tl_value[](0);
// Declaring arrat size, to hold dynamic number of tops
array_setmaxindex(tl_id, value1+1);
array_setmaxindex(tl_value, value1+1);
// Using Pivot highs for starting possible tops
if PivotHighVSBar(1, Price, LeftStrength, RightStrength, RightStrength+1) <> -1 then
begin
tl_new_bn(barnumber[3], H[3], barnumber, H[3]);
tl_id[value1] = tl_getactive;
tl_value[value1] = H[3];
end;
// Running loop to see if trendlines from pivot highs are crossed
for value1 = 0 to array_getmaxindex(tl_id)
begin
condition1 = H < tl_value[value1]+offset and H > tl_value[value1]-offset;
if tl_id[value1] <> 0 and (condition1 or C > tl_value[value1]) then
begin
tl_setend_bn(tl_id[value1], barnumber, tl_value[value1]);
tl_setcolor(tl_id[value1], green);
tl_setstyle(tl_id[value1], tool_dotted);
tl_id[value1] = 0;
end
else
if tl_id[value1] <> 0 and C < tl_value[value1] then
begin
tl_setend_bn(tl_id[value1], barnumber, tl_value[value1]);
tl_setcolor(tl_id[value1], green);
tl_setstyle(tl_id[value1], tool_dotted);
end;
end;
// Resetting array for next session
if sessionlastbar then
begin
array_setmaxindex(tl_id, 0);
array_setmaxindex(tl_value, 0);
end;
Code of DB
Code: Select all
inputs:
Price(L), LeftStrength(3), RightStrength(3), Offset(0.2);
array:
tl_id[](0), tl_value[](0);
// Declaring array size, to hold dynamic number of tops
array_setmaxindex(tl_id, value1+1);
array_setmaxindex(tl_value, value1+1);
// Using Pivot Lows for starting possible DB's
if PivotLowVSBar( 1, Price, LeftStrength, RightStrength, RightStrength + 1 ) <> -1 then
begin
tl_new_bn(barnumber[3], L[3], barnumber, L[3]);
tl_id[value1] = tl_getactive;
tl_value[value1] = L[3];
end;
// Running loop to see if trendlines from pivot lows are crossed
for value1 = 0 to array_getmaxindex(tl_id)
begin
condition1 = L < tl_value[value1]+offset and L > tl_value[value1]-offset;
if tl_id[value1] <> 0 and (condition1 or C < tl_value[value1]) then
begin
tl_setend_bn(tl_id[value1], barnumber, tl_value[value1]);
tl_setcolor(tl_id[value1], red);
tl_setstyle(tl_id[value1], tool_dotted);
tl_id[value1] = 0;
end
else
if tl_id[value1] <> 0 and C > tl_value[value1] then
begin
tl_setend_bn(tl_id[value1], barnumber, tl_value[value1]);
tl_setcolor(tl_id[value1], red);
tl_setstyle(tl_id[value1], tool_dotted);
end;
end;
// Resetting array for next session
if sessionlastbar then
begin
array_setmaxindex(tl_id, 0);
array_setmaxindex(tl_value, 0);
end;
Riembaus