Welcome Guest, please sign in to participate in a discussion. | Search | Active Topics | |
Registered User Joined: 6/16/2005 Posts: 10
|
New to Blocks and want to scan for stocks whose 10 period ma of Historical Volatility is less than 30% of their 40 period ma of HT. Can you help, pls? Thanks, rb
|
|
Administration
Joined: 9/30/2004 Posts: 9,187
|
We'll have somethign for you today or tomorrow rpb.
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
rpb, Please start by creating the following Custom Code Block as Line and Int to Line (Copy and Paste seems to work for this in Firefox, but not in Internet Explorer):
Historical Volatility:
Delete everything in the Code Block Editor and replace it with the following (please keep in mind I am not a programmer):
<WBIGuid("33bc02bb-d1b4-4be9-b510-0074dd58ac02"),FriendlyName("Historical Volatility")> _ Public Class Historical_Volatility Inherits BaseTemplateDLStoDLSPeriod Public Overrides Sub calculate() If ParameterValue <= InputCount And ParameterValue >= 2 Dim sumofsqr As Double = 0 Dim PercSqrDays As Double = 100 * 256 ^ .5 For bar As Integer = 1 To ParameterValue-1 sumofsqr += System.Math.Log(InputValue(bar)/InputValue(bar-1))^2 Next AddToOutput(InputDate(ParameterValue-1),PercSqrDays*((sumofsqr-(System.Math.Log(InputValue(ParameterValue-1)/InputValue(0))^2)/(ParameterValue-1))/(ParameterValue-1))^.5) If ParameterValue < InputCount For bar As Integer = ParameterValue To InputCount-1 sumofsqr += System.Math.Log(InputValue(bar)/InputValue(bar-1))^2 - System.Math.Log(InputValue(bar+1-ParameterValue)/InputValue(bar-ParameterValue))^2 AddToOutput(InputDate(bar),PercSqrDays*((sumofsqr-(System.Math.Log(InputValue(bar)/InputValue(bar+1-ParameterValue))^2)/(ParameterValue-1))/(ParameterValue-1))^.5) Next End If End If End Sub End Class
A slightly different version of this Custom Code Block is contained in Historic Volatility (HV) Code Block. The main difference is the Custom Code Block in this topic uses a Standard Deviation of the Period minus one while the older Custom Code Block uses a Standard Deviation of the Period. There does not appear to be universal agreement on which to use (or the exact formula for that matter).
Please download the attached .scond file to:
\My Documents\Blocks Files\Tool Parts\Strategy Conditions
Once downloaded, you should be able to select Add Condition | My Computer when adding a Strategy Condition to access it.
We are still working on correctly annualizing Historical Volatility using the number of Bars in a year for the selected Time Frame (the Custom Code Block provided is only correct for a 1 Day Time Frame). This should not make a difference in this particular Strategy Condition however because the factor would be applied equally throughout the Block Diagram. While the numbers would be different, the relationships between the Moving Averages would remain the same.Attachments: HV vs HV.scond - 6 KB, downloaded 714 time(s).
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 6/16/2005 Posts: 10
|
Bruce, thanks for your work on this. Question, after I paste the 15 lines above into the Code Block Editor, what do I do? When I try to save, I get a popup "Unhandled Exceptions" with 12 lines of info that I am unble to copy and paste.
Rich
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
rpb, I do not receive any error messages when compiling or saving the provided code.
Please try replacing everything in the Code Block with all 20 lines of code provided. It should pretty much look the same in the Code Block Editor as it does in the forums. I've seen it get squashed into a single line when using Internet Explorer, so make sure you are using Firefox as suggested above.
When you select Compile, you should receive a Compile Success message in the error section of the Code Block Editor. Please provide any error messages if this is not the case.
You will hopefully not receive any error messages when saving if you verify all of the above first.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 6/16/2005 Posts: 10
|
Bruce, I did as you instructed and when I hit Compile got the following error message (I tried reentering everything 4 or 5 times with no luck) "Unhandled Exception:Object reference not set to an instance of an object." Object reference not set to an instance of an object: at WBI.CommonControlCodeEditor.compileOK() at WBI.CommonControlCodeEditor.Button1_Click(Object sender, EventArgs e) at System.Windows.Forms.Control.OnClick(EventArgs e) at System.Windows.Forms.Button.OnClick(EventArgs e) at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) at System.Windows.Forms.Control.WmMouseUp(Message&m, MouseButtons button, Int32 clicks) at System.Windows.Forms.Control.WndProc(Message&m) at System.Windows.Forms.ButtonBase.WndProc(Message&m) at System.Windows.Forms.Button.WndProc(Message&m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&m) at System.Windows.Forms.Control.ControlNativeWindow.Callback(IntPtr hWnd.Int32 msg.IntPtr wparam.IntPtr lparam) Thanks, rpb
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
rpb, I do not know why this would be happening. Please contact technical support.
All e-mail communication sent to support@worden.com during business hours (Monday through Friday 9AM-11PM and Saturday and Sunday 9AM-3PM ET) should be answered within 20 minutes of arrival. For an even quicker response to tech support questions, we recommend calling our voice line at (919) 408-0542 (there is no phone support on Sundays, some Market Holidays or after 9PM ET on weekdays).
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 6/16/2005 Posts: 10
|
Bruce, I spoke with Mark yesterday and he helped solve my problem. I followed your other instructions and scanned the SP500 and all US items watchlists and got no hits. Any suggestions? Thanks for your help.
rpb
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
rpb, The restriction is fairly restrictive, but AV is currently meeting the condition in the Standard and Poors 500 Stocks Watchlist and over 100 symbols meet the condition when I use the All US Items Watchlist.
If you have not added any other Strategy Conditions, you will want to use the Scan Only option.
- Select Strategy | Conditions. - Check Scan Only. - Select Test Strategy for Entire Watchlist. - Select Strategy | By Date. - Move the Date Pointer to the current Date.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 6/16/2005 Posts: 10
|
I have run the scan 4 times on All US Items. The first time a watchlist came up after the scan for 2 or 3 seconds and disappeared. After that nothing. rpb
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
rpb, It takes some time for this to calculate for All US Items on my computer. I've attached a Workspace with everything set up. All you should need to do if you have correctly created the Custom Code Block is select Test Strategy for Entire Watchlist. A percentage should be displayed during the calculation and you should be able to view which symbols meet the Condition for a specific date by moving the Date Pointer.
Please save the attached .bWorks file to the following folder (it requires the Custom Code Block from the earlier post):
\My Documents\Blocks Files\Workspaces
You can then open the Workspace via your FILE menu (Open Workspace then My Computer).Attachments: rpb23423.bWorks - 58 KB, downloaded 732 time(s).
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Guest-1 |