visual basic code of trend lines system : 'กก Parameters Dim nPreviousClose As Double '7 Dim nBars As Double '3 Dim ContractsNumber As Long '1 Dim per As Double '50 Dim zeit1 As Long '0900 Dim zeit2 As Long '2000 'Parameters !! Dim Top, Bottom As Double Dim Z As Long Dim nPivotUpCounter As Double '0 Dim nPivotdownCounter As Double '0 Dim GetSwingHighBarDatatPrice As Price 'Price Dim GetSwingLowBarDatanOccur As Double 'Double Dim GetSwingLowBarDatatPrice As Price 'Price Dim GetSwingLowBarDataStrength As Double 'Double Dim GetSwingHighBarDataOccur As Double 'Double Dim GetSwingHighBarDataStrength As Double 'Double Dim GetSwingLowBarDataLength As Double 'Double Dim GetSwingHighBarDataLength As Double 'Double Dim EndSession As Integer Option Explicit Option Base 1 Dim aPivotUp() As Double Dim aPivotDown() As Double Public APP As SysUserApp Implements System Public Sub System_OnInitCalculate() With APP GetSwingHighBarDatatPrice = 1 GetSwingLowBarDatanOccur = 1 GetSwingLowBarDatatPrice = 2 GetSwingLowBarDataStrength = nBars GetSwingHighBarDataOccur = 1 GetSwingHighBarDataStrength = nBars GetSwingLowBarDataLength = per GetSwingHighBarDataLength = per .StartBar = 0 Bottom = 0 Top = 99999 nPivotUpCounter = 0 nPivotdownCounter = 0 EndSession = 1735 End With End Sub Public Sub System_OnCalculateBar(ByVal Bar As Long) With APP If .Time >= zeit1 And .Time <= zeit2 Then Dim nUp, nDown As Double Dim nImage As Double Dim bPut As Boolean nUp = .GetSwingHighBar(Data, GetSwingHighBarDataOccur, GetSwingHighBarDatatPrice, GetSwingHighBarDataStrength, GetSwingHighBarDataLength) nDown = .GetSwingLowBar(Data, GetSwingLowBarDatanOccur, GetSwingLowBarDatatPrice, GetSwingLowBarDataStrength, GetSwingLowBarDataLength) If nUp <> NullValue Then UpdateBullishPivots nUp End If If nDown <> NullValue Then UpdateBearishPivots nDown End If If nUp <> NullValue And nPivotUpCounter > 1 Then TrendLinePivotUp nImage, bPut If bPut Then Top = nImage End If End If If nDown <> NullValue And nPivotdownCounter > 1 Then TrendLinePivotDown nImage, bPut If bPut Then Bottom = nImage End If End If If .Date > .Date(1) Then EndSession = .Time(1) End If If .GetMarketPosition = 0 Then .Buy AtStop, ContractsNumber, Top .Sell AtStop, ContractsNumber, Bottom Else If .GetMarketPosition = 1 Then .Sell AtStop, ContractsNumber, Bottom Else .Buy AtStop, ContractsNumber, Top End If End If End If End With End Sub Private Sub TrendLinePivotDown(ByRef nImage As Double, ByRef bPut As Boolean) With APP Dim P1, P2 As Double Dim slope, Dif As Double P2 = aPivotDown(nPivotdownCounter) P1 = P2 For Z = nPivotdownCounter - 1 To 1 Step -1 If .Low(aPivotDown(Z)) < .Low(P2) Then P1 = aPivotDown(Z) Exit For End If Next Z If (P1 - P2) <> 0 Then slope = Round((.Low(P2) - .Low(P1)) / (P1 - P2), 2) bPut = True Else Bottom = .Low(P2) bPut = False Exit Sub End If nImage = .Low(P2) For Z = P2 - 1 To 0 Step -1 nImage = nImage + slope Next nImage = nImage + slope If .Low < nImage Then nImage = .Low End If Dif = .Close - (.High - .Close) If Dif < nImage Then nImage = .Low(P2) End If End With End Sub Private Sub TrendLinePivotUp(ByRef nImage As Double, ByRef bPut As Boolean) With APP Dim P1, P2 As Double Dim slope, Dif As Double P2 = aPivotUp(nPivotUpCounter) P1 = P2 For Z = nPivotUpCounter - 1 To 1 Step -1 If .High(aPivotUp(Z)) > .High(P2) Then P1 = aPivotUp(Z) Exit For End If Next Z If (P1 - P2) > 0 Then slope = Round((.High(P1) - .High(P2)) / (P1 - P2), 2) bPut = True Else Top = .High(P2) bPut = False Exit Sub End If nImage = .High(P2) For Z = P2 - 1 To 0 Step -1 nImage = nImage - slope Next nImage = nImage - slope If .High > nImage Then nImage = .High End If Dif = .Close + (.Close - .Low) If Dif > nImage Then nImage = .High(P2) End If End With End Sub Private Sub UpdateBearishPivots(ByVal nPdown As Double) With APP Dim bInsert As Boolean bInsert = True For Z = (nPdown + nPreviousClose) To nPdown Step -1 If .Close(Z) < .Low(nPdown) Then bInsert = False Exit For End If Next If bInsert Then If nPivotdownCounter = 0 Then nPivotdownCounter = nPivotdownCounter + 1 ReDim Preserve aPivotDown(nPivotdownCounter) aPivotDown(nPivotdownCounter) = nPdown Else For Z = 1 To nPivotdownCounter aPivotDown(Z) = aPivotDown(Z) + 1 Next Z If nPdown <> aPivotDown(nPivotdownCounter) Then nPivotdownCounter = nPivotdownCounter + 1 ReDim Preserve aPivotDown(nPivotdownCounter) aPivotDown(nPivotdownCounter) = nPdown End If End If Else For Z = 1 To nPivotdownCounter aPivotDown(Z) = aPivotDown(Z) + 1 Next Z End If End With End Sub Private Sub UpdateBullishPivots(ByVal nPup As Double) With APP Dim bInsert As Boolean bInsert = True For Z = (nPup + nPreviousClose) To nPup Step -1 If .Close(Z) > .High(nPup) Then bInsert = False Exit For End If Next If bInsert Then If nPivotUpCounter = 0 Then nPivotUpCounter = nPivotUpCounter + 1 ReDim Preserve aPivotUp(nPivotUpCounter) aPivotUp(nPivotUpCounter) = nPup Else For Z = 1 To nPivotUpCounter aPivotUp(Z) = aPivotUp(Z) + 1 Next Z If nPup <> aPivotUp(nPivotUpCounter) Then nPivotUpCounter = nPivotUpCounter + 1 ReDim Preserve aPivotUp(nPivotUpCounter) aPivotUp(nPivotUpCounter) = nPup End If End If Else For Z = 1 To nPivotUpCounter aPivotUp(Z) = aPivotUp(Z) + 1 Next Z End If End With End Sub Public Sub System_OnSetParameters(ParamArray ParamList() As Variant) 'กก Parameters initialization nPreviousClose = ParamList(1) nBars = ParamList(2) ContractsNumber = ParamList(3) per = ParamList(4) zeit1 = ParamList(5) zeit2 = ParamList(6) 'Parameters initialization !! End Sub Public Sub System_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 System_OnCalculateBar i i = i + 1 Wend End Sub Private Sub SysUserAppInstance_OnConnection(ByVal Application As SysUserApp, ByVal MTDllInst As Object, Custom() As Variant) Set APP = Application End Sub