Page 1 of 1

Re-Plotting High of the Day

Posted: 24 Nov 2014
by sptrader
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 ?

Re: Erasing existing plot lines

Posted: 24 Nov 2014
by TJ
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.

Re: Erasing existing plot lines

Posted: 24 Nov 2014
by sptrader
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 ..

Re: Erasing existing plot lines

Posted: 25 Nov 2014
by JoshM
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).

Re: Erasing existing plot lines

Posted: 25 Nov 2014
by JoshM
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?

Re: Erasing existing plot lines

Posted: 25 Nov 2014
by sptrader
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..

Re: Re-Plotting High of the Day

Posted: 25 Nov 2014
by shanemcdonald
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

Re: Re-Plotting High of the Day

Posted: 26 Nov 2014
by JoshM
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;

Re: Re-Plotting High of the Day

Posted: 26 Nov 2014
by shanemcdonald
hey !

thats fantastic !
Excellent work Josh !

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

sincerely,
Shane