Finding number of bar and date of event

hi all

n = 300;
SATHA = HHV(H,n);             // Highest price of the most recent 300 bars
SATHB = Ref(SATHA, -1*n);     // Highest price between 300 and 600 bars ago
SATHC = Ref(SATHA, -2*n);     // Highest price between 600 and 900 bars ago
MAXH= Max(SATHA , Max(SATHB ,SATHC )); // Highest high  
SATLA = LLV(L,n);             // lowest price of the most recent 300 bars
SATLB = Ref(SATLA, -1*n);     // lowest price between 300 and 600 bars ago
SATLC = Ref(SATLA, -2*n);     // lowest price between 600 and 900 bars ago
MINL= Min(SATLA , Min(SATLB ,SATLC )); // lowest low   

BARH= BarsSince(H==MAXH) ;            // number of bar to event hi
dtH = Ref( DateTime(), -BARH );        // date of event hi ( **** but it give me string ***)
BARL= BarsSince(L==MINL) ;             // number of bar to event lo ( it is not correct )
dtL = Ref( DateTime(), -BARL );        // date of event lo ( **** but it give me string ***)

the last 4 lines not correct

thank you

@needhelp,

This is a deliberate duplicate of find-the-highest-in-period-stages.

Creating duplicates is against forum rules!

1 Like

it is different issue

Hi all
I used AB manual (guide ).but i can not find why is not working.

BARH= BarsSince(H==MAXH) ; give me the right result

but
BARL= BarsSince(L==MINL) ; give different result

Take a look at using the BarsSinceCompare function instead of BarsSince.

this for the number of bar when the event happened.

BARH=  BarsSinceCompare( H, "==", MAXH );          // number of bar to event hi
BARL= BarsSinceCompare( L, "==", MINL );             // number of bar to event lo 

tested with excel sheet and the result is ( ok)

the reference

http://www.amibroker.com/guide/afl/barssincecompare.html

still the date ( I am working in it). I know do not hold your breath ( even I am almost giving up but I will tray to give you the full code )

thank you

I did not see it .
sorry but consider it is your solution

I need the date is giving me string

i try this one but no

dtH = DateTimeDiff( DateTime(), Ref( Datetime(), - BARH )   ) / ( 60 * 60 * 24 ) ; 

What about simply using:

dtH = Ref(DateTime(), -BARH);

it return string

StrToDateTime(Ref( DateTime(), -BARH )); // i know but it need string and what I have is array

No, it returns an array of dates, not a string. Perhaps you want to use LastValue() or ValueWhen(), something like this:

dtH = LastValue(Ref(DateTime(), -BARH));

thank you
it is the same result (retune string ) not a date

all hi this what string will lead to or how you can use it (i know you're better than me)
but (read between the lines )

date

I can't tell what your goal is, but you should not be passing a DateTime value to the StrToDateTime() function. That function converts a STRING to a DATE, not the other way around.

If you want to output a date as a column in an Exploration, just do this:

AddColumn(dtH, formatDateTime);

it is only in the exploration
can we do it in code and will show in the exploration or not ?

tested in excel sheet and both the same result

date test 2

thank you

this the full code and solved by
mradtke

thank you for your time. (mradtke)

n = 300;
SATHA = HHV(H,n);             // Highest price of the most recent 300 bars
SATHB = Ref(SATHA, -1*n);     // Highest price between 300 and 600 bars ago
SATHC = Ref(SATHA, -2*n);     // Highest price between 600 and 900 bars ago
MAXH= Max(SATHA , Max(SATHB ,SATHC )); // Highest high  
SATLA = LLV(L,n);             // lowest price of the most recent 300 bars
SATLB = Ref(SATLA, -1*n);     // lowest price between 300 and 600 bars ago
SATLC = Ref(SATLA, -2*n);     // lowest price between 600 and 900 bars ago
MINL= Min(SATLA , Min(SATLB ,SATLC )); // lowest low   
BARH=  BarsSinceCompare( H, "==", MAXH );          // number of bar to event hi
dtH_string = Ref( DateTime(), -BARH );        // date of event hi ( ****  it give me string ***)
dtH = LastValue(Ref(DateTime(), -BARH));      // date of event hi ( ****  it give me string ***) is the same as //   dtH_string = Ref( DateTime(), -BARH ); 
BARL= BarsSinceCompare( L, "==", MINL );             // number of bar to event lo 
dtL_string = Ref( DateTime(), -BARL );        // date of event lo ( ****  it give me string ***)
dtL = LastValue(Ref(DateTime(), -BARL));      // date of event lo ( ****  it give me string ***) is the same as //   dtH_string = Ref( DateTime(), -BARH ); 


//AddColumn(dtH, formatDateTime);
filter=1;


AddColumn( SATHA,"SATHA",1.2,colorDefault,colorDefault);
AddColumn( SATHB,"SATHB",1.2,colorDefault,colorDefault);
AddColumn( SATHC,"SATHC",1.2,colorDefault,colorDefault);
AddColumn( SATLA,"SATLA",1.2,colorDefault,colorDefault);
AddColumn( SATLB,"SATLB",1.2,colorDefault,colorDefault);
AddColumn( SATLC,"SATLC",1.2,colorDefault,colorDefault);
AddColumn( MAXH,"MAXH",1.2,colorDefault,colorDefault);
AddColumn( MINL,"MINL",1.2,colorDefault,colorDefault);
AddColumn( BARH,"BARH",1.2,colorDefault,colorDefault);
AddColumn( BARL,"BARL",1.2,colorDefault,colorDefault);
AddColumn( dtH_string ,"dtH_string ",1.2,colorDefault,colorDefault);
AddColumn( dtH,"dtH",formatDateTime,colorDefault,colorDefault);  // formatDateTime to get the date format
AddColumn( dtL_string ,"dtL_string ",1.2,colorDefault,colorDefault); 
AddColumn( dtL,"dtL",formatDateTime,colorDefault,colorDefault);      // formatDateTime to get the date format

also thank you alligator their help straightforward

https://forum.amibroker.com/t/adding-value-to-cell-manually/31196/13

also thank you for who help and his help straightforward

This is an appreciation for them

a hint is not necessarily true, but reminder

Go back to the dollar yen in 1998, what was the price?
Go back further. Go back to 1990, what was the price?
Now what is the price?
What are the events and influences in the year 1198 and in the year 1990
What are the events now?
if the dollar's rise higher than the yen, what does it mean economically for the two industrial countries?
Do not lose sight of China
This is far from technical indicators, but there is a saying (history repeats itself).
Be ready for the worst

2 Likes

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.