📄 midicators.bas
字号:
For Y2 = iZeroPosition - rStep To rSplit2 + 4 Step -rStep 'zero up
.CurrentY = Y2 - iTextHeight / 2
'Debug.Print .CurrentY; rSplit2
If .CurrentY < rSplit2 + iTextHeight Then
.CurrentY = Y2
End If
'print value of grid line
rGridValue = (iZeroPosition - Y2) / (dHeightInd / rIndRange)
If rGridValue > 10 Then
sText$ = Round(rGridValue)
Else
sText$ = Format(rGridValue, "##.##")
End If
rString = .TextWidth(sText$)
If rString > iMaxTxtWidth Then iMaxTxtWidth = rString
.CurrentX = xRightMargin - rString - 10
frmMain.ChartBox.Print sText$
frmMain.ChartBox.Line (xLeftMargin, Y2)-(xRightMargin - rString - 20, Y2), iGridColor
Next Y2
'plot zero line and legion text
rString = .TextWidth(CStr(0))
If oCurrentIndicator.ZeroLinePlot Then
.DrawStyle = vbSolid
frmMain.ChartBox.Line (xLeftMargin, iZeroPosition)-((xRightMargin - rString - 20), iZeroPosition), RGB(0, 0, 160)
Else
frmMain.ChartBox.Line (xLeftMargin, iZeroPosition)-((xRightMargin - rString - 20), iZeroPosition), iGridColor
End If
.CurrentX = xRightMargin - rString - 10
rString = iTextHeight / 2
.CurrentY = .CurrentY - rString
frmMain.ChartBox.Print CStr(0) 'print zero legion text
'start the ind. data plot
.DrawStyle = vbSolid
iPrevIndW = .DrawWidth
.DrawWidth = oCurrentIndicator.PlotWidth
If oCurrentIndicator.PlotTriggerLines Then
'plot upper trigger
rUpperTrig = oCurrentIndicator.UpperTrig
rLowerTrig = oCurrentIndicator.LowerTrig
Y1 = 4 + rSplit2 + (((rMax - rUpperTrig) * dHeightInd) / rIndRange)
rString = .TextWidth(CStr(rUpperTrig)) + iMaxTxtWidth + 3
frmMain.ChartBox.Line (xLeftMargin, Y1)-(xRightMargin - rString - 20, Y1), RGB(0, 0, 160)
.CurrentX = xRightMargin - rString - 10
rString = iTextHeight / 2
.CurrentY = .CurrentY - rString + 3
frmMain.ChartBox.Print CStr(rUpperTrig)
'lower trigger
Y1 = 4 + rSplit2 + (((rMax - rLowerTrig) * dHeightInd) / rIndRange)
rString = .TextWidth(CStr(rLowerTrig)) + iMaxTxtWidth + 3
frmMain.ChartBox.Line (xLeftMargin, Y1)-(xRightMargin - rString - 20, Y1), RGB(0, 0, 160)
.CurrentX = xRightMargin - rString - 10
rString = iTextHeight / 2
.CurrentY = .CurrentY - rString
frmMain.ChartBox.Print CStr(rLowerTrig)
End If
'plot data
x = rRightSideOffset
iCount = iStartIndex
sText$ = sEmpty
For i = 0 To iUB2
Do While x > -1 And iCount >= 0
Y1 = 4 + rSplit2 + (((rMax - aIndData(iCount, i)) _
* dHeightInd) / rIndRange)
If X2 <> 0 Then
If iPlotColors(i, 1) = 0 Then 'line plot
frmMain.ChartBox.Line (X2, Y2)-(x, Y1), iPlotColors(i, 0)
ElseIf iPlotColors(i, 1) = 1 Then 'histogram
frmMain.ChartBox.Line (x, iZeroPosition)-(x, Y1), iPlotColors(i, 0)
End If
End If
X2 = x
Y2 = Y1
iCount = iCount - 1
x = x - iBarSpacing
Loop
x = rRightSideOffset
iCount = iStartIndex
X2 = 0
'get the last ind. value for printout
sText$ = sText$ & CStr(Format(aIndData(iUB, i), "##.00"))
If i <> iUB2 Then sText$ = sText$ & "; "
Next
.DrawWidth = iPrevIndW
'print ind. label text
sText$ = sIndLabel$ & ": " & sText$
'draw a "blackout rect for better visibility of the text
frmMain.ChartBox.Line (1, rSplit2 + 3)-(1 + .TextWidth(sText$), rSplit2 + 3 + .TextHeight(sText$)), iBackColor, BF
.CurrentX = 1
.CurrentY = rSplit2 + 3
frmMain.ChartBox.Print sText$
End With
End Sub
Private Sub LoadDblArray()
Dim i As Integer, aArray() As Double
ReDim aArray(0 To iUBaData)
For i = 0 To iUBaData
aArray(i) = aData(i).dClose 'calculations only need close
Next
oCurrentIndicator.Calculate aArray()
Select Case CurrentIndicator$
Case "MACD"
ReDim aIndData(oCurrentIndicator.RetBoundLo To oCurrentIndicator.RetBoundHi, 0 To 2)
For i = oCurrentIndicator.RetBoundLo To oCurrentIndicator.RetBoundHi
aIndData(i, 0) = oCurrentIndicator.RetVal(i)
aIndData(i, 1) = oCurrentIndicator.RetValSig(i)
aIndData(i, 2) = oCurrentIndicator.RetValHist(i)
Next
Case "RSI", "ROC%"
ReDim aIndData(oCurrentIndicator.RetBoundLo To oCurrentIndicator.RetBoundHi, 0 To 0)
For i = oCurrentIndicator.RetBoundLo To oCurrentIndicator.RetBoundHi
aIndData(i, 0) = oCurrentIndicator.RetVal(i)
Next
End Select
End Sub
Private Sub LoadStockDataArray()
Dim i As Integer, aArray() As StockData
ReDim aArray(0 To iUBaData)
For i = 0 To iUBaData
aArray(i) = aData(i)
Next
Select Case CurrentIndicator$
Case "CCI"
CCI1.Calculate aArray()
ReDim aIndData(CCI1.RetBoundLo To CCI1.RetBoundHi, 0 To 1)
For i = CCI1.RetBoundLo To CCI1.RetBoundHi
aIndData(i, 0) = CCI1.RetValAvg(i)
aIndData(i, 1) = CCI1.RetValAvgAvg(i)
Next
Case "STOCH"
STOCH1.Calculate aArray()
ReDim aIndData(STOCH1.RetBoundLo To STOCH1.RetBoundHi, 0 To 1)
If STOCH1.StochSlow Then 'plot stochastic slowK
For i = STOCH1.RetBoundLo To STOCH1.RetBoundHi
aIndData(i, 0) = STOCH1.RetValKSlow(i)
aIndData(i, 1) = STOCH1.RetValD(i)
Next
Else
For i = STOCH1.RetBoundLo To STOCH1.RetBoundHi
aIndData(i, 0) = STOCH1.RetValK(i)
aIndData(i, 1) = STOCH1.RetValKSlow(i)
Next
End If
End Select
End Sub
Public Sub PlotAvg()
Dim iPeriod As Long, iColor As Long, j As Long
Dim aMovAvg() As Double, x As Integer, y As Integer, xPrev As Integer, yPrev As Integer
Dim i As Integer, iCount As Integer, aTemp() As Double, iOldStyle As Long, iOldWidth As Long
ReDim aTemp(0 To iUBaData)
For i = 0 To iUBaData
aTemp(i) = aData(i).dClose
Next i
With frmMain.ChartBox
iOldStyle = .DrawStyle 'save current draw settings
iOldWidth = .DrawWidth
.DrawStyle = vbSolid
For j = 1 To 3
Select Case j
Case 1
.DrawWidth = iAvgWidth1
MovAvgs.AvgLen = iAvgLen1
iColor = iAvgColor1
Case 2
.DrawWidth = iAvgWidth2
MovAvgs.AvgLen = iAvgLen2
iColor = iAvgColor2
Case 3
.DrawWidth = iAvgWidth3
MovAvgs.AvgLen = iAvgLen3
iColor = iAvgColor3
End Select
MovAvgs.Calculate aTemp()
ReDim aMovAvg(MovAvgs.RetBoundLo To MovAvgs.RetBoundHi)
For i = MovAvgs.RetBoundLo To MovAvgs.RetBoundHi
aMovAvg(i) = MovAvgs.RetVal(i)
Next i
x = .ScaleWidth - iBlankSpace * 10
rRightSideOffset = x
iCount = iStartIndex
Do While x > -1 And iCount > 1
If aMovAvg(iCount) <> 0 Then
'Debug.Print aMovAvg(iCount)
y = 4 + (((dMaxPrice - aMovAvg(iCount)) * dHeightPrice) / dRangePrice)
If x < rRightSideOffset And y < rSplit1 Then
frmMain.ChartBox.Line (x, y)-(xPrev, yPrev), iColor
End If
xPrev = x
yPrev = y
End If
iCount = iCount - 1
x = x - iBarSpacing
Loop
Next
.DrawStyle = iOldStyle 'restore old settings
.DrawWidth = iOldWidth
End With
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -