Trade orario ottimizzabile

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #231246 quote
    Gabriele Battista
    Participant
    Senior

    Vorrei costruire una strategia che compri all’open di una candela oraria e chiuda la posizione long all’ open della candela successiva. Grazie

    #231249 quote
    robertogozzi
    Moderator
    Master

    Penso tu voglia questo:

    SELL at Market
    IF NOT OnMarket THEN
       BUY 1 Contract at Market
    ENDIF
    Gabriele Battista thanked this post
    #231264 quote
    Gabriele Battista
    Participant
    Senior

    Ciao il tuo codice apre un long un ora si e un ora no. Il mio intento era quello di avere un Long al giorno in un ora che potesse poi essere utilizzata come variabile da ottimizzare con un back test. E’ possibile? Grazie

    #231271 quote
    MauroPro
    Participant
    Veteran

    Ho scritto questo semplice TS  sul cfd Nasdaq TF: H1 (non ho inserito le commissioni) e funziona (allego immagini),

    Gabriele Battista and robertogozzi thanked this post
    #231304 quote
    robertogozzi
    Moderator
    Master

    Eccolo:

    ONCE tt = 100000
    OTD = Barindex - TradeIndex(1) > IntradayBarIndex
    IF LongOnMarket THEN
       SELL at Market
    ENDIF
    IF Time = tt AND OTD AND Not LongOnMarket THEN
       BUY 1 Contract at Market
    ENDIF

    @MauroPro

    per favore posta sempre anche il codice, anche se molto semplice. Grazie 🙂

    #231331 quote
    Gabriele Battista
    Participant
    Senior

    Grazie. E’ possibile avere un codice che funzioni nello stesso modo per i giorni della settimana per poter ottimizzare la variabile gg.?

    #231333 quote
    MauroPro
    Participant
    Veteran
    OTD = (barIndex - tradeIndex(1) > intradayBarIndex)
    if not onMarket and OTD and time = tt and dayOfWeek = giorno  then   // tt [0-230000 - step 010000]  - giorno [1(=lunedi)-5(=venerdi) - step 1]
    buy 1 contracts at market
    endif
    if longOnMarket and time = tt + 010000 then
    sell 1 contracts at market
    endif
    
    #231361 quote
    Gabriele Battista
    Participant
    Senior

    Grazie ma dovrebbe aprire all’open di un giorno e chiudere all’open del gg successivo in modo da poter ottimizzare la variabile giorno.

    #231364 quote
    Gabriele Battista
    Participant
    Senior
    //apertura di posizione all'open
    
    ONCE D=1
    IF DayOfWeek = D AND Not OnMarket THEN
    BUY 1 Contract at Market
    ENDIF
    
    //chiusura di posizione all’open gg successivo
    
    IF (DayOfWeek = D+1) AND OnMarket THEN
    SELL at Market
    ENDIF

    Ho provato questo ma ha il problema del venerdì

    #231365 quote
    robertogozzi
    Moderator
    Master

    Eccolo:

    ONCE gg = Day
    OTD = Barindex - TradeIndex(1) > IntradayBarIndex
       IF LongOnMarket AND Day <> Day[1] THEN
    SELL at Market
    ENDIF
    IF OTD AND Not LongOnMarket THEN
       BUY 1 Contract at Market
       gg = Day
    ENDIF
    Gabriele Battista thanked this post
    #231368 quote
    Gabriele Battista
    Participant
    Senior

    Grazie. Devo ottimizzare la variabile gg da 1 a 5 per vedere il gg più profittevole?

    #231373 quote
    robertogozzi
    Moderator
    Master

    Si, esatto.

    Puoi provare anche partendo da 0, se c’è anche la Domenica (lo vedi sul grafico se è presente una candela di Domenica oppure no).

    Gabriele Battista thanked this post
    #231389 quote
    Gabriele Battista
    Participant
    Senior

    grazie ma mi da gli stessi risultati per ogni gg.

    dove sbaglio?

    #231396 quote
    MauroPro
    Participant
    Veteran

    Si in effetti sono tutti giorni uguali, bisogna sentire Roberto.

    Comunque puoi anche usare il tuo codice (simile a quello sotto che ho riscritto e provato sul Dax con timeframe sempre H1) e per il problema del venerdi hai due soluzioni:

    1) esci alle 22 ( come fa il Ts riportato sotto) oppure, solo per il venerdi, crei un uscita dedicata il lunedi (ma non ti consiglio di rimanere dentro overWeek, per interessi, dividendi, imprevisti …).

     

    OTD = barIndex – tradeIndex(1) > intradayBarIndex

    if not onMarket and OTD and dayOfWeek = gg then // gg ottimizzato da 1 a 5 step 1
    buy 1 contract at market
    endif

    if longOnMarket and dayOfWeek = gg+1 then
    sell at Market
    endif

    if longOnMarket and dayOfWeek = 5 and time = 220000 then
    sell at market
    endif

    Gabriele Battista thanked this post
Viewing 14 posts - 1 through 14 (of 14 total)
  • You must be logged in to reply to this topic.

Trade orario ottimizzabile


ProOrder: Trading Automatico & Backtesting

New Reply
Summary

This topic contains 13 replies,
has 3 voices, and was last updated by MauroPro
1 year, 10 months ago.

Topic Details
Forum: ProOrder: Trading Automatico & Backtesting
Language: Italian
Started: 04/08/2024
Status: Active
Attachments: 3 files
Logo Logo
Loading...