creazione macro



  • creazione macro
    di ludagi data: 01/09/2015 16:24:27

    ho un file e su di essa ho fatto una macro per testare quanto segue :



    1° memorizzo prezzo attuale

    2° se prezzo corrente - prezzo memorizzato >50 vendo

    2a° se gain = 40 chiudo gain

    2b° se loss = 15 chiudo in loss

    2c° memorizzo prezzo attuale

    oppure


    3° se prezzo corrente - prezzo memorizzato < 50 compro

    3a° se gain = 40 chiudo gain

    3b° se loss = 15 chiudo in loss

    3c° memorizzo prezzo attuale


    e ripeto ciclo

    ma la macro non da risultati razionali

    è possibile correggerla

    grazie

     
    Sub sim()
    
    Static g, l, v, a, p, s, x
    s = 40
    
    
    For i = 8 To 5000
    
    If x = 0 Then
    
    p = Range("$f$" & i)
    
    If Range("f" & i) - p >= 50 Then  ' vendi
    
    v = Range("$F$" & i)  ' prezzo di vendita
    x = 1
    
    
    
    If Range("f" & i) - p <= 50 Then 'acquista 
    
    a = Range("$F$" & i)  'prezzo d'acquisto
    
    x = 1
    
    End If
    End If
    End If
    
    
    
    If x = 1 Then
    
    
    If Range("F" & i) - v <= -40 Then
    
    g = g + s
    
    p = Range("$f$" & i)
    x = 0
    Else
    
    If Range("F" & i) - v >= 15 Then
    
    l = l + 15
    
    p = Range("$f$" & i)
    
     x = 0
    Else
    
    If Range("F" & i) - a >= 40 Then
    
    g = g + s
    
    p = Range("$f$" & i)
    x = 0
    
    Else
    If Range("F" & i) - a <= -15 Then
    l = l + 15
    
    p = Range("$f$" & i)
    
    x = 0
    
    End If
    
    
    End If
    End If
    End If
    End If
    
    
    
    
    Next i
    
    Range("F1") = g
    
    Range("G1") = l
    
    'g = o
    
    'l = 0
    
    End Sub
    



  • di patel data: 01/09/2015 17:55:02

    lancia la macro passo passo con F8 in modo da controllare dove sbaglia