Join the 80,000 other DTN customers who enjoy the fastest, most reliable data available. There is no better value than DTN!

(Move your cursor to this area to pause scrolling)




"I am keeping IQFeed, much better reliabilty than *******. I may refer a few other people in the office to switch as well." - Comment from Don
"Thanks for the great product and support. During this week of high volume trading, my QuoteTracker + IQ Feed setup never missed a beat. Also, thanks for your swiftness in responding to data issues. I was on ******* for a few years before I made the switch over early this year, and wish I had done it a long time ago." - Comment from Ken
"Very impressed with the quality of your feed - ******* is a real donkey in comparison." - Comment from A.C. via Email
"I've been using IQFeed 4 in a multi-threaded situation for the last week or two on 2600 symbols or so with 100 simultaneous daily charts, and I have had 100% responsiveness." - Comment from Scott
"I was on the phone with a friend who uses CQG and right after the Fed announcement, CQG was as much as 30 seconds behind DTN.IQ. Some quotes were off by as much as 15-18 cents. Your feed never missed a beat." - Comment from Roger
"DTN has never given me problems. It is incredibly stable. In fact I've occasionally lost the data feed from Interactive Brokers, but still been able to trade because I'm getting good data from DTN." - Comment from Leighton
"I have been using IQFeed now for a few years in MultiCharts and I have zero complaints. Very, very rare to have any data hiccups or anything at all go wrong." - Comment from Public Forum
"I like you guys better than *******...much more stable and a whole lot fewer issues." - Comment from Philip
"I've been using Neoticker RT with IQFeed for two months, and I'm very happy with both of the products (I've had IQFeed for two years with very few complaints). The service from both companies is exceptional." - Comment from Public Forum
"If you are serious about your trading I would not rely on IB data for serious daytrading. Took me a while to justify the cost of IQ Feed and in the end, it's just a 2 point stop on ES. Better safe than sorry" - Comment from Public Forum
Home  Search  Register  Login  Recent Posts

Information on DTN's Industries:
DTN Oil & Gas | DTN Trading | DTN Agriculture | DTN Weather
Follow DTNMarkets on Twitter
DTN.IQ/IQFeed on Twitter
DTN News and Analysis on Twitter
»Forums Index »Archive (2017 and earlier) »IQFeed Developer Support »VB Code to Compute RSI -- What's wrong?
Author Topic: VB Code to Compute RSI -- What's wrong? (2 messages, Page 1 of 1)

brandon
-Interested User-
Posts: 19
Joined: Jan 4, 2006


Posted: Feb 11, 2006 09:23 AM          Msg. 1 of 2
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

nsolot
-DTN Guru-
Posts: 273
Joined: Sep 4, 2004


Posted: Feb 11, 2006 09:39 AM          Msg. 2 of 2
Sorry I can't help with your code.

You might take a look at

http://www.modulusfe.com/tasdk/vb.asp

I've used the C++ version and it might save you a lot of time/headaches.
 

 

Time: Sun May 5, 2024 4:26 PM CFBB v1.2.0 9 ms.
© AderSoftware 2002-2003