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

Questions about MultiCharts and user contributed studies.
User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

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

Postby TJ » 28 Oct 2009

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

tekram
Posts: 96
Joined: 26 May 2009
Has thanked: 6 times
Been thanked: 18 times

Postby tekram » 28 Oct 2009

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
Last edited by tekram on 28 Oct 2009, edited 2 times in total.

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Postby TJ » 28 Oct 2009

good solution !

many thanks.

Spaceant
Posts: 254
Joined: 30 May 2009
Has thanked: 1 time
Been thanked: 3 times

Postby Spaceant » 29 Oct 2009

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

SUPER
Posts: 646
Joined: 03 Mar 2007
Has thanked: 106 times
Been thanked: 84 times

Postby SUPER » 29 Oct 2009

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

brodnicki steven
Posts: 407
Joined: 01 Jan 2008
Been thanked: 3 times

Postby brodnicki steven » 29 Oct 2009

Great code Tekram Thanks !
It looks like, with slight changes , it could be used to find the date and time of any market event.

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Postby TJ » 29 Oct 2009

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

bowlesj3
Posts: 2180
Joined: 21 Jul 2007
Has thanked: 227 times
Been thanked: 429 times

Postby bowlesj3 » 31 Oct 2009

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 }

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Postby TJ » 31 Oct 2009

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

bowlesj3
Posts: 2180
Joined: 21 Jul 2007
Has thanked: 227 times
Been thanked: 429 times

Postby bowlesj3 » 31 Oct 2009

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.


Return to “MultiCharts”