Sub SMA()
If SMA1_P < DATA_ROW Then AVERAGE(CLOSE_COL, SMA1_COL, SMA1_P) If SMA1_P + SMA2_P < DATA_ROW Then AVERAGE(SMA1_COL, SMA2_COL, SMA2_P) If SMA3_P < DATA_ROW Then AVERAGE(CLOSE_COL, SMA3_COL, SMA3_P)
End Sub
Sub AVERAGE(PRICE_COL As Integer, COL As Integer, P As Integer)
DATA.getCellByPosition(COL, DATA_ROW).Value = DATA.getCellRangeByPosition(PRICE_COL, DATA_ROW - P + 1, PRICE_COL, DATA_ROW).computeFunction(com.sun.star.sheet.GeneralFunction.AVERAGE)
End Sub
Sub MACD()
Dim EMA1 As Single Dim EMA2 As Single
Static PRE_EMA1 As Single Static PRE_EMA2 As Single
If EMA1_P < DATA_ROW Then EMA1 = MACD_EMA(EMA1_COL, EMA1_P, PRE_EMA1) PRE_EMA1 = EMA1 End If
If EMA2_P < DATA_ROW Then DATA.getCellByPosition(MACD_COL , DATA_ROW).Value = EMA1 - MACD_EMA(EMA2_COL, EMA2_P, PRE_EMA2) DATA.getCellByPosition(SIGNAL_COL, DATA_ROW).Value = DATA.getCellRangeByPosition(MACD_COL, DATA_ROW - SIGNAL_P + 1, MACD_COL, DATA_ROW).computeFunction(com.sun.star.sheet.GeneralFunction.AVERAGE) DATA.getCellByPosition(HIST_COL , DATA_ROW).Value = DATA.getCellByPosition(MACD_COL, DATA_ROW).Value - DATA.getCellByPosition(SIGNAL_COL, DATA_ROW).Value EMA2 = MACD_EMA(EMA2_COL, EMA2_P, PRE_EMA2) PRE_EMA2 = EMA2 End If
End Sub
Function MACD_EMA(COL As Integer, P As Integer, PRE_EMA As Single) As Single
If DATA_ROW = P + 1 Then MACD_EMA = DATA.getCellRangeByPosition(CLOSE_COL, DATA_ROW - P + 1, CLOSE_COL, DATA_ROW).computeFunction(com.sun.star.sheet.GeneralFunction.AVERAGE) Else MACD_EMA = PRE_EMA + 2 / (P + 1) * (DATA.getCellByPosition(CLOSE_COL, DATA_ROW).Value - PRE_EMA) End If
End Function
Sub ICHIMOKU()
If TENKAN_P < DATA_ROW Then DATA.getCellByPosition(TENKAN_COL, DATA_ROW).Value = NAKANE(TENKAN_P) If KIJYUN_P < DATA_ROW Then DATA.getCellByPosition(KIJYUN_COL, DATA_ROW).Value = NAKANE(KIJYUN_P) If SPAN1_P < DATA_ROW Then DATA.getCellByPosition(SPAN1_COL , DATA_ROW + FORWARD_P - 1).Value = (DATA.getCellByPosition(TENKAN_COL, DATA_ROW).Value + DATA.getCellByPosition(KIJYUN_COL, DATA_ROW).Value) / 2 If SPAN2_P < DATA_ROW Then DATA.getCellByPosition(SPAN2_COL , DATA_ROW + FORWARD_P - 1).Value = NAKANE(SPAN2_P) If CHIKOU_P < DATA_ROW Then DATA.getCellByPosition(CHIKOU_COL, DATA_ROW - CHIKOU_P + 1).Value = DATA.getCellByPosition(CLOSE_COL, DATA_ROW).Value
End Sub
Function NAKANE(P As Integer) As Single
Dim HIGH As Single Dim Low As Single
HIGH = DATA.getCellRangeByPosition(HIGH_COL, DATA_ROW - P + 1, HIGH_COL, DATA_ROW).computeFunction(com.sun.star.sheet.GeneralFunction.MAX) LOW = DATA.getCellRangeByPosition(LOW_COL , DATA_ROW - P + 1, LOW_COL , DATA_ROW).computeFunction(com.sun.star.sheet.GeneralFunction.MIN)
NAKANE = (HIGH + LOW) / 2
End Function
