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

Retaining a constants value from bar to bar Rate this Topic:
Previous Topic · Next Topic Watch this topic · Print this topic ·
edrichmond
Posted : Wednesday, July 22, 2009 7:57:40 PM
Registered User
Joined: 7/26/2006
Posts: 23
Bruce,
In the following code in order to achieve what I want, I need the variable 'countconst' to retain its value from bar to bar.  As it is, for each bar,' count' and 'countconst' assume the value of '0'  and unless the middle set of if statements are true, keeps the value of zero thru the entire code.  The code is
'#wickpercenttop = userinput.single = 2.0
'#wickpercentbottom = userinput.single = 10.0
'#BenchmarkSize = userinput.single = 1.5
'#Retracement = userinput.single = 0.5
Static atr As Single = 0
Dim wickbottom As Single
Dim TH As Single
Dim TL As Single
Dim wicktop As Single
Dim countconst As Single
Dim count As Single

wicktop = wickpercenttop / 100
wickbottom = wickpercentbottom / 100

atr = 0
For i As Integer = 1 To 5
    th = system.Math.Max(price.high(i), price.Close(i + 1))
    tl = system.Math.Min(price.low(i), price.Close(i + 1))
    atr += th - tl
Next i
atr = atr / 5

If     price.Close >= price.Open AndAlso _
    price.TradeRange >= Benchmarksize * ATR AndAlso _
    price.Open - price.Low < wickbottom * price.TradeRange AndAlso _
    price.High - price.Close < wicktop * price.TradeRange Then
    count = currentindex
    If count = currentindex Then countconst = currentindex
End If

If count <= currentindex Then
    count = currentindex - count
End If
plot = countconst

Eliezer
m_badger
Posted : Wednesday, July 22, 2009 8:00:01 PM
Registered User
Joined: 9/13/2008
Posts: 99
Eliezer,
Currently countconst is declared as:
Dim countconst As Single

perhaps you want to declare it as:

Static counconst As Single

to ensure the value does not go out of scope at the end of the bar?

_mad
edrichmond
Posted : Wednesday, July 22, 2009 8:27:22 PM
Registered User
Joined: 7/26/2006
Posts: 23
Thank you mad, that is the answer!!  I figured it out after I posted the question.  Bruce, if you read this I would like to thank you for your past and future help.
Eliezer
Bruce_L
Posted : Thursday, July 23, 2009 8:22:14 AM


Worden Trainer

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

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
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.