Cannot access DailyOpen, DailyHigh, DailyLow from intraday

I am trying to recreate a strategy that I have running in TradeStation with Amibroker. It is an intraday VIX futures (VX) strategy. In TradeStation it uses two datastreams. Data1 is a one minute, and only the day session (8:30am-3:15pm CST). Data2 uses daily data. Part of the conflict is that when using a day session in Amibroker it truncates all datastreams. So to get around this so it matches the way TS does it, I imported a secondary daily datastream into Amibroker and just tacked on "_Daily" to the back of the symbol, and then I am using SetForeign to access this data. The problem is that it is only recognizing the closing values for each day. For the Open, High, and Low it is returning the Close. I see in the documentation that it will do this if it does not have the data for the Open, High, Low, but it DOES have the data. I can plot the "_Daily" data on a separate chart and it is there. Why would it not let me access this via the code? Here is how I am trying to do it:

SetForeign("@VX=11INN_Daily");
TimeFrameSet( inDaily ); 
SetBarsRequired( sbrAll, sbrAll );

inDailyOpen = Open;
inDailyHigh = High;
inDailyLow = Low;
inDailyClose = Close;

//inDailyOpen = Foreign( "@VX=11INN_Daily", "O" ); 
//inDailyHigh = Foreign( "@VX=11INN_Daily", "H" ); 
//inDailyLow = Foreign( "@VX=11INN_Daily", "L" ); 
//inDailyClose = Foreign( "@VX=11INN_Daily", "C" ); 

if (DailyMA_SMA_or_EMA == 0)
{
	inMAdaily = MA(Close, DailyMAfilter_lookback); 
}
else
{
	inMAdaily = EMA(Close, DailyMAfilter_lookback); 
}
RestorePriceArrays();

DailyOpen = TimeFrameExpand( inDailyOpen, inDaily);
DailyHigh = TimeFrameExpand( inDailyHigh, inDaily);
DailyLow = TimeFrameExpand( inDailyLow, inDaily);
DailyClose = TimeFrameExpand( inDailyClose, inDaily);
MAdaily = Nz(TimeFrameExpand( inMAdaily, inDaily), 100);

printf( "DailyOpen: " + NumToStr( DailyOpen ) + "\n" ); 
printf( "DailyHigh: " + NumToStr( DailyHigh ) + "\n" ); 
printf( "DailyLow: " + NumToStr( DailyLow ) + "\n" ); 
printf( "DailyClose: " + NumToStr( DailyClose ) + "\n" ); 
printf( "###### MAdaily: " + NumToStr( MAdaily ) + "\n" ); 

As you can see I also tried "Foreign" instead of a one-time SetForeign and that resulted in the same.

image

This is probably not your only problem, but you should begin by adding a TimeFrameRestore() call to match your TimeFrameSet() call. Also, did you tick the box for "Allow mixed EOD/Intraday data" in your database settings?

I thought RestorePriceArrays() also does a TimeFrameRestore(). Anyway, I added that too right before RestorePriceArrays() and nothing changed. Then I tried checking "Allow mixed EOD/Intraday data" in the database settings and all daily prints returned {Empty}.

Any other suggestions?

RestorePriceArrays() has same effect as TimeFrameRestore().
Has been discussed in the past already and is also to be found on KB.

"Allow mixed EOD/Intraday data" is for data plugins for IQFeed and eSignal only!


As for getting OHLC set fixup of SetForeign to 2.

/// possibly fixed thread version 
/// @link https://forum.amibroker.com/t/cannot-access-dailyopen-dailyhigh-dailylow-from-intraday/8594 /4
//SetBarsRequired( sbrAll, sbrAll );
DailyMAfilter_lookback = 20;
DailyMA_SMA_or_EMA = 0;

SetForeign("@VX=11INN_Daily", fixup = 2 );
TimeFrameSet( inDaily ); 

	inDailyOpen = Open;
	inDailyHigh = High;
	inDailyLow = Low;
	inDailyClose = Close;

	if (DailyMA_SMA_or_EMA == 0)
	{
		inMAdaily = MA(Close, DailyMAfilter_lookback); 
	}
	else
	{
		inMAdaily = EMA(Close, DailyMAfilter_lookback); 
	}	
RestorePriceArrays();

expandmode = expandLast;
DailyOpen = TimeFrameExpand( inDailyOpen, inDaily, expandmode);
DailyHigh = TimeFrameExpand( inDailyHigh, inDaily, expandmode);
DailyLow = TimeFrameExpand( inDailyLow, inDaily, expandmode);
DailyClose = TimeFrameExpand( inDailyClose, inDaily, expandmode);
MAdaily = TimeFrameExpand( inMAdaily, inDaily, expandmode);

printf( "DailyOpen: " + NumToStr( DailyOpen ) + "\n" ); 
printf( "DailyHigh: " + NumToStr( DailyHigh ) + "\n" ); 
printf( "DailyLow: " + NumToStr( DailyLow ) + "\n" ); 
printf( "DailyClose: " + NumToStr( DailyClose ) + "\n" ); 
printf( "###### MAdaily: " + NumToStr( MAdaily ) + "\n" );

PlotOHLC( DailyOpen, DailyHigh, DailyLow, DailyClose, "Daily", colorDefault, stylecandle );
Plot( MAdaily, "MADaily", colorRed );
2 Likes

@fxshrat , I've changed everything as you have above here. The most notable thing is fixup=2. That did make the O, H, L appear, but they are off by a day. For instance, when I click on 9/6/18, I should be getting the most recent daily values for 9/5/18, but nope, it is returning the values for 9/4/18. So odd. Why would this be?

This is being tested on a 1 min interval. When I switch to a 5min and above intervals it works correct. Weird!

If doing this then your imported EOD data does not move in 1-minute.

//...

if( Interval() == 60 )
	expandmode = expandFirst;
else
	expandmode = expandLast;
	
DailyOpen = TimeFrameExpand( inDailyOpen, inDaily, expandmode);
DailyHigh = TimeFrameExpand( inDailyHigh, inDaily, expandmode);
DailyLow = TimeFrameExpand( inDailyLow, inDaily, expandmode);
DailyClose = TimeFrameExpand( inDailyClose, inDaily, expandmode);
2 Likes

And don't you have a future leak? Because you know daily High/Low at the end of the day only.

So shouldn't you add a one bar delay inside timeframeset?

//...

if ( Interval() < inDaily)
    delay = 1;
else 
    delay = 0;

SetForeign("@VX=11INN_Daily", fixup = 2 );
TimeFrameSet( inDaily ); 

	inDailyOpen = Ref(Open,-delay);
	inDailyHigh = Ref(High,-delay);
	inDailyLow = Ref(Low,-delay);
	inDailyClose = Ref(Close,-delay);

	if (DailyMA_SMA_or_EMA == 0)
	{
		inMAdaily = Ref(MA(Close, DailyMAfilter_lookback),-delay);
	}
	else
	{
		inMAdaily = Ref(EMA(Close, DailyMAfilter_lookback),-delay); 
	}	
RestorePriceArrays();

if ( Interval() <= in1Minute )
	expandmode = expandFirst;
else
	expandmode = expandLast;
	
DailyOpen = TimeFrameExpand( inDailyOpen, inDaily, expandmode);
DailyHigh = TimeFrameExpand( inDailyHigh, inDaily, expandmode);
DailyLow = TimeFrameExpand( inDailyLow, inDaily, expandmode);
DailyClose = TimeFrameExpand( inDailyClose, inDaily, expandmode);

// ....
3 Likes

Recommended reading
http://www.amibroker.com/guide/h_timeframe.html

and comment to Foreign function
http://www.amibroker.com/f?foreign

Check your timestamps in imported data. That is very first thing to do.

Second thing is that you know daily close at the END of day, not at the start, so you may think they are "off by one day" as you say, but not, they aren't. Again this is explained in
http://www.amibroker.com/guide/h_timeframe.html

Expecting to know current day's (final) High/Low/Close at 9:30 (on session start) is expecting future leak. These data are known when session closes.

On unaligned timestamps Foreign would (CORRECTLY) only report PAST data, and would not allow to leak the future. Note that EOD record is considered as THE LAST record for the day. So any intraday record preceed EOD record.

But if you WANT TO LEAK the future (BAD idea but anyway if you want it for some reason), you can import those "_Daily" data with 00:00:00 timestamp (so they appear as they happening as very first price for the day - which is of course NOT true, but as I said - that is only when you want to LEAK the future)

1 Like