## SOS Programming SOLVER VBA

So I need help im almost crying i have tried and spent weeks on this but no success whatsoever

What i am trying to do is to maximize the return on a stock at the end of the first 3 months period by changing 6 variables.
This 6 variables give me signals of buy sell and hold. So once i have maximized the return on the fisrt 3 months i test this variables on the future (the next 3 months) to see if this strategy works on the future. So basically im backtesting a investment strategy.

The only thing is that i am using solver but it is not respecting all the restrictions i gave it.

Please i need help im dying here.

note: Everything works except for the solver part

Sub Solver()

Dim x As Integer
Dim cont2 As Integer
Dim solv As Range
Dim cont As Integer
Dim n As Integer
'Las variables de abajo son para copiar y pegar valores únicamente
Dim empresa As String
Dim fechafin As Date
Dim rendpivot As Double
Dim rendbench As Double
Dim rendbh As Double
Dim R1 As Double
Dim S1 As Double
Dim R2 As Double
Dim S2 As Double
Dim R3 As Double
Dim S3 As Double
Dim prueba As Integer

cont = 0
cont2 = 0

n = Worksheets("backtesting V2").Cells(1, 9).Value

For cont = 0 To n - 1

x = Worksheets("backtesting V2").Cells(7 + cont, 2).Offset(1, 0).Value
cont2 = Worksheets("backtesting V2").Cells(7 + cont, 2).Offset(1, -1).Value

If x = 1 Then

SolverReset

SolverOk SetCell:=Worksheets("backtesting V2").Cells(7 + cont, 20), MaxMinVal:=1, ValueOf:="0", ByChange:="\$I\$5:\$N\$5", _
Engine:=3, EngineDesc:="Evolutionary"

SolverSolve UserFinish:=True

empresa = Worksheets("backtesting V2").Cells(3, 3)
Worksheets("ResultadosV2").Cells(4 + prueba, 3) = empresa

fechafin = Worksheets("backtesting V2").Cells(7 + cont, 3)
Worksheets("ResultadosV2").Cells(4 + prueba, 4) = fechafin
Worksheets("ResultadosV2").Cells(4 + prueba, 4).NumberFormat = "m/d/yyyy"

rendpivot = Worksheets("backtesting V2").Cells(7 + cont + cont2, 20)
Worksheets("ResultadosV2").Cells(4 + prueba, 5) = rendpivot
Worksheets("ResultadosV2").Cells(4 + prueba, 5).NumberFormat = "0.00%"

rendbench = Worksheets("backtesting V2").Cells(7 + cont + cont2, 22)
Worksheets("ResultadosV2").Cells(4 + prueba, 6) = rendbench
Worksheets("ResultadosV2").Cells(4 + prueba, 6).NumberFormat = "0.00%"

rendbh = Worksheets("backtesting V2").Cells(7 + cont + cont2, 24)
Worksheets("ResultadosV2").Cells(4 + prueba, 7) = rendbh
Worksheets("ResultadosV2").Cells(4 + prueba, 7).NumberFormat = "0.00%"

R1 = Worksheets("backtesting V2").Cells(5, 9)
Worksheets("ResultadosV2").Cells(4 + prueba, 10) = R1
Worksheets("ResultadosV2").Cells(4 + prueba, 10).NumberFormat = "0.00%"

S1 = Worksheets("backtesting V2").Cells(5, 10)
Worksheets("ResultadosV2").Cells(4 + prueba, 11) = S1
Worksheets("ResultadosV2").Cells(4 + prueba, 11).NumberFormat = "0.00%"

R2 = Worksheets("backtesting V2").Cells(5, 11)
Worksheets("ResultadosV2").Cells(4 + prueba, 12) = R2
Worksheets("ResultadosV2").Cells(4 + prueba, 12).NumberFormat = "0.00%"

S2 = Worksheets("backtesting V2").Cells(5, 12)
Worksheets("ResultadosV2").Cells(4 + prueba, 13) = S2
Worksheets("ResultadosV2").Cells(4 + prueba, 13).NumberFormat = "0.00%"

R3 = Worksheets("backtesting V2").Cells(5, 13)
Worksheets("ResultadosV2").Cells(4 + prueba, 14) = S1
Worksheets("ResultadosV2").Cells(4 + prueba, 14).NumberFormat = "0.00%"

S3 = Worksheets("backtesting V2").Cells(5, 14)
Worksheets("ResultadosV2").Cells(4 + prueba, 15) = S1
Worksheets("ResultadosV2").Cells(4 + prueba, 15).NumberFormat = "0.00%"

prueba = prueba + 1

Else

End If

Worksheets("ResultadosV2").Cells(2, 2) = prueba + 1

Next cont