Welcome Guest, please sign in to participate in a discussion. | Search | Active Topics | |
Registered User Joined: 7/28/2006 Posts: 36
|
Hi --
I am trying to create an indicator that increases the cumulative total to plot by a long term stoc value when a short term stoc is > 80 and decreases the plot by the same amount when the short term stoc is < 20.
This is the code I have:
'# Cumulative
Dim x As Single
If isFirstBar Then
x = 0
end if
If Price.STOC(10, 2) > 80 Then
x += Price.STOC(200, 70)
End If
If Price.STOC(10, 2) < 20 Then
x -= Price.STOC(200, 70)
End If
Plot = x
But the plot does not accumulate. From the forums, I thought that changing "Dim" to "Static" would fix the problem, but all that does is make the plot vanish.
I would very much appreciate some help.
jhilton
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
I think the problem is that you are attempting to add or subtract Price.STOC(200, 70) to x before Price.STOC(200, 70) exists. You might want to try something like the following instead:
'# Cumulative
Static x As Single
If CurrentIndex >= 270 Then
If Price.STOC(10, 2) > 80 Then
x += Price.STOC(200, 70)
End If
If Price.STOC(10, 2) < 20 Then
x -= Price.STOC(200, 70)
End If
Plot = x
Else If isFirstBar Then
x = 0
Plot = Single.NaN
Else
Plot = Single.NaN
End If
Another thing to check is if Price.STOC(10, 2) and Price.STOC(200, 70) mean what you intend. The 2 and 70 are Bars Ago parameters.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 7/28/2006 Posts: 36
|
I appreciate the information. I see that I have my thinking completely screwed up. I mistakenly assumed that the parameters represented the stoc values as they appear in TC.
What I really need then is an SF Real Code template for translating the cumulative indicator settings in TC into SF.
Can you help me with that, using, say, stoc10.2 and stoc200.70? Or can you set up the template to allow the parameters to vary?
jhilton
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
Sorry, I was wrong (I misinterpreted the automcomplete). The parameters do in fact match up with what is used in TeleChart (Period, %K, Bars Ago).
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 7/28/2006 Posts: 36
|
I just tried it & it's exactly what I want.
Thank you very much.
jhilton
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
You're welcome.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 12/31/2005 Posts: 2,499
|
QUOTE (Bruce_L) I think the problem is that you are attempting to add or subtract Price.STOC(200, 70) to x before Price.STOC(200, 70) exists. You might want to try something like the following instead:
'# Cumulative
Static x As Single
If CurrentIndex >= 270 Then
If Price.STOC(10, 2) > 80 Then
x += Price.STOC(200, 70)
End If
If Price.STOC(10, 2) < 20 Then
x -= Price.STOC(200, 70)
End If
Plot = x
Else If isFirstBar Then
x = 0
Plot = Single.NaN
Else
Plot = Single.NaN
End If
Another thing to check is if Price.STOC(10, 2) and Price.STOC(200, 70) mean what you intend. The 2 and 70 are Bars Ago parameters.
A very minor change will improve performance a bit. Instead of
If Price.STOC(10, 2) > 80 Then
x += Price.STOC(200, 70)
End If
If Price.STOC(10, 2) < 20 Then
x -= Price.STOC(200, 70)
End If
changing it to
If Price.STOC(10, 2) > 80 Then
x += Price.STOC(200, 70)
else If Price.STOC(10, 2) < 20 Then
x -= Price.STOC(200, 70)
End If
elminates the < 20 check when it is > 80
|
|
Guest-1 |