MACD Strategy Core Code
 

'Generating signals for opening positions

 

Private Sub Signals()

 

Dim ByPebP, SlPebP, ByMgbP, SlMgbP, DlPe, Trigger As Double

 

'Calculating Trigger for an action standard

Trigger = [B8].Value * [B34].Value / 100

 

'The strategy is inside between If and Then. If MACD > Signal, Then generate a Long OK signal.

If LongOK = False And _

    Cells(Candle, "V").Value - Cells(Candle, "W").Value > Trigger And Cells(Candle + 1, "V").Value < Cells(Candle + 1, "W").Value Then     'Strategy for Long Condition Yang

    LongOK = True

    BCBM = Candle

    BBP = Round(Cells(Candle, "L").Value, 2)

    Cells(Candle, "N").Value = "Long OK " & Int([B20].Value * CP / 100 / BBP) & " @ " & BBP

    Exit Sub

End If

 

'The strategy is inside between If and Then. If MACD < Signal, Then generate a Short OK signal.

If ShortOK = False And _

    Cells(Candle, "V").Value - Cells(Candle, "W").Value < -1 * Trigger And Cells(Candle + 1, "V").Value > Cells(Candle + 1, "W").Value Then   'Strategy for Short Condition Yin

    ShortOK = True

    SCBM = Candle

    SBP = Round(Cells(Candle, "L").Value, 2)

    Cells(Candle, "N").Value = "Short OK " & Int(([B20].Value + 1.5 * [B19].Value * SlPebP) / 1.5 * CP / 100 / SBP) & " @ " & SBP

    Exit Sub

End If

 

If BCBM - Candle > [B7].Value Then LongOK = False

If SCBM - Candle > [B7].Value Then ShortOK = False

 

'Open Long

If BCBM - Candle <= [B7].Value Then

'    If LongOK = True And ShortOK = False And Cells(Candle, "I").Value > BBP Then

    If LongOK = True And ShortOK = False Then

            DlPe = Round((Cells(Candle, "J").Value + Cells(Candle, "K").Value) / 2, 2)

        If [B19].Value = 0 Then

            TdSum = Int([B20].Value * CP / 100 / DlPe)

            Cells(Candle, "O").Value = -1 * TdSum * DlPe

            [B19].Value = [B19].Value + TdSum

            PBM = DlPe

            BM = [B20].Value + Cells(Candle, "O").Value + [B19].Value * PBM

            [B20].Value = [B20].Value + Cells(Candle, "O").Value

            Cells(Candle, "AE").Value = [B20].Value + [B19].Value * Cells(Candle, "L").Value

            Cells(Candle, "N").Value = "Buy/Open " & TdSum & " @ " & DlPe

        End If

    End If

End If

 

'Open Short

If SCBM - Candle <= [B7].Value Then

'    If ShortOK = True And LongOK = False And Cells(Candle, "I").Value < SBP Then

    If ShortOK = True And LongOK = False Then

             DlPe = Round((Cells(Candle, "J").Value + Cells(Candle, "K").Value) / 2, 2)

        If [B19].Value = 0 Then

            TdSum = Int([B20].Value / 1.5 * CP / 100 / DlPe)

            Cells(Candle, "O").Value = TdSum * DlPe

            [B19].Value = [B19].Value - TdSum

            PBM = DlPe

            BM = [B20].Value + Cells(Candle, "O").Value + [B19].Value * PBM

            [B20].Value = [B20].Value + Cells(Candle, "O").Value

            Cells(Candle, "AE").Value = [B20].Value + [B19].Value * Cells(Candle, "L").Value

            Cells(Candle, "N").Value = "Sell/Open " & TdSum & " @ " & DlPe

       End If

    End If

End If

 

End Sub

  


Free Tutorial

Share

Copyright © 2009~2023 Data Gladiator All Rights Reserved.

Disclaimer & Privacy Policy     Contact Us