Welcome Guest, please sign in to participate in a discussion. | Search | Active Topics | |
Registered User Joined: 3/12/2005 Posts: 123
|
If I wanted to create a condition that identifies "today is the second consecutive day in which price has not traded above the previous day’s close", would I have to create it in realcode? If so, any help creating it would be greatly appreciated. Thanks.
|
|
Administration
Joined: 9/30/2004 Posts: 9,187
|
On a Daily chart, create a RealCode condition using the following formula:
If price.high < price.Close(1) then pass
Then right click on the condition and select Edit. Set it to passing 2 of the last 2 bars.
|
|
Registered User Joined: 3/12/2005 Posts: 123
|
StockGuy,
Thank you, I'll give it a try. How would you code consecutive higher or lower closes? For example, 5 higher consecutive closes. Thnaks again.
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
flan4,
A higher Close would be:
If Price.Last > Price.Last(1) Then Pass
While a lower Close would be:
If Price.Last < Price.Last(1) Then Pass
In both cases, you could set it to passing 5 of the last 5 bars to create a version that checks for five consecutive instances.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 3/12/2005 Posts: 123
|
Thanks Bruce
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
flan4,
You're welcome. Our pleasure.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 3/12/2005 Posts: 123
|
Bruce,
In the spirit of learning, in the first phase of creating my condition, and after naming my new condition, the following "header" came up before i copied and pasted the above provided code:
'|*****************************************************************|
'|*** StockFinder RealCode Condition - Version 5.0 www.worden.com
'|*** Copy and paste this header and code into StockFinder *********
'|*** Condition:Today 2nd consecutive day Price not traded above previous day’s close
'|*** Example: if price.percentChange > 1 then pass
'|******************************************************************
The 3rd line is what I named the condition. What is the purpose of the 4th line, "example"? Is that a necessary line for my code to work? What if I deleted it, would it matter?
Do I need such headers to create a realcode? I.e. what if I deleted the entire header?
Does it matter on which line I copy my code?
Thanks
|
|
Administration
Joined: 9/18/2004 Posts: 3,522
|
You don't need the headers at all, they're there in case you want to copy/paste them somewhere else. They can be removed if you do not want them at all.
Ken Gilb (Kuf) Chief Software Engineer - Worden Brothers Inc. Try/Catch - My RealCode Blog
|
|
Registered User Joined: 3/12/2005 Posts: 123
|
Regarding 5 consecutive closes above, let's say you set up a scan that has you selling short on the close of the 5th consecutive higher close, and you're buying-to-cover on the following day's close, will stockfinder get confused or create errors when you have a stretch of 11 consecutive higher closes? I've been working with customer service regarding some odd results (when I drag "trade signals" to the chart, the trade signals are plotted incorrectly). In other words, do you have to add any code, or do anything, to account for "overlap"? Hope this makes sense. Thanks.
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
A Condition to check for something happening 5 consecutive Bars will also be met when that same something has happened on 11 consecutive Bars as something that has met a Condition for 11 out of 11 Bars has also met that same Condition for 5 out 5 Bars.
If you want a Rule to return True for exactly 5 consecutive Bars, then you would need to check for the Condition being True for 5 out of the last 5 Bars but not True 5-Bars Ago. It is probably easier to manually do this in your RealCode than to use the x of y Bars feature built into RealCode Conditions.
'|*****************************************************************|
'|*** StockFinder RealCode Condition - Version 5.0 www.worden.com
'|*** Copy and paste this header and code into StockFinder *********
'|*** Condition:Up Exactly 5 Bars
'|******************************************************************
Static Count As Integer
If isFirstBar Then
Count = 0
Else If Price.Last > Price.Last(1) Then
Count += 1
Else
Count = 0
End If
If Count = 5 Then Pass
This wouldn't reset because of any Trades happening within BackScanner however (and I would not have suggestions that would do so that do not pretty much require recreating the entire BackScan within your RealCode).
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 3/12/2005 Posts: 123
|
Thanks Bruce.
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
You're welcome.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 3/12/2005 Posts: 123
|
Bruce,
I've been trying to create a backscan that would buy the first down close after a string of consecutive up closes, but have been unsuccessful. I would like to use the condition you created:
Static Count As Integer
If isFirstBar Then
Count = 0
Else If Price.Last > Price.Last(1) Then
Count += 1
Else
Count = 0
End If
If Count = 5 Then Pass
Typically, one would create a combo condition and set the y of the x of y bar 1 day greater for this type of test?
Thanks
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
Setting the Up Exactly 5 Bars RealCode Condition to Passing 1 of the Last 2 and something like:
If Price.Last < Price.Last(1) Then Pass
To Passing 1 of the Last 1 before Dragging and Dropping them onto each other to create a Combo Condition certainly seems to work for me.
I get Trades in BackScanner and they seem to correspond correctly with the Chart.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 3/12/2005 Posts: 123
|
Thanks Bruce, they seem to correspond correctly for me too!
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
You're welcome.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Guest-1 |