Is Selected ParamDate a Valid Trading Day

Hi,

I'm looking to get the below code working for charts with a higher timeframe than Daily.

I would like AmiBroker to run a check that the selected ParamDate is an actual trading day. The below code I wrote works fine but only on Daily charts. As TimeFrameSet is only for higher timeframes I'm struggling to find a solution to get AmiBroker to access the dates for each Daily bar when on say a Weekly or Monthly chart.

Any help would be much appreciated - thanks.

// Check that selected ParamDate is an actual traing day (check over all loaded daily bars)

entryDate_dn = ParamDate("Entry Date:", Now(1), format = 0);

entryDate_dt = DateTimeConvert(2, entryDate_dn);
entryDate_str = DateTimeToStr(entryDate_dt, 4);
entryDate_search = Lookup(entryDate_dn, entryDate_dt, 0);
entryDate_IsInvalid = IsNull(entryDate_search);

errorText = WriteIf(entryDate_IsInvalid, "Invalid Entry Date!", "Entry Date OK");

GfxSetOverlayMode(mode = 0) ;
GfxSelectFont("Segoe UI", 12, 600);
GfxSetBkMode(1);
GfxSelectSolidBrush(colorLightBlue);
GfxRoundRect(10, 80, 600, 120, 20, 20);
GfxDrawText(errorText, 10, 80, 600, 120, 1 | 4 | 16 | 32);

@TrendSurfer here is a bit odd approach using OLE (with all the usual performances caveats).

I slighlty modified your code:

Version( 6.30 ); // tested version

// Check that selected ParamDate is an actual trading day (check over all loaded daily bars)

entryDate_dn = ParamDate("Entry Date:", Now(1), format = 0);

entryDate_dt = DateTimeConvert(2, entryDate_dn);
entryDate_str = DateTimeToStr(entryDate_dt, 4);
// entryDate_search = Lookup(entryDate_dn, entryDate_dt, 0);
// entryDate_IsInvalid = IsNull(entryDate_search);

// Using OLE to access quotations from the database
Ab = CreateObject("Broker.Application");
stk = ab.Stocks(Name());
qts = stk.Quotations;
// As explained in this thread
// https://forum.amibroker.com/t/retrieve-time-frame-based-quotes-using-ole-objects/7570/4
qt = qts.Item(  entryDate_str );
qtTypeOf = typeof(qt); // will return object for a valid date, number for a missing entry
// _TRACEF("QT type for date %s : %s", entryDate_str, qtTypeOf);
entryDate_IsInvalid = (qtTypeOf == "number");

errorText = entryDate_str  + " : " + WriteIf(entryDate_IsInvalid, "Invalid Entry Date!", "Entry Date OK");
GfxSetOverlayMode(mode = 0) ;
GfxSelectFont("Segoe UI", 12, 600);
GfxSetBkMode(1);
if (entryDate_isInvalid)
	GfxSelectSolidBrush(colorRed);
else
	GfxSelectSolidBrush(colorGreen);
GfxRoundRect(10, 80, 600, 120, 20, 20);
GfxDrawText(errorText, 10, 80, 600, 120, 1 | 4 | 16 | 32);

I did not test it extensively but seems to work.

3 Likes

Thanks @beppe - have not used OLE before, much appreciated.

1 Like