Welcome Guest, please sign in to participate in a discussion. | Search | Active Topics | |
Registered User Joined: 1/13/2012 Posts: 72
|
If the 20-day moving average (simple) is going up, and the price dips and forms a Swing Low, how would this be found in Stockfinder? There are PCFs in TC2000.
I have tried several methods to find Swing Low, such as ...
1) Look for 3 bars going down -> IF Price.Low < Price.MaxLow(3,1) then pass,
then
2) 3 bars going up -> IF Price.High > Price.MaxHigh(3,1) then pass
in a sequence. The results look like a 'hodge-podge'.
---------------------
There must be an easier, and clearer way.
(it would be nice to mark the entire Swing Low, if possible, OR at least mark the bottom bar)
Thanks.
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
A Swing High RealCode Condition can be written as:
'|*****************************************************************|
'|*** StockFinder RealCode Condition - Version 5.0 www.worden.com
'|*** Copy and paste this header and code into StockFinder *********
'|*** Condition:Swing High
'|******************************************************************
'# Before = UserInput.Integer = 3
'# After = UserInput.Integer = 3
If CurrentIndex >= Before AndAlso _
CurrentIndex < Price.Count - After Then
If Price.High > Price.MaxHigh(Before, 1) AndAlso _
Price.High > Price.MaxHigh(After, -After) Then
Pass
End If
Else
SetIndexInvalid
End If
While a Swing Low RealCode Condition can be written as:
'|*****************************************************************|
'|*** StockFinder RealCode Condition - Version 5.0 www.worden.com
'|*** Copy and paste this header and code into StockFinder *********
'|*** Condition:Swing Low
'|******************************************************************
'# Before = UserInput.Integer = 3
'# After = UserInput.Integer = 3
If CurrentIndex >= Before AndAlso _
CurrentIndex < Price.Count - After Then
If Price.Low < Price.MinLow(Before, 1) AndAlso _
Price.Low < Price.MinLow(After, -After) Then
Pass
End If
Else
SetIndexInvalid
End If
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 5/5/2010 Posts: 185
|
Bruce,
I know it's possible to construct an indicator from the swing high swing low conditions, but how can i write a code which checks for the last signal and keeps on until the next signal (watchlist).
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
Maybe something like the following RealCode Indicator?
Note that it should not be used for backtesting as it starts plotting the new value at the Swing High or Swing Low instead of after the Swing High or Swing Low where it is actually detected. This should not affect its use a WatchList Column however.
'|******************************************************************
'|*** StockFinder RealCode Indicator - Version 5.0 www.worden.com
'|*** Copy and paste this header and code into StockFinder *********
'|*** Indicator:Swing High/Low
'|******************************************************************
'# Before = UserInput.Integer = 3
'# After = UserInput.Integer = 3
Static Status As Single
If isFirstBar Then
Status = Single.NaN
End If
If CurrentIndex >= Before AndAlso _
CurrentIndex < Price.Count - After Then
Dim BothTest As Boolean = False
If Price.High > Price.MaxHigh(Before, 1) AndAlso _
Price.High > Price.MaxHigh(After, -After) Then
BothTest = True
Status = 1
End If
If Price.Low < Price.MinLow(Before, 1) AndAlso _
Price.Low < Price.MinLow(After, -After) Then
If BothTest = True Then
Status = 0
Else
Status = -1
End If
End If
End If
Plot = Status
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 5/5/2010 Posts: 185
|
thx Bruce!
|
|
Registered User Joined: 5/5/2010 Posts: 185
|
Bruce,
As with the code above, please do the same with a stochastic indicator crossing above and below.
thanks.
|
|
Administration
Joined: 9/30/2004 Posts: 9,187
|
Crossing above and below what?
|
|
Registered User Joined: 5/5/2010 Posts: 185
|
value = 50, my problem is with coding the output.
example, if stoch > 50 then plot = 1, signal until stoch < 50 then plot = -1 signal until.....
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
Maybe something like the following?
'|******************************************************************
'|*** StockFinder RealCode Indicator - Version 5.0 www.worden.com
'|*** Copy and paste this header and code into StockFinder *********
'|*** Indicator:Stochastic Cross
'|******************************************************************
'# Period = UserInput.Integer = 12
'# SK = UserInput.Integer = 3
Static Status As Single
If isFirstBar Then
Status = Single.NaN
End If
If Price.STOC(Period, SK) > 50 Then
Status = 1
Else If Price.STOC(Period, SK) < 50 Then
Status = -1
End If
Plot = Status
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
Really the only time you can't just use the following is when the stochastic equals 50 exactly.
'|******************************************************************
'|*** StockFinder RealCode Indicator - Version 5.0 www.worden.com
'|*** Copy and paste this header and code into StockFinder *********
'|*** Indicator:Stochastic Cross Simple
'|******************************************************************
'# Period = UserInput.Integer = 12
'# SK = UserInput.Integer = 3
If Price.STOC(Period, SK) > 50 Then
Plot = 1
Else
Plot = -1
End If
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 5/5/2010 Posts: 185
|
Thanks Bruce!
|
|
Registered User Joined: 5/5/2010 Posts: 185
|
Bruce can we amend the code dated tuesday December 15, 3:06:24 pm? I would like to add my own indicator ( indicator.value) thanks.
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
In what way to you want to include indicator.value in the code? Do you want have the results based on indicator.value instead price?
'|******************************************************************
'|*** StockFinder RealCode Indicator - Version 5.0 www.worden.com
'|*** Copy and paste this header and code into StockFinder *********
'|*** Indicator:Stochastic Cross
'|******************************************************************
'# indicator = chart.indicator
'# Period = UserInput.Integer = 12
'# SK = UserInput.Integer = 3
Static Status As Single
If isFirstBar Then
Status = Single.NaN
End If
If indicator.STOC(Period, SK) > 50 Then
Status = 1
Else If indicator.STOC(Period, SK) < 50 Then
Status = -1
End If
Plot = Status
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 5/5/2010 Posts: 185
|
after adding my indicator , i get error msg... Name ('indicator') is not declared
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
That just means your indicator isn't called "indicator" as would seem to have been suggested in your question..
See the line that says, "'# indicator = chart.indicator"?
That line would be correct if your indicator was actually called "indicator" and on the chart.
The line is normally created by dragging on dropping the the indicator into the RealCode.
You can do this by deleting the line from the RealCode, dragging and dropping your indicator into that place in the RealCode and then changing the variable name (the part between the '# and = in the line) to indicator.
RealCode for Real People: Indicators (6:05)
Writing Conditions in RealCode (10:11)
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Guest-1 |