Welcome Guest, please sign in to participate in a discussion. Search | Active Topics |

Cumulative Stoc Indicator Rate this Topic:
Previous Topic · Next Topic Watch this topic · Print this topic ·
jhilton
Posted : Wednesday, July 7, 2010 1:34:51 AM
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

Bruce_L
Posted : Wednesday, July 7, 2010 8:58:53 AM


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
jhilton
Posted : Wednesday, July 7, 2010 9:13:42 AM
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
Bruce_L
Posted : Wednesday, July 7, 2010 9:27:08 AM


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
jhilton
Posted : Wednesday, July 7, 2010 10:15:06 AM
Registered User
Joined: 7/28/2006
Posts: 36
I just tried it & it's exactly what I want.

Thank you very much.

jhilton
Bruce_L
Posted : Wednesday, July 7, 2010 10:17:44 AM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
You're welcome.

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
jas0501
Posted : Wednesday, July 7, 2010 11:18:03 AM
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
Users browsing this topic
Guest-1

Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.