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
How to find the date and time of a specific bar?
- TJ
- Posts: 7775
- Joined: Aug 29 2006
- Location: Global Citizen
- Has thanked: 1036 times
- Been thanked: 2233 times
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);
Last edited by tekram on Oct 28 2009, edited 2 times in total.
- TJ
- Posts: 7775
- Joined: Aug 29 2006
- Location: Global Citizen
- Has thanked: 1036 times
- Been thanked: 2233 times
good solution !
many thanks.
many thanks.
You need to use PowerLanguageEditor and look into output tabHi,
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
-
- Posts: 407
- Joined: Jan 01 2008
- Been thanked: 3 times
Great code Tekram Thanks !
It looks like, with slight changes , it could be used to find the date and time of any market event.
It looks like, with slight changes , it could be used to find the date and time of any market event.
- TJ
- Posts: 7775
- Joined: Aug 29 2006
- Location: Global Citizen
- Has thanked: 1036 times
- Been thanked: 2233 times
you can print to any one of the following locations: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
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
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.
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 }
- TJ
- Posts: 7775
- Joined: Aug 29 2006
- Location: Global Citizen
- Has thanked: 1036 times
- Been thanked: 2233 times
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
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
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.
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.