Display correct daily close of foreign symbols

My base TF is 1-second but I need previous day close price of all symbols, I am using below code but it only shows correct close price for symbols which have daily close time earlier or equal to the selected symbol while calling foreign.

_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", colorGREEN  , styleNoTitle | styleLine ); 

PREVCHDFC = TimeFrameGetPrice("C",inDaily,-1);

PREVCICIC = TimeFrameGetPrice("C",inDaily,-1);

PREVCAXIS = TimeFrameGetPrice("C",inDaily,-1);

PREVCKOTK = TimeFrameGetPrice("C",inDaily,-1);

PREVCSBIN = TimeFrameGetPrice("C",inDaily,-1);

"ICICI      "  +  PREVCICIC;
"AXIS      "   + PREVCAXIS ;
"SBIN      "   + PREVCSBIN ;

For example, if I selected "HDFC" as base symbol and its closing time is 15:40:05 then it does not show correct daily close price for symbol "AXIS" which has close time of 15:41:07. So, is there a way to ignore my selected symbol closing time and display correct previous day close of all symbols irrespective of their day close times?


you are getting bad ticks from data source.

1st try and clean or resolve that. if last closing ticks are correct, then first set timeframe to daily in base symbol and then set daily in foreign symbols and retrieve Close for the symbols. Long back I tried something like this and it seemed to work.

If data is not aligned correctly, this is bound to happen.

Closing ticks are correct and I need base symbol to be on 1 second timeframe only because my complete code is based on that timeframe only and requirement of that code is previous day adjusted close price of all symbols. Is there any different approach to achieve that?

Closing time is 15:29:59 so i dont know which exchange you mean. NSE has official closing price which is last 30 min VWAP and is updated in Bhavcopy.
Some vendors end the LTP as closing tick which is incorrect while others update the last tick to the official closing price(VWAP).
After that whatever trades happen in post-market hours is at that (official) close price and session halts at 4pm (3:40pm to 4pm). In this session there are only market orders(no limit) because of fixed closing price.

So either you discard all data after 15:30 or cumulate it and create an artificial tick at 4PM for all tickers and insert it with cumulative volume or just the tick at 4PM. Then all the data for all tickers will be aligned. If for any reason there are no post-market trades then artificial 4pm will still help.

If a particular time bar is not in present in base symbol, then AB will not create it, for that there is pad and align option against the perfect base symbol. So in minute bars it can be masked but not in seconds tick bcos that is lowest exchange feed time.

That is why as an alternative you can check, in same 1-second code, first set timeframe to daily then call foreign and set them to daily. later, timeframe expand if needed and you will get last closing price of each symbol. this is what i meant in my post if you just want previous day close.

I am using truedata for real-time data, yes I am talking about adjusted close price between 3:40pm to 4pm. How can I create a artificial 4pm tick automatically that would show whatever closing price is there for that symbol before 4pm for all my symbols everyday?

Easiest way is BATCH way
Using Batch window (amibroker.com)

you can use the script way, you need to Export quotes with code in link 1 but use a single file and use #pragma maxtreads 1. Just set time to 160000 <- ie. 4PM

AmiBroker Knowledge Base » How to export quotes to separate text files per symbol

Then with 1 instance running import using OLE or as in my first line post use AB BATCH automation for import

summary: Batch setup AFL to export data, then Batch to import it 'OR' OLE.import if you are comfortable 'OR' do both export/import using script as you can store export code in APX file and run it using OLE. (OLE object can be done in JScript or python which i am use but its not limited 2 them, you can use any language that supports OLE

1 Like

I have not explored any other feature of amibroker other than simple AFLs using technical indicators, this is first time I am using these features. So, forgive me if it is a silly question, I am able to export all quotes to single file and also import it using batch. Only thing left is adding that 4pm tick in the exported file for all symbols before importing it back. Is it possible to do it with batch itself?

Currently my batch processes looks like this, please let me know if I am going in the right direction.

You need a simple echo command to file. Inside Windows batch file (.BAT)

echo "Text you want to append to the file" >> filename.txt

Then from AmiBroker batch you can call it using ExecuteAndWait command

It is important to understand that you DO NOT need to Export at all.

If you IMPORT data, the data from imported file are INSERTED to existing file at the correct position (based on timestamp). So you don't need to do Export->Import.
You just need to do IMPORT of NEW records ONLY.

Had to use export as I needed to fetch last date of trading and closing price on that day.

dt = Datetime();
SetOption( "NoDefaultColumns", True );

This worked for me for creating artificial tick for all symbols at same time i.e. 4pm with adjusted closing price.

Thanks @nsm51 and @Tomasz for all your help.

OK, but for that you only need to export LAST CLOSE, not all data.

Yes only exporting previous day close data for last 1 day for all symbols forcing date and time to be prevoius day 4pm.

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