Welcome Guest, please sign in to participate in a discussion. | Search | Active Topics | |
Registered User Joined: 10/4/2010 Posts: 11
|
I am looking to add a RealCode condition to an exisiting RealCode condition I have for a moving average crossover. What I am looking to do is to pass a condition that when price pulls back to the moving average. Example: I currently have a condition that passes when the 13 period moving average crosses up through the 28 period moving average, now I want to add to that condition a statement that also finds where price retests the 13 period moving average. Essentially If the 13 SMA crosses up through the 28 SMA And price restests the 13 SMA Then pass.
Thanks,
Zach
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
While it is theoretically possible for 13-Period Simple Moving Average to have always been above the 28-Period Simple Moving Average, this is not likely for a symbol which has been actively trading for an extended period of time. This means we probably do not need to test for the crossover and only need to test that the 13-Period Simple Moving Average was above the 28-Period Simple Moving Average during the previous bar.
The question then becomes one of how you wish to define price testing the 13-Period Simple Moving Average. Do we just require the low of teh current bar to be below the 13-Period Simple Moving Average?
'|*****************************************************************|
'|*** StockFinder RealCode Condition - Version 5.0 www.worden.com
'|*** Copy and paste this header and code into StockFinder *********
'|*** Condition:Pullback in Price
'|******************************************************************
If Price.Low < Price.AVGC(13) AndAlso _
Price.AVGC(13, 1) > Price.AVGC(28, 1) Then
Pass
End If
Do we jneed the current or closing price to be below the 13-Period Simple Moving Average?
'|*****************************************************************|
'|*** StockFinder RealCode Condition - Version 5.0 www.worden.com
'|*** Copy and paste this header and code into StockFinder *********
'|*** Condition:Pullback in Price
'|******************************************************************
If Price.Last < Price.AVGC(13) AndAlso _
Price.AVGC(13, 1) > Price.AVGC(28, 1) Then
Pass
End If
Do we also require price to be decreasing?
'|*****************************************************************|
'|*** StockFinder RealCode Condition - Version 5.0 www.worden.com
'|*** Copy and paste this header and code into StockFinder *********
'|*** Condition:Pullback in Price
'|******************************************************************
If Price.Last < Price.AVGC(13) AndAlso _
Price.Last < Price.Last(1) AndAlso _
Price.AVGC(13, 1) > Price.AVGC(28, 1) Then
Pass
End If
Or you may want something else entirely.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 10/4/2010 Posts: 11
|
This is perfect thank you.
One more aspect to include would be if price came down to test the moving average at some percent say 0.5% or is there a way you could include a specific price level above the moving average say $0.10.
Thanks for your help Bruce.
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
Change the following line:
If Price.Low < Price.AVGC(13) AndAlso _
To the following for being at or below 0.5 above the moving average:
If Price.Low <= 1.005 * Price.AVGC(13) AndAlso _
Or to the following for being at or below $0.10 above the moving average:
If Price.Low <= Price.AVGC(13) + .1 AndAlso _
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 10/4/2010 Posts: 11
|
Hey Bruce one more thing to clarify the original conditions I requested. I have a strategy that I am looking at that looks for the Short Period Moving Average crossing up through the Longer Period Moving Average and then the strategy triggers a long position when price retests the Short Period Moving Average...That is why I was including the Moving Average cross with the price retest.
I can make it work I think with what you gave me, but if you have any suggestion I would be more than happy to listen, as I am just doing a lot of trial and error ( which is fine, best way to learn ) to figure things out.
Again thanks for you time and help.
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
If the crossup does not need to have happened within a certain number of bars of its confirmation then there is absolutely no reason to test for it. If it has to have happenid within 10 bars or from 4 to 8 bars ago or something like that than we could test for it if you want.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 10/4/2010 Posts: 11
|
If you could do that for me that would be great, we could just use an arbitrary lookback of 10 bars.
Thanks again for your time Bruce, I appreciate your help.
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
You indicated the results were perfect, but did not indicate which RealCode you ended up using. I'll modify the first RealCode Condition given as an example. Modifications to the other RealCode Conditions would be similar.
'|*****************************************************************|
'|*** StockFinder RealCode Condition - Version 5.0 www.worden.com
'|*** Copy and paste this header and code into StockFinder *********
'|*** Condition:Pullback in Price
'|******************************************************************
Static Since As Single
If isFirstBar Then
Since = Single.NaN
End If
If Price.AVGC(13) > Price.AVGC(28) AndAlso _
Price.AVGC(13, 1) <= Price.AVGC(28) Then
Since = 0
End If
If Since <= 10 AndAlso _
Price.Low < Price.AVGC(13) AndAlso _
Price.AVGC(13, 1) > Price.AVGC(28, 1) Then
Pass
End If
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 10/4/2010 Posts: 11
|
Thanks again Bruce, I didn't have a chance to test those yet but they appeared to be what I was looking for when I stated they were perfect. Any help you provide for me will eventually get me on the right path, like I said this is all trial and error for me.
Thanks again,
Zach
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
You're welcome.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Guest-1 |