DGL implementation using Mouse Events

Studies that have been contributed to the community by other users. If you’ve got something useful to share, that’s great!
johnromeronc
Posts: 53
Joined: 18 Feb 2011
Has thanked: 11 times
Been thanked: 13 times

DGL implementation using Mouse Events

Postby johnromeronc » 01 Jul 2012

This is my implementation of some aspects of Dynamic Gann Levels. using mouse events to recalculate.
I prefer to use fib ratios instead of 1/8s as the original DGL - you can change the input if you want.
I also did not implement any of the extentions fo the DGL levels greater than 1.0 -- like 1.32, 1.61,
I hope to use Mouse Events to select the points in the future. I'm currently having issues with Text_New and getting the MouseDateTime into values it will use.
You are welcome to use this code freely.
I used code originally created by Gregory Wood and it then had several modifications by others after that.

Usage: use the text tool to label swing high/lows with "a0", "b0" and "c0"
In its current implementation you can only have 4 sets of a-b-c's .a0-b0-c0 thru a3-b3-c3
The 2nd text character is what determines which 3 points belong to which DGL.
It will use the close for Point "a' and depending on the relationship of point "b" to "c", it will create a V (high - low - high) or inverted V DGL (low - high - low).
Then refresh the indicator by using Ctrl Left mouse click - This is to save you from having to cycle the status of the indicator from On - Off - On
When you press Ctrl Left Mouse Click - it will do a Recalculate.
As part of the initial calculation and recalculation it will delete any orphan text points.
Example you delete c3, but leave a3 and b3. These 2 will be deleted from the chart as part of the recalculation
You can delete any of the three ax, bx, or cx and it will delete the other 2 in that DGL group.
You can use the mouse to move a point and them Ctrl Left Mouse Click and it will redraw it for you.
I also automatically draw Andrews pitchfork, as that is what I wanted. You can go in and delete / comment that part of the code if you want
The color of each entire set of DGL lines (levels) is the same color, with the exception for DGL lvl = 0.5, that I color Magenta.
Line style of "dot" for the lower DGL levels, "solid" for higher.
Input selection for the values to use for the levels and colors for each DGL set of points.
I do not move the text like the original implementation did, as this will stack the text objects on the close/high/low and make it difficult to select or move them.

Use the pointer to move the labels to other points, then Ctrl Left Mouse Click to refresh.
You can display other groups of points by using labels "ax", "bx" and "cx",
where 'x' is 1, 2, or 3, e.g. "a3", "b3", "c3".
The DGL can overlap each other.

As this is a work in progress, there are some variables that I created and are not used.
When you look in the Switch/Case set of code, you can see where I am trying to figure out how to get MouseClickDateTime into the Date and Time parts of New_Text.
Once I get past that, I / You will be able to seelect the a-b-c points using Shift Left Mouse Click and not need to use the keyboard for anything.
Almost like a real drawing tool, except you can not move the set of lines as a whole / group.

Below is the log of the code before I stripped out what I didn't want and added other lines of code.
12/14/96 v1.0 - Initial distribution by Gregory Wood
12/16/96 v1.1 - Point A now uses the Close; projected TL's now extend right
01/08/97 v1.15 - Add customizable colors
01/10/97 v1.16 - Text placement logic now uses bar midpoint instead of close
01/13/97 v1.17 - Print values to log file
07/25/99 v1.18 - adapt to ts2k
John Romero
2012/07/01 - heaviliy modified / stripped original to use mouse events and removed things I did not want to speed it up.


Image

Code: Select all

[ProcessMouseEvents = true] ;


Inputs: Inp_Lvl_0(0.0),
Inp_Lvl_1(0.125),
Inp_Lvl_2(0.238),
Inp_Lvl_3(0.382),
Inp_Lvl_4(0.5),
Inp_Lvl_5(0.618),
Inp_Lvl_6(0.786),
Inp_Lvl_7(0.875),
Inp_Lvl_8(1.0),
Inp_ColorSet0(red),
Inp_ColorSet1(green),
Inp_ColorSet2(cyan),
Inp_ColorSet3(yellow);

vars: JOR_0(0), JOR_1(0), JOR_Recalc(0), JOR_Text("a3"),JOR_Date(0),JOR_Time(0),JOR_Bar(0);

{

This is my implementation of some aspects of Dynamic Gann Levels. using mouse events to recalculate.
I prefer to use fib ratios instead of 1/8s as the original DGL - you can change the input if you want.
I also did not implement any of the extentions fo the DGL levels greater than 1.0 -- like 1.32, 1.61,
I hope to use Mouse Events to select the points in the future. I'm currently having issues with Text_New and getting the MouseDateTime into values it will use.
You are welcome to use this code freely.
I used code originally created by Gregory Wood and it then had several modifications by others after that.

Usage: use the text tool to label swing high/lows with "a0", "b0" and "c0"
In its current implementation you can only have 4 sets of a-b-c's .a0-b0-c0 thru a3-b3-c3
The 2nd text character is what determines which 3 points belong to which DGL.
It will use the close for Point "a' and depending on the relationship of point "b" to "c", it will create a V (high - low - high) or inverted V DGL (low - high - low).
Then refresh the indicator by using Ctrl Left mouse click - This is to save you from having to cycle the status of the indicator from On - Off - On
When you press Ctrl Left Mouse Click - it will do a Recalculate.
As part of the initial calculation and recalculation it will delete any orphan text points.
Example you delete c3, but leave a3 and b3. These 2 will be deleted from the chart as part of the recalculation
You can delete any of the three ax, bx, or cx and it will delete the other 2 in that DGL group.
You can use the mouse to move a point and them Ctrl Left Mouse Click and it will redraw it for you.
I also automatically draw Andrews pitchfork, as that is what I wanted. You can go in and delete / comment that part of the code if you want
The color of each entire set of DGL lines (levels) is the same color, with the exception for DGL lvl = 0.5, that I color Magenta.
Line style of "dot" for the lower DGL levels, "solid" for higher.
Input selection for the values to use for the levels and colors for each DGL set of points.
I do not move the text like the original implementation did, as this will stack the text objects on the close/high/low and make it difficult to select or move them.

Use the pointer to move the labels to other points, then Ctrl Left Mouse Click to refresh.
You can display other groups of points by using labels "ax", "bx" and "cx",
where 'x' is 1, 2, or 3, e.g. "a3", "b3", "c3".
The DGL can overlap each other.

As this is a work in progress, there are some variables that I created and are not used.
When you look in the Switch/Case set of code, you can see where I am trying to figure out how to get MouseClickDateTime into the Date and Time parts of New_Text.
Once I get past that, I / You will be able to seelect the a-b-c points using Shift Left Mouse Click and not need to use the keyboard for anything.
Almost like a real drawing tool, except you can not move the set of lines as a whole / group.

Below is the log of the code before I stripped out what I didn't want and added other lines of code.
12/14/96 v1.0 - Initial distribution by Gregory Wood
12/16/96 v1.1 - Point A now uses the Close; projected TL's now extend right
01/08/97 v1.15 - Add customizable colors
01/10/97 v1.16 - Text placement logic now uses bar midpoint instead of close
01/13/97 v1.17 - Print values to log file
07/25/99 v1.18 - adapt to ts2k

John Romero
2012/07/01 - heaviliy modified / stripped original to use mouse events and removed things I did not want to speed it up.
}

switch (getappinfo(aicalcreason)) begin
case CalcReason_MouseLClick :
if MouseClickCtrlPressed then begin
// JOR_0 = MouseClickDateTime;
// print("mouse date time --> ",MouseClickDateTime);
// print("JOR_0 --> ",JOR_0);
// print("Left Ctrl -> Date portion of MouseDtTm = ", DateToString(IntPortion(JOR_0)));
// print("Left Ctrl ->Time Portion of MouseDtTm = ", TimeToString(FracPortion(JOR_0)));
// print("price --> ", MouseClickPrice);
// JOR_1 = text_new_s( JOR_0,JOR_0,MouseClickPrice,JOR_Text);
// JOR_1 = text_new_s( Intportion(JOR_0),FracPortion(JOR_0),MouseClickPrice,JOR_Text);
// if JOR_Text = "a3" then JOR_Text = "b3";
// if JOR_Text = "b3" then JOR_Text = "c3";
end { if MouseClickCtrlPressed & CalcReason_MouseLClick }
else
if MouseClickShiftPressed then begin
// print("recacl");
// JOR_Recalc = 1;
recalculate;
end; { if MouseClickShiftPressed & CalcReason_MouseLClick }
case CalcReason_MouseRClick : // currently I do not use MouseRClick for anyting
if MouseClickCtrlPressed then begin
print("Right Ctrl ");
end { if MouseClickCtrlPressed & CalcReason_MouseRClick }
else
if MouseClickShiftPressed then begin
print("Right Shift ");
end; { if MouseClickShiftPressed & CalcReason_MouseRClick }

end;


if currentbar = 1 then begin { initialize control arrays }
array:abc[3](""); { The basic point labels }
abc[0] = "a";
abc[1] = "b";
abc[2] = "c";
array:nums[4](""); { The way to distinguish one series of points from another, a_b_c, a1-b1-c1, etc up to a3_b3_c3 }
nums[0] = "0";
nums[1] = "1";
nums[2] = "2";
nums[3] = "3";
var: inums(4);
array:DGL_Levels[9](0); { assign input levels to array for calculations in loops }
DGL_Levels[0] = Inp_Lvl_0;
DGL_Levels[1] = Inp_Lvl_1;
DGL_Levels[2] = Inp_Lvl_2;
DGL_Levels[3] = Inp_Lvl_3;
DGL_Levels[4] = Inp_Lvl_4;
DGL_Levels[5] = Inp_Lvl_5;
DGL_Levels[6] = Inp_Lvl_6;
DGL_Levels[7] = Inp_Lvl_7;
DGL_Levels[8] = Inp_Lvl_8;

array: colorset[4](tool_red);
colorset[0] = Inp_ColorSet0 ; { for series 0, A0B0C0 }
colorset[1] = Inp_ColorSet1 ; { for series 0, A1B1C1 }
colorset[2] = Inp_ColorSet2 ; { for series 0, A2B2C2 }
colorset[3] = Inp_ColorSet3 ; { for series 0, A3B3C3 }

end; { if currentbar = 1 }

array:dd[3,4](0),tt[3,4](0),vv[3,4](0),bb[3,4](0),hh[3,4](0);
{
dd --> array - holds the date value for each point
tt --> array - hold the time value for each point
vv --> array - holds the price value for each point
bb --> array - holds the bar # for each point
hh --> array - holds the handle value for each point
}
array: fb[4,8,4](0),fv[4,8,4](0); {fb[nums,lev,proj], fv[nums,lev,proj]}
array: han[4,8](0); // holds the handle for each drawn DGL trend line
array: Pt_B_High[4](0), Pt_B_Low[4](0);
var: tft(0), fdd(0), fvv(0), ptt(0), pdd(0), pvv(0), fbb(0), pbb(0), pvv2(0);
var: ii(0), jj(0), kk(0), mm(0);
{
ii --> is the index for looping through different ABC sets
jj --> is the index for looping through each A_B_C point in a DGL set of points
kk --> is the index for looping through each DGL level 0 - 8
fvv --> used to draw individual DGL lines in loop
fbb --> used to draw individual DGL lines in loop
pvv --> used to draw individual DGL lines in loop
}
var: handl(0); // holds current handle to drawing object
var: ss(""); // holds found text string to see if it is one we want


if currentbar = 1 then begin { examine all the text strings and save some info about the ones we recognize }
handl = text_getfirst(2);
while handl >= 0 begin
ss = text_getstring(handl);
for ii = 0 to inums - 1 begin
for jj = 0 to 2 begin { look for well-formed strings }
if ss = abc[jj] + nums[ii] then begin { save the item's date, time, value and handle }
tt[jj,ii] = text_gettime(handl);
dd[jj,ii] = text_getdate(handl);
vv[jj,ii] = text_getvalue(handl);
hh[jj,ii] = handl;
end; { if ss = abc[jj] + nums[ii] }
end; { for jj = 0 to 2 loop through search for A_B_C points in a DGL }
end; { for ii = 0 to inums - 1 loop through the groups of DGLs }
handl = text_getnext(handl,2); { IMPORTANT -- infinite loop if this is missing! }
end; { while handl >= 0 }

// Now that we have searched and recorded all "a_b_c" DGL points, make sure we have all 3
// If not make dd = 0 for all points of that DGL set and set hh - the pointer
for ii = 0 to inums - 1 begin
for jj = 0 to 2 begin { look for well-formed strings }
if dd[jj,ii] = 0 then begin { a missing point has been located - remove the other points }
dd[0,ii] = 0;
dd[1,ii] = 0;
dd[2,ii] = 0;
if hh[0,ii] > 0 then text_delete(hh[0,ii]); // attempt to delete all three text objects as well
if hh[1,ii] > 0 then text_delete(hh[1,ii]);
if hh[2,ii] > 0 then text_delete(hh[2,ii]);

end; { if dd[jj,ii] = 0 }
end; { for jj = 0 to 2 loop through search for A_B_C points in a DGL }
end; { for ii = 0 to inums - 1 loop through the groups of DGLs searching for missing A_B_C points }
end; { if currentbar = 1 }


for ii = 0 to inums - 1 begin { check each series... }
for jj = 0 to 2 begin { check each point }
if time = tt[jj,ii] and date = dd[jj,ii] then begin { we've found a selected point }
If jj = 0 then vv[0,ii] = close ; // point A of DGL is always close
If jj = 1 then begin
Pt_B_High[ii] = High;
Pt_B_Low[ii] = Low;
end;
bb[jj,ii] = currentbar; { remember where we found it -- bar # is used to calculate time between points }
if jj = 2 then begin { we're at the third point, Cx }
if vv[1,ii] > vv[2,ii] then begin
vv[1,ii] = Pt_B_High[ii];
vv[2,ii] = Low;
end
else begin
vv[1,ii] = Pt_B_Low[ii];
vv[2,ii] = High;
end;
for kk = 0 to 8 begin { examine each level }
fbb = bb[1,ii] * DGL_Levels[kk] + bb[2,ii] * (1 - DGL_Levels[kk]); // bars for point using B & C
fvv = vv[1,ii] * DGL_Levels[kk] + vv[2,ii] * (1 - DGL_Levels[kk]); // price for point using B&C
pvv = TLValue(vv[0,ii],bb[0,ii],fvv,fbb,currentbar);

han[ii,kk] = TL_New(dd[0,ii],tt[0,ii],vv[0,ii],date,time,pvv);
TL_SetExtRight(han[ii,kk],TRUE);
TL_SetColor(han[ii,kk], colorset[ii]);
if kk = 1 then
TL_SetStyle(han[ii,kk],3); { Make DGL lvl 1 line dotted .......... style = 3 }
if kk = 2 then
TL_SetStyle(han[ii,kk],3); { Make DGL lvl 2 line dotted .......... style = 3 }
if kk = 3 then
TL_SetStyle(han[ii,kk],3); { Make .382 DGL line dots ..... style = 3 }
if DGL_Levels[kk] = .5 then begin // usually kk = 4 is DGL level .5
TL_SetStyle(han[ii,kk],3); { Make .5 DGL line dots ....... style = 3 }
TL_SetColor(han[ii,kk], Magenta);
{ show the related trident channel }
pvv = TLValue(vv[1,ii],bb[1,ii],fvv+vv[1,ii]-vv[0,ii],fbb+bb[1,ii]-bb[0,ii],currentbar);
handl = TL_New(dd[1,ii],tt[1,ii],vv[1,ii],date,time,pvv);
TL_SetExtRight(handl,TRUE);
tl_setstyle(handl,2);
TL_SetColor(handl, colorset[ii]);
pvv = TLValue(vv[0,ii]-(fvv-vv[2,ii]),bb[0,ii]+(bb[2,ii]-fbb),vv[2,ii],bb[2,ii],bb[1,ii]);
handl = TL_New(dd[1,ii],tt[1,ii],pvv,date,time,vv[2,ii]);
TL_SetExtRight(handl,TRUE);
tl_setstyle(handl,2);
TL_SetColor(handl, colorset[ii]);

end; { if DGL_Levels[kk] = .5 }

end; { for kk = 0 to 8 }

end; {if jj = 2 }
end; { if time=tt[jj,ii] and date = dd[jj,ii] }
end; { for jj = 0 to 2 }
end; { for ii = 0 to inums-1}
Attachments
DGL screen 7-1-2012 9-03-55 PM.png
(31.9 KiB) Downloaded 1068 times

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: DGL implementation using Mouse Events

Postby JoshM » 04 Jul 2012

Wow impressive! Thanks for sharing John. :)


Return to “User Contributed Studies and Indicator Library”