Page 1 of 1

How to find the date and time of a specific bar?

Posted: Oct 28 2009
by TJ
if I want to find the highest high of the previous 10 bars,
I would use highest(high, 10)

How do I find the date and time of that specific bar?
or the bar number?


TIA

Posted: Oct 28 2009
by tekram

Code: Select all

input: Lookback(10);

vars:timeofbarsago(0), dateofbarsago(0), counter(0);

value1 = highest(high, Lookback);
for counter = 0 to Lookback -1
begin
if H[counter]=value1 then
begin
timeofbarsago = time[counter];
dateofbarsago = date[counter];
end;
end;
//earliest occurence of highest high with Lookback

Print(ELDateToString(dateofbarsago)," ", timeofbarsago, " ", Value1:0:4);
edited to check currentbar high

Posted: Oct 28 2009
by TJ
good solution !

many thanks.

Posted: Oct 29 2009
by Spaceant
Hi,

I have tried to copy the code and test it, but I am not familar withthe Print syntax. Where does it print?... in a file or any other form..... as it doesn't plot anything on the chart as an indicator.

Sa

Posted: Oct 29 2009
by SUPER
Hi,

I have tried to copy the code and test it, but I am not familar withthe Print syntax. Where does it print?... in a file or any other form..... as it doesn't plot anything on the chart as an indicator.

Sa
You need to use PowerLanguageEditor and look into output tab

Posted: Oct 29 2009
by brodnicki steven
Great code Tekram Thanks !
It looks like, with slight changes , it could be used to find the date and time of any market event.

Posted: Oct 29 2009
by TJ
Hi,

I have tried to copy the code and test it, but I am not familar withthe Print syntax. Where does it print?... in a file or any other form..... as it doesn't plot anything on the chart as an indicator.

Sa
you can print to any one of the following locations:
1. output log window in PowerLanguage Editor
2. printer
3. a text file

you can see more discussions and examples here:
http://www.traderslaboratory.com/forums ... -6000.html

Posted: Oct 31 2009
by bowlesj3
Hi TJ,

I was curious about this and took a look at the Highest function itself thinking it makes sense just to modify it. Here is what I found. It calls a function called "extremes". There is another wrapper function called HighestBar which also called "extremes" and it returns the offset instead of the value. From there you can get anything by using the offset (High, date, time, RSI, BB, etc).

I copied extremes into the code below for faster reference. It appears you can run the function itself with an offset as well. To find this out you have to look up ExecOffset which It references below. It is a command that can tell you which offset the function extremes was run with.

You know, it just occured to me that I could have used this function HighestBar/LowestBar and just recently too. Cool. Helping helped.

John.

Code: Select all

{ Multiple-output function; see MULTIPLE-OUTPUT FUNCTIONS note below }

inputs:
Price( numericseries ),
Length( numericsimple ),
HiLo( numericsimple ), { pass in 1 for Highest(Bar), -1 for Lowest(Bar) }
oExtremeVal( numericref ),
oExtremeBar( numericref ) ;

variables:
MyVal( 0 ),
MyBar( 0 ) ;

MyVal = Price ;
MyBar = 0 ;

for Value1 = 1 to Length - 1
begin
if ( HiLo = 1 and Price[Value1] > MyVal )
or ( HiLo = -1 and Price[Value1] < MyVal )
then
begin
MyVal = Price[Value1] ;
MyBar = Value1 ;
end ;
end ;

oExtremeVal = MyVal ;
oExtremeBar = MyBar + ExecOffset ;

Extremes = 1 ; { function return always 1, not used; only outputs used }

Posted: Oct 31 2009
by TJ
Hi John:

WHAT A FIND !!!

Thanks for the investigative work...
Why didn't I think of it first ? LOL

I can just latch onto the function and extract the date and time.

This is brilliant !

regards
TJ

Posted: Oct 31 2009
by bowlesj3
Yah, I would say there have been some people before us who had their thinking caps on (especially considering the wrapper approach).

Note: there is an extremesFC version too with a highestFC/lowestFC and highestbarFC/lowestbarFC too. I think this version rolls the internal table by retaining the values across calls (a series function maybe). It must because the backward search would never occur because Myval is set to zero. I would have to create a detailed trace on all if statements using print statements (which show the bar number as well) to truly understand this one. Maybe someday if I have the need or am bored I might do this.

John.