Earnings dates in GetFnData("Aux1"), how to get number of days/bars until next and from previous earnings?

Earnings dates in GetFnData("Aux1"), how to get number of days/bars until next and from previous earnings?

This is related to https://forum.amibroker.com/t/plot-earnings-dates/589
I scraped historical earnings dates, and imported them to aux1 field as 1, so my sample quote data for Apple looks like this:
Ticker Date Close Open High Low Volume Open Int. Aux1 Aux2 EOD
AAPL 5/1/2018 169.1 166.4102 169.2 165.27 535693.8 0 1 0 EOD
AAPL 4/30/2018 165.26 162.1302 167.26 161.84 424274.3 0 0 0 EOD

I would like to run an exploration but need help figuring out how to make use of GetFnData("Aux1")

  1. My first pertinent afl line with
    TodayEarnings = IIf ( GetFnData("Aux1") == 1, 1, 0);
    throws
    IIf ( GetFnData(------------------------^ .... Unsupported field
    when running an exploration
  2. How can I count today's bar to next aux1, also accounting for NO future quote or aux1 always being 0?
  3. How can I count today's bar to previous aux1, also accounting for NO past quote or aux1 always being 0?

This is the start to my afl code:

TodayEarnings = IIf ( GetFnData("Aux1") == 1, 1, 0); // If Aux1 is 1 then earnings are on today's bar
NextEarnings = 1; // in days from entry day, how to calculate today's bar to next aux1, also accounting for NO future quote/aux1?
PreviousEarnings = 1; // in days from entry day, how to calculate today's bar to previous aux1?

AddColumn ( TodayEarnings, "TodayEarnings", 1.0);
AddColumn ( NextEarnings, "NextEarnings", 1.0);
AddColumn ( PreviousEarnings, "PreviousEarnings", 1.0);

Thanks you, @fxshrat for suggesting to use Aux1 directly, w/o GetFnData.

Here's a solution that seems to do the job:

NextEarnings = IIf ( Aux1 == 1, 0, 
			   IIf ( Ref( Aux1, 1 ) == 1, 1, 
			   IIf ( Ref( Aux1, 2 ) == 1, 2, 
			   IIf ( Ref( Aux1, 3 ) == 1, 3, 
			   IIf ( Ref( Aux1, 4 ) == 1, 4, 
			   IIf ( Ref( Aux1, 5 ) == 1, 5, 
			   IIf ( Ref( Aux1, 6 ) == 1, 6, 
			   999 ))))))); // in days from entry day
PreviousEarnings = IIf ( Aux1 == 1, 0, 
				   IIf ( Ref( Aux1, -1 ) == 1, 1, 
			       IIf ( Ref( Aux1, -2 ) == 1, 2, 
			       IIf ( Ref( Aux1, -3 ) == 1, 3, 
			       IIf ( Ref( Aux1, -4 ) == 1, 4, 
			       IIf ( Ref( Aux1, -5 ) == 1, 5, 
			       IIf ( Ref( Aux1, -6 ) == 1, 6, 
			       -999 ))))))); // in days from entry day

AddColumn ( Aux1, "Aux1", 1.0);
AddColumn ( NextEarnings, "NextEarnings", 1.0);
AddColumn ( PreviousEarnings, "PreviousEarnings", 1.0);

Look in help for function :
ValueWhen and BarIndex

Hi @mdwin01,
would you please elaborate how you did you get historical earnings dates and imported them into aux1?
Thanks.

@Oscar
I wrote my proprietary script to go to a web source that contains historical earnings dates for each symbol in my database.
So as an example, if I was only interested in company A and B, based on say https://marketchameleon.com/Overview/A/Earnings/Earnings-Dates
I'd generate a file with:
A,2018-04-18,1
A,2018-01-17,1
B,2017-10-18,1
that I can later import into Amibroker, with the 1's going in as aux1 field.

Better way will be to read csv file. Make a CSV file with all data you need and read that file using afl.
Below is the link to do.

Read CSV file