I'm trying to devise an indicator that will plot a line for each open gap from the date of the gap's close to the right hand margin of the chart--where the gap date and price will plot. When the gap gets filled the line should no longer plot.
It seems that processing multiple passes through chart bar data will be necessary but if that can be done it's not clear to me how you go about it.
Hints? Better yet, if somebody is aware of something similar I'd appreciate a point.
Thanks in advance.
Plotting gaps / multiple passes through bar data [SOLVED]
- TJ
- Posts: 7752
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1034 times
- Been thanked: 2228 times
Re: Plotting gaps / multiple passes through bar data
Hints?I'm trying to devise an indicator that will plot a line for each open gap from the date of the gap's close to the right hand margin of the chart--where the gap date and price will plot. When the gap gets filled the line should no longer plot.
It seems that processing multiple passes through chart bar data will be necessary
but if that can be done it's not clear to me how you go about it.
Hints? Better yet, if somebody is aware of something similar I'd appreciate a point.
Thanks in advance.
First step: draw a mock up.
-
- Posts: 191
- Joined: 27 Apr 2010
- Location: San Jose
- Has thanked: 67 times
- Been thanked: 10 times
Re: Plotting gaps / multiple passes through bar data
Here is what I am looking to do (attached). When a gap is filled the plot would be dropped.
- Attachments
-
- gap_plotter_mock-up.png
- (36.88 KiB) Downloaded 796 times
-
- Posts: 191
- Joined: 27 Apr 2010
- Location: San Jose
- Has thanked: 67 times
- Been thanked: 10 times
Re: Plotting gaps / multiple passes through bar data
I'm thinking that this kind of approach would work:
1. if EOD
a. draw a trend line from the bar close extended to the right
b. label it with price and date text.
c. write the value of the trend line ID and closing price to an array.
d. write the value of the price and date text ID's and--associated trend line ID--to arrays.
2. as each new bar closes, process the arrays from beginning to end.
a. if the high to low of the new bar encompasses the closing price for any day in the array
(1) delete the trend line for that day
(2) process the other arrays and delete the price and date text associated with the deleted trend line ID
b. increment the subsequent trend line and text IDs to account for the trend line(s) and text that have been removed? (not sure about this. if an existing trend line or text is deleted by code do IDs get updated or remain static? will test this)
I've only used arrays a couple of times in Easy/Power Language but conceptually this seems like it would work. If anybody sees any potential snag I'd appreciate a heads up.
Thx.
PDQ
1. if EOD
a. draw a trend line from the bar close extended to the right
b. label it with price and date text.
c. write the value of the trend line ID and closing price to an array.
d. write the value of the price and date text ID's and--associated trend line ID--to arrays.
2. as each new bar closes, process the arrays from beginning to end.
a. if the high to low of the new bar encompasses the closing price for any day in the array
(1) delete the trend line for that day
(2) process the other arrays and delete the price and date text associated with the deleted trend line ID
b. increment the subsequent trend line and text IDs to account for the trend line(s) and text that have been removed? (not sure about this. if an existing trend line or text is deleted by code do IDs get updated or remain static? will test this)
I've only used arrays a couple of times in Easy/Power Language but conceptually this seems like it would work. If anybody sees any potential snag I'd appreciate a heads up.
Thx.
PDQ
Last edited by PD Quig on 13 Oct 2013, edited 2 times in total.
- TJ
- Posts: 7752
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1034 times
- Been thanked: 2228 times
Re: Plotting gaps / multiple passes through bar data
Yes, any time you want to reference a historic data, you have to use an array (or some kind of database) to capture that critical data.
Before you start coding, you have to decide how much historical gap data you want to retain...
1. ALL of them? (some Dow/SP gaps from years ago are still not filled. ie. you will need a large database to store all the historic points.)
2. A limited look back period, eg. the past 10 days?
3. A limited data points, eg. only the previous 2 gaps? one above and one below?
Lots of planning ahead...
Before you start coding, you have to decide how much historical gap data you want to retain...
1. ALL of them? (some Dow/SP gaps from years ago are still not filled. ie. you will need a large database to store all the historic points.)
2. A limited look back period, eg. the past 10 days?
3. A limited data points, eg. only the previous 2 gaps? one above and one below?
Lots of planning ahead...
- TJ
- Posts: 7752
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1034 times
- Been thanked: 2228 times
Re: Plotting gaps / multiple passes through bar data
The drawing object IDs are assigned as the object is created. The numbers are unique and are not recycled.::
b. increment the subsequent trend line and text IDs to account for the trend line(s) and text that have been removed? (not sure about this. if an existing trend line or text is deleted by code do IDs get updated or remain static? will test this)
::
Thx.
PDQ
-
- Posts: 191
- Joined: 27 Apr 2010
- Location: San Jose
- Has thanked: 67 times
- Been thanked: 10 times
Re: Plotting gaps / multiple passes through bar data
Good to know that the trend line and text ID's remain static. That will make things easier.
At this point I'm thinking to apply the indicator to a chart that goes back one or two years only -- so the arrays would be fairly small (TF has only 14 unfilled gaps since 1/1/2013). Ultimately I could see writing the data out to a database but not now.
Thanks a lot, TJ.
At this point I'm thinking to apply the indicator to a chart that goes back one or two years only -- so the arrays would be fairly small (TF has only 14 unfilled gaps since 1/1/2013). Ultimately I could see writing the data out to a database but not now.
Thanks a lot, TJ.
-
- Posts: 191
- Joined: 27 Apr 2010
- Location: San Jose
- Has thanked: 67 times
- Been thanked: 10 times
Re: Plotting gaps / multiple passes through bar data
I got some time to work this again last night and am mostly finished. It all works except for the gap text label horizontal positioning. I'd like to have the gap label text flushed all the way to the right like you can with the horizontal line drawing tool (see attached image). There must be a way to find the right hand margin of the chart and use that to plot the text but if there is I'm not finding it.
Here's the code:
Here's the code:
Code: Select all
inputs:
Start_Date (1130101),
Session_Start_Time (0930),
Session_End_Time (1600),
Font_Size (9);
variables:
Gap_Price (0),
Line_Gap (-1),
Text_Gap (-1),
Text_Gap_str (""),
Close_Index (0),
Plot_Lines_Text (false),
x (0);
arrays:
Closing_Price_Array[] (0),
Gap_Status_Array[] (0),
Gap_Date_Array[] (0),
Gap_Text_Array[] ("");
//*****************************************************************************
// capture end of day price, date, text in arrays -- potential gaps
//*****************************************************************************
if date >= Start_Date and time = Session_End_Time and barstatus = 2 then begin
Close_Index = Close_Index + 1;
array_setmaxindex(Closing_Price_Array, Close_Index);
array_setmaxindex(Gap_Status_Array, Close_Index );
array_setmaxindex(Gap_Date_Array, Close_Index );
array_setmaxindex(Gap_Text_Array, Close_Index );
Closing_Price_Array[Close_Index] = close;
Gap_Status_Array[Close_Index] = 0;
Gap_Date_Array[Close_Index] = date;
Gap_Text_Array[Close_Index] = numtostr(close,1) + " " + eldatetostring(date);
Plot_Lines_Text = true;
end;
//*****************************************************************************
// check for gap fills
//*****************************************************************************
if date >= Start_Date and time > Session_Start_Time and time <= Session_End_Time and barstatus = 2 then begin // gaps can only be filled during the regular session
for x = 1 to Close_Index begin
if date > Gap_Date_Array[x] and
Gap_Status_Array[x] = 0 and
Closing_Price_Array[x] <= high and
Closing_Price_Array[x] >= low then begin
Gap_Status_Array[x] = 1;
Plot_Lines_Text = true;
end;
end;
end;
//*****************************************************************************
// plot gap trend lines
//*****************************************************************************
if Plot_Lines_Text then begin
for Value1 = 1 to Close_Index begin
if TL_Exist(Value1) then TL_Delete(Value1);
if Text_Exist(Value1) then Text_Delete(Value1);
if Gap_Status_Array[Value1] = 0 then begin
Line_Gap = TL_new(Gap_Date_Array[Value1],Session_End_Time,Closing_Price_Array[Value1],Gap_Date_Array[Value1],Session_End_Time,Closing_Price_Array[Value1]);
TL_SetExtRight(Line_Gap,true);
TL_setsize(Line_Gap,0.5);
TL_setstyle(Line_Gap,tool_dashed3);
TL_setcolor(Line_Gap,tool_blue);
Text_Gap = Text_new(Gap_Date_Array[Value1],Session_End_Time,Closing_Price_Array[Value1],Gap_Text_Array[Value1]);
Text_SetColor(Text_Gap,tool_blue);
Text_SetStyle(Text_Gap,0,1);
Text_SetAttribute(Text_Gap,1,false);
Text_SetSize(Text_Gap,Font_Size);
end;
end;
Plot_Lines_Text = false;
end;
- Attachments
-
- Text Horizontal Alignment -- Right.png
- (72.14 KiB) Downloaded 787 times
- TJ
- Posts: 7752
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1034 times
- Been thanked: 2228 times
Re: Plotting gaps / multiple passes through bar data
Look upI got some time to work this again last night and am mostly finished. It all works except for the gap text label horizontal positioning. I'd like to have the gap label text flushed all the way to the right like you can with the horizontal line drawing tool (see attached image). There must be a way to find the right hand margin of the chart and use that to plot the text but if there is I'm not finding it.
::[/code]
getappinfo
-
- Posts: 191
- Joined: 27 Apr 2010
- Location: San Jose
- Has thanked: 67 times
- Been thanked: 10 times
Re: Plotting gaps / multiple passes through bar data
Half way there. I get the time portion of the last bar as follows:
Text_Plot_Time = DateTime2ELTime(GetAppInfo(aiRightDispDateTime));
...and I know that aiRightDispDateTime also contains the date portion from the Wiki example:
FormatDate("MM/dd/yyyy", GetAppInfo(aiRightDispDateTime)) which = 10/20/2013 on my chart.
It must be right under my nose, but I've tried six different things and can't figure out how you can get the EL date out of GetAppInfo(aiRightDispDateTime).
Text_Plot_Time = DateTime2ELTime(GetAppInfo(aiRightDispDateTime));
...and I know that aiRightDispDateTime also contains the date portion from the Wiki example:
FormatDate("MM/dd/yyyy", GetAppInfo(aiRightDispDateTime)) which = 10/20/2013 on my chart.
It must be right under my nose, but I've tried six different things and can't figure out how you can get the EL date out of GetAppInfo(aiRightDispDateTime).
- TJ
- Posts: 7752
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1034 times
- Been thanked: 2228 times
Re: Plotting gaps / multiple passes through bar data [SOLVED]
The date is in Julian format.Half way there. I get the time portion of the last bar as follows:
Text_Plot_Time = DateTime2ELTime(GetAppInfo(aiRightDispDateTime));
...and I know that aiRightDispDateTime also contains the date portion from the Wiki example:
FormatDate("MM/dd/yyyy", GetAppInfo(aiRightDispDateTime)) which = 10/20/2013 on my chart.
It must be right under my nose, but I've tried six different things and can't figure out how you can get the EL date out of GetAppInfo(aiRightDispDateTime).
Use juliantodate to convert.
-
- Posts: 191
- Joined: 27 Apr 2010
- Location: San Jose
- Has thanked: 67 times
- Been thanked: 10 times
Re: Plotting gaps / multiple passes through bar data
I must have read your brainwaves because I finally stumbled across it and was just typing this to wave you off.
Thanks for your help on this.
Thanks for your help on this.
- TJ
- Posts: 7752
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1034 times
- Been thanked: 2228 times
Re: Plotting gaps / multiple passes through bar data
You are welcome.I must have read your brainwaves because I finally stumbled across it and was just typing this to wave you off.
Thanks for your help on this.