Download software Tutorial videos
Subscription & data-feed pricing Class schedule


New account application Trading resources
Margin rates Stock & option commissions

Attention: Discussion forums are read-only for extended maintenance until further notice.
Welcome Guest, please sign in to participate in a discussion. Search | Active Topics |

How can Calculate an Absolute Value ? Rate this Topic:
Previous Topic · Next Topic Watch this topic · Print this topic ·
evanm
Posted : Sunday, June 6, 2010 7:57:39 PM
Registered User
Joined: 9/18/2008
Posts: 65
I have written the following code to calculate the difference in the top of the bollinger band and top of keltner channel and the different between the Bottom of Bollinger band and Bottom of Keltner.

Now my problem is that sometimes these MA calucation values can be a negative number.
How can i make the end result of a calculation an "Absolute" Value.

'# MA3 = indicator.MovingAverage.6
'# MA2 = indicator.MovingAverage.5
'# MA1 = indicator.MovingAverage.4
'# MA = indicator.MovingAverage.2
'*********************************************
'* if Price.Close > Price.Close(1) then Pass *
'*********************************************
'*** MA=TopBollinger Moving Avg
'*** MA1=BottomBollinger Moving Avg
'*** MA2=TopKeltner Moving Avg
'*** MA3=BottomKeltner Moving Avg
'***********************************************

Dim diff As Single
Dim diff2 As Single


diff = (MA.value - MA2.value) - _
(MA1.VALUE - MA3.value)

diff2 = (MA.value(1) - MA2.value(1)) - _
(MA1.VALUE(1) - MA3.value(1))

If diff > diff2 Then Pass

As shown above how can i have the following result in an absolute value
(MA.value - MA2.value)
evanm
StockGuy
Posted : Sunday, June 6, 2010 10:33:23 PM

Administration

Joined: 9/30/2004
Posts: 9,187
system.math.abs(MA.value - MA2.value)
evanm
Posted : Sunday, June 6, 2010 11:19:09 PM
Registered User
Joined: 9/18/2008
Posts: 65
Thank you
But will this work for Stockfinder version 4 ?
EvanM
Bruce_L
Posted : Monday, June 7, 2010 6:58:13 AM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
evanm,
Yes, the Absolute Value function works in StockFinder 4. The difference is that the system portion could be left out in StockFinder 5. So in StockFinder 5 it could be written as:

Math.Abs(MA.Value - MA2.Value)

While in StockFinder 4, you need to explicitly state System:

System.Math.Abs(MA.Value - MA2.Value)

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
StockGuy
Posted : Monday, June 7, 2010 10:15:47 AM

Administration

Joined: 9/30/2004
Posts: 9,187
QUOTE (evanm)
Thank you
But will this work for Stockfinder version 4 ?
EvanM


Did you try it in version 4?
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.