ROSS PATTERN 1-2-3 PARA VISUAL CHART 5. 'กก Parameters Dim ObservationPeriod As Integer '14 Dim StrengthPivot As Long '1 Dim NuMaxBars_1_2 As Long '3 Dim NuMaxBars_2_3 As Long '2 'Parameters !! Dim rsidata As DataIdentifier Private Type pat123type active As Boolean: setup As Boolean: p1 As Double: barp1 As Long: p2 As Double:barp2 As Long:p3 As Double:barp3 As Long End Type Dim bearpat() As pat123type: Dim bullpat() As pat123type: Dim lastbar As Long Option Explicit Public APP As OscUserApp Implements Indicator Public Sub Indicator_OnInitCalculate() With APP rsidata = .GetIndicatorIdentifier(RSI, Data, ObservationPeriod, 70, 30) ReDim bearpat(1):ReDim bullpat(1):lastbar = -1 End With End Sub Public Sub Indicator_OnCalculateBar(ByVal bar As Long) With APP If bar <> lastbar Then bullpat(1) = bullpat(0):bearpat(1) = bearpat(0) Else bullpat(0) = bullpat(1):bearpat(0) = bearpat(1) End If '----- BULL PATTERN 1-2-3 If Not bullpat(0).setup Then bullpat(0).setup = Setup_Pattern123(bullpat(0), 1) If bullpat(0).setup Then If FulFill_HighestHigh(bar - bullpat(0).barp3) Then bullpat(0).active = True Else bullpat(0).setup = (.High() <= bullpat(0).p2 And .Low() >= bullpat(0).p3) End If End If Call Paint_Pattern(bullpat(0), 1) '----- BEAR PATTERN 1-2-3 If Not bearpat(0).setup Then bearpat(0).setup = Setup_Pattern123(bearpat(0), -1) If bearpat(0).setup Then If FulFill_LowestLow(bar - bearpat(0).barp3) Then bearpat(0).active = True Else bearpat(0).setup = (.High() <= bearpat(0).p3 And .Low() >= bearpat(0).p2) End If End If Call Paint_Pattern(bearpat(0), 6) lastbar = bar End With End Sub Public Sub Indicator_OnSetParameters(ParamArray ParamList() As Variant) 'กก Parameters initialization 'Parameters initialization !! End Sub Public Sub Indicator_OnCalculateRange(ByVal StartBar As Long, ByVal FinalBar As Long) Dim i As Long i = APP.StartBar If StartBar > i Then i = StartBar End If While Not APP.ShouldTerminate And i <= FinalBar APP.CurrentBar = i Indicator_OnCalculateBar i i = i + 1 Wend End Sub Private Sub OscUserAppInstance_OnConnection(ByVal Application As OscUserApp, ByVal MTDllInst As Object, Custom() As Variant) Set APP = Application End Sub Private Function Setup_Pattern123(ByRef pat As pat123type, signal As Integer) As Boolean With APP Dim pataux As pat123type: Dim baraux3 As Double: Dim distance As Integer:Dim exitloop As Boolean: Dim x As Integer pataux.barp1 = -1:pataux.barp2 = -1: pataux.barp3 = -1 distance = 3 + NuMaxBars_1_2 + NuMaxBars_2_3 + 2 * StrengthPivot If (signal = 1) Then baraux3 = .GetSwingLowBar(Data, 1, PriceLow, StrengthPivot, distance) Else baraux3 = .GetSwingHighBar(Data, 1, PriceHigh, StrengthPivot, distance) End If If baraux3 <> NullValue Then If (signal = 1) Then pataux.p3 = Math.Round(.Low(baraux3), 5) Else pataux.p3 = Math.Round(.High(baraux3), 5) End If pataux.barp3 = .CurrentBar() - baraux3 Dim baraux2 As Double:Dim top2val As Double x = 1: distance = 2 + NuMaxBars_2_3 + StrengthPivot If (signal = 1) Then top2val = Math.Round(.GetHighest(Data, PriceHigh, distance), 5) Else top2val = Math.Round(.GetLowest(Data, PriceLow, distance), 5) End If While Not exitloop If (signal = 1) Then baraux2 = .GetSwingHighBar(Data, x, PriceHigh, StrengthPivot, distance) Else baraux2 = .GetSwingLowBar(Data, x, PriceLow, StrengthPivot, distance) End If If baraux2 <> NullValue Then If (baraux2 > baraux3) Then If (signal = 1) Then pataux.p2 = Math.Round(.High(baraux2), 5) Else pataux.p2 = Math.Round(.Low(baraux2), 5) End If pataux.barp2 = .CurrentBar() - baraux2 If (pataux.p2 = top2val) Then exitloop = True Else pataux.barp2 = -1 x = x + 1 End If Else x = x + 1 End If Else exitloop = True End If Wend If (pataux.barp2 <> -1) Then Dim top1val As Double: Dim baraux1 As Double exitloop = False: x = 2: distance = baraux2 + 1 + NuMaxBars_1_2 + StrengthPivot If (signal = 1) Then top1val = Math.Round(.GetLowest(Data, PriceLow, distance), 5) Else top1val = Math.Round(.GetHighest(Data, PriceHigh, distance), 5) End If While Not exitloop If (signal = 1) Then baraux1 = .GetSwingLowBar(Data, x, PriceLow, StrengthPivot, distance) Else baraux1 = .GetSwingHighBar(Data, x, PriceHigh, StrengthPivot, distance) End If If baraux1 <> NullValue Then If (signal = 1) Then pataux.p1 = Math.Round(.Low(baraux1), 5) Else pataux.p1 = Math.Round(.High(baraux1), 5) End If pataux.barp1 = .CurrentBar() - baraux1 If (pataux.p1 = top1val) Then exitloop = True Else pataux.barp1 = -1 x = x + 1 End If Else exitloop = True End If Wend If (pataux.barp1 <> -1) Then If (signal = 1 And .GIV(rsidata, baraux1) >= 30) Or (signal = -1 And .GIV(rsidata, baraux1) <= 70) Then pataux.barp1 = -1 pataux.p1 = NullValue End If End If End If End If If (pataux.barp1 <> -1) Then pat = pataux Setup_Pattern123 = True Else Setup_Pattern123 = False End If End With End Function Private Function FulFill_HighestHigh(nbref As Double) As Boolean With APP Dim exitloop As Boolean: Dim fulfill As Boolean: Dim n As Integer While Not exitloop If (.High(n) > .High(nbref)) Then exitloop = True: fulfill = True Else n = n + 1: exitloop = (n >= nbref) End If Wend FulFill_HighestHigh = fulfill End With End Function Private Function FulFill_LowestLow(nbref As Double) As Boolean With APP Dim exitloop As Boolean: Dim fulfill As Boolean: Dim n As Integer While Not exitloop If (.Low(n) < .Low(nbref)) Then exitloop = True:fulfill = True Else n = n + 1: exitloop = (n >= nbref) End If Wend FulFill_LowestLow = fulfill End With End Function Private Sub Paint_Pattern(ByRef pat As pat123type, n As Integer) With APP If (pat.active) Then Dim bar As Long bar = .CurrentBar() .SetIndicatorValue pat.p1, n, bar - pat.barp1 .SetIndicatorValue pat.p2, n + 1, bar - pat.barp2 .SetIndicatorValue pat.p3, n + 2, bar - pat.barp3 .SetIndicatorValue pat.p2, n + 3 .SetIndicatorValue pat.p3, n + 4 pat.setup = False If (n = 1) Then pat.active = (.High() <= pat.p2 And .Low() >= pat.p3) Else pat.active = (.High() <= pat.p3 And .Low() >= pat.p2) End If End If End With End Sub