Registered User Joined: 10/5/2010 Posts: 67
|
How to define a condition that the current bar is a median bar in the last 100 bars i.e. it is not a very wide bar not a very narrow bar. Thank you.
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
The following RealCode Indicator has user inputs for the period, bottom percentile and top percentile you want to use to check if the bar is near the median.
If you use the default period of 100 with a bottom percentile of 25 and a top percentile of 75, it should return true if the bar range is in middle 50% of bar ranges over the most recent 100 bars.
'|*****************************************************************|
'|*** StockFinder RealCode Condition - Version 5.0 www.worden.com
'|*** Copy and paste this header and code into StockFinder *********
'|*** Condition:Bar Range Percentile
'|******************************************************************
'# Period = UserInput.Integer = 100
'# BotPerc = UserInput.Single = 25
'# TopPerc = UserInput.Single = 75
Static range As New List(Of Single)
If isFirstBar Then
range.Clear
End If
range.Insert(0, Price.High - Price.Low)
If range.Count = Period Then
Dim rank As Integer
For i As Integer = 1 To range.Count - 1
rank += System.Math.Sign(range(0) - range(i))
Next
range.RemoveAt(range.Count - 1)
rank = 100 * rank / range.Count / 2 + 50
If BotPerc <= rank AndAlso _
rank <= TopPerc Then
Pass
End If
Else
SetIndexInvalid
End If
If isLastBar Then
range.Clear
End If
-Bruce Personal Criteria Formulas TC2000 Support Articles
|