Welcome Guest, please sign in to participate in a discussion. | Search | Active Topics | |
Registered User Joined: 12/13/2006 Posts: 7
|
Using code blocks, how would I test for the following:
1) a close less than the close 4 bars ago and
2) if and only if condition 1 is met, the bar that fulfills condition 1, is followed by 10 consecutive bars in which the close is higher than the close of the bar 4 periods ago and
3) if and only if condition 2 is met, then counting from the last day the fulfills condition 2 (that is , the 10th consecutive bar with a close higher than the close 4 bars ago), there are 20 bars, which do not have to be consecutive, in which the close is greater or equal to the high 2 bars ago.
The output should be a 1 or other marker when the all 3 conditions are met. There need not be any plot for bars for which all three conditions have not been met.
End post
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
If you have not done so already, you may wish to review at least one of the following before attempting to create your own Code Blocks:
Hello World! Writing Code Blocks for SnapSheets in Visual Basic.NET Creating a True Range Block
Start by creating a Custom Code Block as T/F Line to Line. Delete everything in the Code Block Editor and replace it with the following (please keep in mind I'm not a programmer):
<WBIGuid("6dd94734-c0ec-40b6-8280-fcfc50617aee"),FriendlyName("TF to 10")> _ Public Class TF_to_10 inherits BaseTemplateDLBooltoDLS Public Overrides Sub calculate() For bar As Integer = 0 To InputCount-1 If InputValue(bar) AddToOutput(InputDate(bar),1) Else AddToOutput(InputDate(bar),0) End If Next End Sub End Class
It takes a Date & TrueFalse Series as Input. It outputs 1 if the Input is True and 0 if the Input is False.
Then create a Custom Code Block as Bar, T/F Line to Line. Delete everything in the Code Block Editor and replace it with the following (please keep in mind I'm not a programmer):
<WBIGuid("e827c772-d66a-412f-acea-e71f6120cbea"),FriendlyName("BEL Value When Last True")> _ Public Class BEL_Value_When_Last_True inherits BaseTemplateDBSAndDLBToDLS Public Overrides Sub calculate() Dim first As Integer = System.Math.Max(Input1FirstActualIndex, Input2FirstActualIndex) Dim last As Integer = System.Math.Min(Input1LastActualIndex, Input2LastActualIndex) If last >= first Dim skip As Integer = 0 Dim value As Single For bar As Integer = first To last If Input2Value(bar) skip = 1 value = Input1Last(bar) End If If skip AddToOutput(InputDate(bar),value) End If Next End If End Sub End Class
It takes a Date & Number Series as Input1 (actually a Date & Bar Series, but it doesn't use the extra data) and a Date & TrueFalse Series as Input2. It only calculates for Dates where Input1 and Input2 both exist starting with the first time the Date & TrueFalse Series returns True. The Block outputs the Value of Input1 the last time Input2 was True.
Then save the attached .plot file in the following folder (please do so only after successfully creating the above Custom Code Block):
\My Documents\My SnapSheets\Tool Parts\Chart
You can add it to any SnapSheet using the ADD STUDY button and then selecting Add Study | My Computer.Attachments: sjmultra.plot - 6 KB, downloaded 580 time(s).
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 12/13/2006 Posts: 7
|
Thank you for your assistance. I have viewed the videos you recommend. What they don't cover are commands such as "Public Overrides Sub Calculate" or what is the differnece between a "sub" and a "class" or how to use "skip" or other functions/commands in the code you prepaared.
How would I go about learning more about these and other available commands?
Thanks you
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
We don't offer support for learning Visual Basic (and I'm not a programmer in any case). There are numerous books and free tutorials on the internet on this subject however (You might wish to try an internet search).
Fortunately, you will not normally need to worry about most of this however. When you create a Custom Code Block using Create Code Block, selecting a Code Block Type will create a template containing what you need to integrate your code into Blocks. It will indicate where to include your own code.
All of the references you asked about with the exception of skip fall into the category of being included as part of this template. In this case, skip is actually a variable that is assigned a value.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 12/13/2006 Posts: 7
|
When you input a bar, what is the inputvalue of the bar? Is it the close, high, average value, etc.?
Thanks
|
|
Administration
Joined: 9/30/2004 Posts: 9,187
|
That depends on what you're putting the bar data into. If the block accepts bar data then the whole bar is passed through. If the block only accepts a number, then the Last (Close) value is passed into the block. You can change this by putting one of these blocks between the bar data output and the number input:
Bar Open (First) Bar High Bar Low Bar Close (Last)
|
|
Guest-1 |