how to use CountIF?
Posted: Dec 01 2014
by Ram
Dear All,
I'm looking for a way of getting the number of times a certain price was crossed over from last bar, I know how to get this done using loops but as I need to scan many prices I prefer to use CountIF instead of loops inside loops..
Can anyone pls point me on how to do this?
Thanks much in advance!
Best,
Ram
Re: how to use CountIF?
Posted: Dec 01 2014
by Henry MultiŠ”harts
Hello Ram,
It works the same way as in the PowerLanguage. You can find the description and examples in the
Functions & Reserved Words Reference guide.
Re: how to use CountIF? [SOLVED]
Posted: Dec 04 2014
by Ram
for anyone interested in a working example:
Code: Select all
Imports System
Imports System.Drawing
Imports PowerLanguage
Imports PowerLanguage.Indicator
Imports PowerLanguage.Function
Imports System.Linq
Namespace PowerLanguage.Indicator
Public Class countIF
Inherits IndicatorObject
Public Sub New(ByVal _ctx As Object)
MyBase.New(_ctx)
End Sub
Protected Overrides Sub CalcBar()
If Bars.LastBarOnChart Then
MyPrice = 2000
' count how many times the HIGH was above MyPrice
MyCount = Me.criteria.CountIF(ExecInfo.MaxBarsBack)
'print out the results
Output.WriteLine(MyCount)
StopCalc()
End If
End Sub
Protected Overrides Sub Create()
End Sub
Protected Overrides Sub StartCalc()
ExecInfo.MaxBarsBack = Bars.FullSymbolData.Count
'criteria for HIGH level count example
Me.m_criteria = New Lambda(Of Boolean)(Function(_bb) PublicFunctions.DoubleGreater(MyBase.Bars.High.Item(_bb), MyPrice))
End Sub
Private ReadOnly Property criteria As ISeries(Of Boolean)
Get
Return Me.m_criteria
End Get
End Property
Private m_criteria As ISeries(Of Boolean)
Private MyPrice as Double
Private MyCount as Double
End Class
End Namespace