C[1] and a "0" if C Exa">

  
Monday, January 05, 2009     | Register
TradersStudio Forums
Subject: Counting occurances in a bar array

You are not authorized to post a reply.   
Author Messages
bhh
Posts:17

08-25-2008 1:46 PM Alert 

If I build a bar array of data, is there a function or technique that would allow me to count the occurances of a specific value over a specific number of bars?

Example:

A bar array "data1" is built that stores a "1" if C>CΏ] and a "0" if C<=CΏ].  I want to count the number of occurances of "1" in the past 200 bars, basically telling me how many days the market has close positive from the previous day in the past 200 days.

Example2:

I want to count the number of occurances where data1<>data1Ώ], the number of times a change of direction has occured or number of "runs" in the series.

 

 

murray
Posts:435

08-25-2008 4:44 PM Alert 

Use Summation function to count them up.

It should be in your version if not here is the script , it's a general function.

 

'*******************************************************************
' TradersStudio(r) 2004-2007 , All rights reserved
'Description: Summation
' Adds all the values passed to in, also takes the [] syntax.
'********************************************************************
Function Summation(Price As BarArray, Length) as bararray
    Dim Counter
    Dim CSum As BarArray

    Counter = 0
    CSum = 0

    CSum = 0
    For Counter = 0 To Length - 1
        CSum = CSum + Price[Counter]
    Next
    Summation = CSum
End Function

 

You are not authorized to post a reply.
Forums > TradersStudio 2.x > TradersStudio Basic > Counting occurances in a bar array



ActiveForums 3.6
TradersStudio® Copyright 2004-2009 All Rights Reserved   |  Privacy Statement  |  Terms Of Use