Welcome Guest, please sign in to participate in a discussion. | Search | Active Topics | |
Registered User Joined: 2/26/2005 Posts: 115
|
In the past Bruce provided a Block code to plot the Ulcer Index (see post under my name). I am unable to retrieve that code and so how can now create from scratch in the Stock Finder 4?
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
Please see Blockifying the Ulcer Index risk metric.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 2/26/2005 Posts: 115
|
Hey Bruce, I have found the post, but I copied your code and tried to run it on SF4 but it found multiple errors and I was unsuccessful. What is the fix?
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
As the only RealCode given in the topic doesn't produce any errors when used in the Code tab of a RealCode Indicator as intended, I'm going to guess that you tried using the Custom Code Block given in my Tuesday, October 02, 2007 11:39:04 AM ET post as RealCode (BTW, that Code works just fine when you follow the directions and use it as a Line and Int to Line Custom Code Block).
I suspect the fix is to use the RealCode given in my Monday, August 18, 2008 5:26:34 PM ET post in the Code tab of a RealCode Indicator. I'll reproduce it for you here:
'Ulcer Index
'# Period = UserInput.Integer = 10
Dim SumSq As Single = 0
Dim MaxValue As Single = 0
For bar1 As Integer = Period To 0 Step -1
If Price.Last(bar1) >= MaxValue Then
MaxValue = Price.Last(bar1)
Else
SumSq = SumSq+(100*(Price.Last(bar1)/MaxValue-1))^2
End If
Next
If CurrentIndex >= Period-1 Then
Plot = SumSq^.5/Period
Else
Plot = Single.NaN
End If
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 11/21/2004 Posts: 84
|
Hi Bruce (& others) -
I was looking for the Real Code for the Ulcer Index, and found your previous post on it. I did a 'Copy & Paste' into SF5, it compiled and ran fine.
My question is more with the numeric results of the formula, as they don't come very close to the value from another piece of software (that I'm in the process of phasing out of).
This is my understanding of the formula:
Ulcer Index = SquareRoot((The Sum of all R² values) / N)
Where the R is the % amount that the price is below its previous high water mark value, for each day in the series.
Not being to familar with VB, your formula looks pretty representative. The only thing I'm not sure of it that the each R value is a % and not the value of the price difference. Could you take a quick look and verify the logic in its calculation for me ? Thanks.
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
100*(Price.Last(bar1)/MaxValue-1) calculates a Percent Difference of Price.Last(bar1) from MaxValue.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 11/21/2004 Posts: 84
|
I see what you mean Bruce. As soon as I see a ratio (division) and a *100, it's an indication of percent all right. :)
But, the Real Code does not come close to yielding the expected resultant value. When plotted, it is also very erratic, in that there are many spikes, where I see a rather smooth curve of this indicator when plotted else where. Case in point:
The 21 day UI for HISMX -
FasTrack = 2.26
MetaStock = 2.58
This RealCode = 0.49
Checking 3 other funds in two time frames gives similar results. Something is not quite right, but I'll have to dig into it. Thanks for the assistance tho. StockFinder is a very neat program, what a terriffic toolbox. Cheers ............. Tom ..............
|
|
Registered User Joined: 11/21/2004 Posts: 84
|
For those interested, I found the calculation problem with the Read Code above. Here is my solution:
Change the line: Plot = SumSq ^.5 / Period
To: Plot = (SumSq / Period) ^ .5
i.e. take the sum of the squares calculated in the Do Loop in above lines (SumSq), divide by the Period, then take its Square Root.
With this change the Real Code matches perfectly with the calculations in other software.
"Hats Off" to Woden Support for providing the base code for this. StockFinder Rules !
Good Trading to All. .......... Tom ...........
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
tomham,
Thanks for figuring out the issue and posting a solution!
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Guest-1 |