brandon has contributed to 19 posts out of 21199 total posts
(0.09%) in 6,698 days (0.00 posts per day).
20 Most recent posts:
Hello everyone!
I modified the sample Visual Basic code that was given to retrieve historical data via COM so that I could compute RSI on the fly from historical 5-minute bars. It would start with the first bar returned (the oldest) and calculate all the way to the last bar. I assumed a 14-period (15 data points) period for Wilder RSI.
I used the formula taken from here for Wilder RSI: http://www.stockcharts.com/education/IndicatorAnalysis/indic_RSI.html. However, my results don't seem to be returning the same RSI as sites like prophet.net and other technical analysis tools. Also, when I put in a longer timeframe for the data pulled (like 5 days), the RSI remains the same although it should be different since it is smoothed. I have pasted the code below. Maybe someone could help me out here? I am not sure what I am doing wrong!
This is my modified version of the original history.frm. I added a list box, List1, that contains ticker symbols. The code of the form is below (with comments). Most of the code is in CalcRS and hlookup_MinuteCompleted.
For whatever reason, the RSI is not changing when I give it more data (5 days instead of, say, 2) which is bizaare. I must be doing something wrong. Does anybody have any experience with this that could help me?
Option Explicit Dim WithEvents hlookup As HistoryLookup ' History COM object Dim loaded As Boolean Dim curSymbol As String Dim globSpun As Boolean Dim lAG, lAL Dim okayz As Boolean
'----------------------- ' Registers the application with IQFeed, and starts the IQConnect data service ' Also populates the HistoryType combo box with type of history requests Private Sub Form_Load() loaded = False Dim strName As String Dim strVersion As String Dim strKey As String strName = "IQFEED_DEMO" strVersion = "1" strKey = "1" loaded = IQFeedY1.RegisterClientApp(strName, strVersion, strKey) Set hlookup = New HistoryLookup Go.Enabled = False lAG = 0 lAL = 0 End Sub
Private Sub Form_Unload(icancel As Integer) Set hlookup = Nothing IQFeedY1.RemoveClientApp End Sub
'----------------------- 'Initialize COM object and make the request when user clicks on the go button. Private Sub Go_Click() Dim i As Integer If Not loaded Then Set hlookup = New HistoryLookup End If okayz = True For i = 1 To List1.ListCount ' Wait for the last request to finish While okayz = False DoEvents Wend ' List1 contains a list of ticker symbols curSymbol = List1.List(i) okayz = False hlookup.RequestMinuteHistory curSymbol, 1, 5 Next i End Sub
Private Sub hlookup_AbortedLoad(ByVal bsReason As String) MsgBox bsReason End Sub
' This function calculates the RS Private Function CalcRS(closes As Variant) Dim UpTotal, DownTotal Dim i As Integer Dim Diff Dim AvgGain, AvgLoss, RS UpTotal = 0 DownTotal = 0 ' We start at 2 since the first value is only used for reference For i = 2 To 15 Diff = closes(i) - closes(i - 1) If Diff > 0 Then ' Up Session UpTotal = UpTotal + Abs(Diff) ElseIf Diff < 0 Then ' Down Session DownTotal = DownTotal + Abs(Diff) Else ' Flat leave it the same End If Next i
' Compute "average" gain & loss AvgGain = UpTotal / 14 AvgLoss = DownTotal / 14 ' Set global variables lAG = AvgGain lAL = AvgLoss ' Return RS (AvgGain / AvgLoss) CalcRS = AvgGain / AvgLoss End Function
'----------------------- ' If minute request databars are returned then display them Private Sub hlookup_MinuteCompleted(ByVal lMinutesLoaded As Long, ByVal aTime As Variant, ByVal aOpen As Variant, ByVal aClose As Variant, ByVal aHigh As Variant, ByVal aLow As Variant, ByVal aVolume As Variant, ByVal IntVolume As Variant) Dim data As String Dim i, c, n As Integer ' Counters Dim closes(15) ' Variable holding closing prices Dim rsi ' Actual RSI computed at end from smooth RSI Dim offset As Integer Dim pGain, pLoss ' Previous gain & loss Dim srs ' Will contain smoothed RS pGain = 0 pLoss = 0 ' Set closing prices array to get first RS from CalcRS() For i = 1 To 15 closes(i) = aClose(i) Next i ' Calculate first RS and set global variables CalcRS (closes) ' Now, we start from the second closing price instead of the first offset = 2 ' For each data point, run the CalcRS function and smooth it For i = 16 To lMinutesLoaded c = 1 ' Set closes array from offset to the closing price data point we're currently at For n = offset To i closes(c) = aClose(n) c = c + 1 Next n ' Remember previous gain and loss pGain = lAG pLoss = lAL
' Set new gain/loss into lAG and lAL. This is why we saved them. CalcRS (closes) ' Now calculate the smoothed RS. srs = (((pGain * 13) + lAG) / 14) / (((pLoss * 13) + lAL) / 14) ' Increase offset so we start off with the next closing price offset = offset + 1 Next i ' Get the actual RSI value from the smoothed RS rsi = 100 - (100 / (1 + srs))
HistoryList.Text = HistoryList.Text & "RSI for " & CStr(curSymbol) & ": " + CStr(rsi) + vbCrLf ' Set this variable to TRUE so that the requesting loop knows its okay to go on okayz = True End Sub
'----------------------- ' If day request databars are returned then display them Private Sub hlookup_DayCompleted(ByVal lDaysLoaded As Long, ByVal aTime As Variant, ByVal aOpen As Variant, ByVal aClose As Variant, ByVal aHigh As Variant, ByVal aLow As Variant, ByVal aVolume As Variant) Dim data As String Dim i As Integer For i = 1 To lDaysLoaded data = data & aTime(i) & "," & aOpen(i) & "," & aClose(i) & "," & aHigh(i) & "," & aLow(i) & "," & aVolume(i) & vbCrLf Next i HistoryList.Text = data
End Sub '----------------------- ' Receives the status of the IQConnect data service ' status = 0, Then IQConnect is unavailable ' status = -1, Then IQConnect could not be loaded (Possible installation issue) Private Sub IQFeedY1_IQConnectStatus(strStatus As String) If strStatus = "-1" Then MsgBox "IQFeedY Reports an error loading IQFeed." ElseIf strStatus = "0" Then MsgBox "IQFeedY Reports IQConnect shutdown." Unload History End If End Sub
Private Sub IQFeedY1_SystemMessage(strSystemData As String) If InStr(strSystemData, "S,SERVER CONNECTED") > 0 Then Go.Enabled = True End If End Sub
Thanks!
Brandon Edited by brandon on Feb 11, 2006 at 09:24 AM
That's the bizaare thing -- I don't even use a percent or so! Perhaps I'm using usleep() too liberally? And any ideas on why it would hurt to use multiple connections?
Regards,
Brandon
When monitoring approximately 100 or so ACTIVE issues, I have quite a bottleneck; my program seems to not be capable of reading in line-by-line at nearly the speed that data is received, and the queue seems to fill up considerably. I am reading in one line at a time from the update server (port 5009) by read()ing data from the socket until a CRLF is received; after receiving a line, it parses it by the commas, creates the struct, fills in the value, and passes it to each of my threads analyzing the data.
For instance, I know that the client is receiving update lines every time a bid/ask changes (as part of the update types; one for tick, one for after hours, one for bid , one for ask, etc) and in active issues such as GOOG (where even with my normal display software it's hard to keep up with all the changes!) it causes an excessive amount of traffic.
Having said this, a couple of questions and theories:
* Is there anyway to limit this amount of data? Can you send me an update only when a tick occurs? * Would establishing multiple connections to the update server help? E.g., for every 10 symbols, have one connection? Connection 1 would monitor A, B, C, D, E, F, G, H, I, & J, connection 2 K, L, M, N, O, P, Q, R, S & T, and so forth. Could this help the problem? * Having me write a seperate program to connect to the feed (10 symbols per connection), and on a tick change (up or down) send the message down the pipe to my analysis program? This way, it's only reading tick changes as opposed to EVERYTHING.
Would any of this help? Being new to IQFeed, and not having access to the source code or knowledge of the way the backend operates, I don't know what is the best method for monitoring data. I am asking this question of the programmers of IQFeed and others who have used IQFeed to power their program with no lag.
Thanks in advance!
Brandon
When does the 'close' value in an Update/Summary message display the last trading day's close? It is 1:30 EST on Thursday and 'close' is still returning the closing price on AAPL at 80.86 (Tuesday's close price). Should it not return Wednesday's closing price of 83.90? When does it roll over?
Thanks,
Brandon
Thank you!
- Brandon
I am coding in C on the UNIX platform. I have multiple socket connections open to port 9100 through the form of multiple threads. Each thread has a connection to the server on port 9100.
I don't have any snippets to show atm, but I do know it's not any faster and I am not sure why. Have you experienced that at all?
I am positive that I am making the requests simultaneously. I have no idea why it is behaving like this.
I second this request. When I request data from the the historical server from multiple connections, I get no speed increase whatsoever. Instead, it seems that the requests are queued and delivered in what seems to be sequential order.
Is there anyway to get the data faster? I have over 1000 symbols I need to query daily. Right now it seems as if Yahoo! is faster for EOD day data than the IQ service I'm paying for!
Also, does this problem occur on port 5009 (the update server)? I am thinking of assigning 50 symbols per connection to hopefully eliminate any kind of bottlenecks that having 500 symbols updating over one socket may incur. Is this a good idea?
As a plus, 4.1 seems to be much more stable than 4.0. At least the data won't just mysteriously stop transferring :-).
Thanks,
Brandon
I have written a function to return the amount of days for which to query the historical server given a number of trading days. For instance, if today is Monday and the market has been open or is open, and you want the past two days of data, it will return 4, as it will skip over weekends. Otherwise, if the market is NOT open, it will return 5, as it will only be able to retrieve Friday and Thursday.
This has been integrated with a holiday schedule checker (MarketOpen() function) to determine whether or not the market was closed on that day (Christmas, Easter, etc).
The function is below. I ask DTN developers to please let me know if this logic is correct:
* If day is a weekend, increase the number of days to query by 1. * If the time of the CURRENT DAY is prior to the market opening (9:30 am), then increase the number of days to query by 1.
Is this correct? Please note the function below, and take a look at the TODO comments.
/* * Get the actual amount of days to query the IQConnect server for 'days' trading days. */ int GetQueryDays(int days) { struct tm l_tm; int cur_hour, cur_min, cur_day, cur_mon, cur_year, cur_wday; time_t l_time = time(NULL); int num_days = 0; int i;
if (!days) return 1;
localtime_r(&l_time, &l_tm);
cur_min = l_tm.tm_min; cur_hour = l_tm.tm_hour; cur_day = l_tm.tm_mday; cur_mon = l_tm.tm_mon; cur_year = l_tm.tm_year; cur_wday = l_tm.tm_wday;
num_days = days; i = 1;
/* First, check if we're in a trading day, and the request is only for one day. */ if (days == 1) { if (cur_wday != 0 && cur_wday != 6 && cur_hour <= 23 && cur_min <= 59) { if (cur_hour > 8) { /* TODO: > 30 may be buggy? It depends on when they roll-over for 1 minute bars. Check this later. */ if (cur_hour == 9 && cur_min > 30) return 1; /* Just one day is needed. */ } } }
while (i <= days) { if (cur_wday == 0) cur_wday = 6; else cur_wday -= 1;
if (cur_day == 1) { if (cur_mon == 0) { /* First day of January; we have to scroll-back a year. */ cur_year -= 1; cur_mon = 11; } else { cur_mon -= 1; }
cur_day = NumberOfDaysInMonth(cur_mon, cur_year); } else cur_day -= 1;
if (Market_Open(cur_mon, cur_day, cur_wday, 11, 30)) i++; else num_days++; }
/* If today is a weekend, or it's past midnight but before the market open, then add another day to the total. */ if (l_tm.tm_wday == 0 || l_tm.tm_wday == 6) num_days++; else if (l_tm.tm_hour >= 0 && l_tm.tm_hour <= 8) num_days++; else if (l_tm.tm_hour == 9 && l_tm.tm_min <= 30) { /* TODO: <= 30 may be buggy? It depends on when they roll-over for 1 minute bars. Check this later. */ num_days++; }
return num_days; }
Thanks in advance!
Brandon Edited by brandon on Jan 8, 2006 at 02:35 PM
I've noticed this with other symbols in the past as well. Is there some kind of data that we can access to determine which symbols are splitting, have split, and when? So that way we can divide by the split appropriately to adjust for it.
Just putting in my two cents!
Brandon
Do you have any plans to send this information? It would be very helpful, and wouldn't require too much on your end I do not think?
Brandon
I cannot seem to get the last price executed in after hours market trading within the summary message. For instance, with YHOO, I get this (it is 3:25 AM EST now, all is closed):
P,YHOO,F,41.5300,0.,,0,200,0,0,0.0100,8999.9998,100,100,,175,0.,18:06t,,0,41.5300,8999.9898,,,,t,N,,,,01/05/2006,,41.5300,,,,0.,0,38.3,,,,,1,,58920106.079999998,14,4,,12829610,AMEX-BSE-CSE-CHX-PSE-NMS,,,,,0,,,41.4185,,,
YHOO closed the normal trading session at 41.53 today, but according to Yahoo Finance, is up .22 to 41.75 in the after hours on the ECN.
The issue occurs with all stocks, not just YHOO.
Any idea?
Thanks,
Brandon
Steve,
Thanks for the clarification. I did not realize that I need not send the \r\n after each command. I have now corrected my program.
Brandon
To further clarify, here is what is happening (logged from a telnet session to the history server, port 9100):
> telnet localhost 9100 Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. HM,X,1,60; 2006-01-04 17:00:00,49.84,49.84,49.84,49.84,2447300,58800 2006-01-04 16:00:00,50.00,49.57,49.59,49.82,2388500,501500 2006-01-04 15:00:00,49.89,49.40,49.84,49.59,1823500,315200 2006-01-04 14:00:00,49.88,49.71,49.83,49.83,1508100,123000 2006-01-04 13:00:00,50.20,49.69,50.18,49.84,1384900,267000 2006-01-04 12:00:00,50.22,49.58,49.64,50.19,1117900,340700 2006-01-04 11:00:00,49.77,49.43,49.45,49.65,775000,474600 2006-01-04 10:00:00,49.68,49.00,49.44,49.45,297200,292900
!ENDMSG! HM,MSFT,1,60; !SYNTAX_ERROR! HT,X,1; !SYNTAX_ERROR!
... and so on ...
I have to disconnect and reconnect in order to receive a valid response to my requests.
This is IQFeed v4.1.0.0.
Thanks,
Brandon
Steve,
I am not using v4.0.0.0. I am using 4.1.0.0.
Any ideas?
When I issue a request for historical data on port 9100, it returns the data just fine, ending with the !ENDMSG! message. After the first message I am unable to retrieve anymore historical data, being told !SYNTAX ERROR! or the like. I must re-connect to the server to issue the next command.
Is there something I must put after the first request in order to retrieve more?
Thanks in advance,
Brandon
I am not referring to a particular exchange or ECN; just the last extended trade price, period. It doesn't seem to be returning the correct one. You would imagine that the field would contain the last pre-market price, and it does not. Any ideas?
Er repost? Edited by brandon on Jan 4, 2006 at 02:13 PM
I retrieved the field 'Extended trading last' for various stocks that had gapped up or down this morning (1/4) and from the after-hours market last night (1/3), and found that the last price is shown as the last trade price during normal hours. How do I get the last price traded on the ECNs?
Thanks,
Brandon
|