END OF MONTH

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #225732 quote
    Hary Trading
    Participant
    New

    Buongiorno e buone feste a tutti

    un ringraziamento anticipato a chi vorrà aiutarmi

    Vorrei codificare una strategia di questo tipo:

    Entra long con 1 contratto gli ultimi due giorni dI contrattazione  del mese (prendiamo per esempio Marzo) e chiudiamo il trade il secondo giorno del mese successivo (in questo caso Aprile)

    Grazie ancora

     

    Hary

    #225734 quote
    Jean FX
    Moderator
    New

    L’uscita al secondo giorno di negoziazione del mese è facile, ma l’apertura al penultimo giorno non può essere automatizzata, poiché non esiste un calendario di trading che indichi il numero teorico di giorni di negoziazione rimanenti nel mese.

    #225742 quote
    robertogozzi
    Moderator
    Master

    In effetti è un pò difficile essere certi che funzioni tutti i mesi.

    Si può trovare l’ultimo giorno del mese ed andare indietro di due giorni presumibilmente non festivi, ma non è detto che sia sempre così. Ad esempio, questo mese il 31 è domenica, quindi andando indietro di due giorni NON festivi si arriva al 28 Dicembre e tutto funziona correttamente, ma se il 28 Dicembre il trading fosse chiuso non possiano saperlo, quindi per quel mese non verrebbe aperta nessuna posizione.

    Questo l’ho provato sul DAX, Giornaliero:

    DEFPARAM CumulateOrders = False
    ONCE EntryDay = 0
    x = OpenMonth
    IF x <> x[1] THEN  //al cambio del mese si feterminano i giorni totali del mese
    $gg[OpenDay] = OpenDayOfWeek
    FOR i = (OpenDay + 1) TO 31   //riempire un ARRAY con tutti i giorni delle settimana del mese
    $gg[i] = $gg[i-1] + 1
    IF $gg[i] > 7 THEN
    $gg[i] = 1
    ENDIF
    NEXT
    DayMax = 31
    IF (x = 4) OR (x = 6) OR (x = 9) OR (x = 11) THEN
    DayMax = 30
    ELSIF x = 2 THEN
    DayMax  = 28
    IF (Year MOD 4) = 0 THEN
    IF (Year MOD 100) <> 0 THEN
    DayMax = 29
    ELSE
    IF (Year MOD 400) = 0 THEN
    DayMax = 29
    ENDIF
    ENDIF
    ENDIF
    ENDIF
    j = 0
    EntryDay = 0
    FOR i = 1 TO 20
    IF ($gg[DayMax] >= 1) AND ($gg[DayMax] <= 5) THEN
    EntryDay = DayMax
    j = j + 1
    IF j = 2 THEN
    break
    ENDIF
    ENDIF
    DayMax = DayMax - 1
    NEXT
    ENDIF
    IF (Day >= EntryDay) AND Not OnMarket THEN
    BUY 1 CONTRACT AT MARKET
    j = 0
    ENDIF
    IF OnMarket THEN
    IF x <> x[1] THEN
    j = j + 1
    IF j >= 2 THEN
    SELL AT MARKET
    ENDIF
    ENDIF
    ENDIF
    //graph EntryDay
    //graph DayOfWeek

    se trovi qualche incongruenza fammi sapere il Mese e l’Anno (e lo strumento su cui l’hai provato), per vedere se si può risolvere o meno.

    #225745 quote
    Hary Trading
    Participant
    New

    Grazie infinite ad entrambi per il vostro aiuto

    Siete sempre gentilissimi

     

    Grazie

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.

END OF MONTH


ProOrder: Trading Automatico & Backtesting

New Reply
Author
author-avatar
Hary Trading @adtrader Participant
Summary

This topic contains 3 replies,
has 3 voices, and was last updated by Hary Trading
2 years, 1 month ago.

Topic Details
Forum: ProOrder: Trading Automatico & Backtesting
Language: Italian
Started: 12/27/2023
Status: Active
Attachments: No files
Logo Logo
Loading...