Re-Plotting High of the Day

Studies that have been contributed to the community by other users. If you’ve got something useful to share, that’s great!
sptrader
Posts: 710
Joined: 09 Apr 2010
Location: Colorado
Has thanked: 468 times
Been thanked: 261 times
Contact:

Re-Plotting High of the Day

Postby sptrader » 24 Nov 2014

Not being a programmer, I came across a situation that I can't figure out..
I have a study that plots from the times 0100 to 0700, AFTER 0700, I want to remove the old study and replace it with a new one...
How can I turn the "status off " of a study or erase its previous plot completely ??
Would trendlines be a better way ?

User avatar
TJ
Posts: 7210
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 991 times
Been thanked: 2052 times

Re: Erasing existing plot lines

Postby TJ » 24 Nov 2014

Not being a programmer, I came across a situation that I can't figure out..
I have a study that plots from the times 0100 to 0700, AFTER 0700, I want to remove the old study and replace it with a new one...
How can I turn the "status off " of a study or erase its previous plot completely ??
Would trendlines be a better way ?
It depends.

If it is a straight line, a Trendline drawing object might be easier.

Otherwise you can use a loop to re-plot everything in the past.

sptrader
Posts: 710
Joined: 09 Apr 2010
Location: Colorado
Has thanked: 468 times
Been thanked: 261 times
Contact:

Re: Erasing existing plot lines

Postby sptrader » 24 Nov 2014

Yes, TJ, a straight line..
Basically, I'm trying to capture the "developing" high and low of a session, then, when the session is over and the high and low has been determined.. erase the developing high and low ...and replace it with the final high and low of the session.
Thanks TJ ..

User avatar
JoshM
Posts: 2099
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1526 times
Been thanked: 1502 times
Contact:

Re: Erasing existing plot lines

Postby JoshM » 25 Nov 2014

How can I turn the "status off " of a study or erase its previous plot completely ??
Would trendlines be a better way ?
Indicator lines cannot be turned off, Henry said here so something like `NoPlot()` will not help.

You can use Abort to turn off the study, but this would require that you manually re-enable the indicator each time it has been turned off (which can become a pain if you have a lot of charts).

User avatar
JoshM
Posts: 2099
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1526 times
Been thanked: 1502 times
Contact:

Re: Erasing existing plot lines

Postby JoshM » 25 Nov 2014

Basically, I'm trying to capture the "developing" high and low of a session, then, when the session is over and the high and low has been determined.. erase the developing high and low ...and replace it with the final high and low of the session.
One way to do that is with a Plot that displays the developing high (or low) and is replaced with the final high (or low) when the session has ended (with a loop, like TJ said).

For example:

Code: Select all

Variables:
highOfSession(0),
sessionEndingTime(180000), // 18:00:00
x(0);

if (BarStatus(1) = 2) then begin

highOfSession = MaxList(highOfSession, High);

if (Time_s < sessionEndingTime) then
Plot1(highOfSession);

if (Time_s[1] < sessionEndingTime and
Time_s >= sessionEndingTime) then begin

for x = 100 downto 0 begin

if (Date[x] = Date) then
Plot1[x](highOfSession);

end;

highOfSession = 0;

end;

end;
That code gives the following chart when the high is still developing (i.e., before 18:00 hour):

Image

When the session has ended (after 18:00 in the code example), the plot becomes:

Image

Is this what you meant?
Attachments
scr.25-11-2014 11.07.31.png
scr.25-11-2014 11.07.31.png (5.94 KiB) Viewed 1952 times
scr.25-11-2014 11.07.09.png
scr.25-11-2014 11.07.09.png (6.25 KiB) Viewed 1941 times

sptrader
Posts: 710
Joined: 09 Apr 2010
Location: Colorado
Has thanked: 468 times
Been thanked: 261 times
Contact:

Re: Erasing existing plot lines

Postby sptrader » 25 Nov 2014

JoshM: Yes, that is EXACTLY what I meant, thanks so much for the very "elegant" solution !!
You saved me many hours of trial and error, figuring that out..

shanemcdonald
Posts: 196
Joined: 08 Aug 2012
Has thanked: 41 times
Been thanked: 41 times

Re: Re-Plotting High of the Day

Postby shanemcdonald » 25 Nov 2014

josh

could that be used to plot OHLC of previous day based on a certain session instead of relying on the session template under instrument formatting ?
I would like to use a regular globex session for the charting, but show the OHLC of pit session for crude.
09:00 - 14:30

could your code be used to do that ?

shane

User avatar
JoshM
Posts: 2099
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1526 times
Been thanked: 1502 times
Contact:

Re: Re-Plotting High of the Day

Postby JoshM » 26 Nov 2014

could that be used to plot OHLC of previous day based on a certain session instead of relying on the session template under instrument formatting ?
I would like to use a regular globex session for the charting, but show the OHLC of pit session for crude.
09:00 - 14:30
Like this?

Image

Here the previous day OHLC of the pit session are plotted as soon as the new pit session begins (see the vertical lines that highlight the pit sessions).

Code: Select all

Inputs:
SessionStart(900),
SessionEnd(1430);

Variables:
highOfPrevSession(0),
lowOfPrevSession(0),
closeOfPrevSession(0),
openOfPrevSession(0),
highThisSession(0),
lowThisSession(0),
closeThisSession(0),
openThisSession(0),
startTime(SessionStart * 100),
endTime(SessionEnd * 100);

if (BarStatus(1) = 2) then begin

// Reset variables
if (Time_s[1] < startTime) and
(Time_s >= startTime) then begin

highOfPrevSession = lowThisSession;
lowOfPrevSession = highThisSession;
openOfPrevSession = openThisSession;
closeOfPrevSession = closeThisSession;

lowThisSession = 9999;
highThisSession = 0;

end;

if (Time_s[1] < startTime) and (Time_s >= startTime) then
openThisSession = Open;

if (Time_s[1] < endTime) and (Time_s >= endTime) then
closeThisSession = Close;

// Only collect high and low during custom
// session; only works when this session doesn't
// span midnight
if (Time_s >= startTime) and
(Time_s <= endTime) then begin

highThisSession = MaxList(highThisSession, High);
lowThisSession = MinList(lowThisSession, Low);

end;

Plot1(highOfPrevSession, "High");
Plot2(lowOfPrevSession, "Low");
Plot3(openOfPrevSession, "Open");
Plot4(closeOfPrevSession, "Close");
end;
Attachments
previousPitSessionOHLC.pla
(5.65 KiB) Downloaded 484 times
scr.26-11-2014 11.06.11.png
scr.26-11-2014 11.06.11.png (13.67 KiB) Viewed 1912 times

shanemcdonald
Posts: 196
Joined: 08 Aug 2012
Has thanked: 41 times
Been thanked: 41 times

Re: Re-Plotting High of the Day

Postby shanemcdonald » 26 Nov 2014

hey !

thats fantastic !
Excellent work Josh !

Thank you for your efforts, this is a great piece of coding.

sincerely,
Shane


Return to “User Contributed Studies and Indicator Library”