CHIUSURA POSIZIONE SU TIMEFRAME DIVERSO

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #159610 quote
    supermyguel
    Participant
    Average

    Buonasera

    Ho creato un TS in cui l’apertura delle posizioni (sia long che short) è su timeframe 5minuti.

    Una seconda parte del codice prevede l’uscita di metà posizione ad un determinato livello e contestualmente fissa la chiusura dell’altra metà ad un determinato parametro in base ad high e low.

    Il codice intero su TF 5minuti funziona perfettamente….non riesco però ad assegnare TF1 minuto per la seconda parte. E’ un’istruzione possibile?

    if not onmarket then
    halfposition=0
    endif
    
    if time >= StartE And time <= StartL and OTD then 
    IF miacondizione1 then
    buy N shares AT MARKET
    halfposition=1
    SET STOP %LOSS 0.92
    //SET STOP PTRAILING TSL
    SET TARGET %PROFIT 0.98
    else
    if miacondizione2 then
    sellshort N shares at market
    halfposition=1
    SET STOP %LOSS 0.92
    //SET STOP PTRAILING TSL
    SET TARGET %PROFIT 0.98
    endif
    endif
    endif
    
    //DA QUA IN AVANTI DEVE ESSERE TIMEFRAME 1M//
    
    partial=(N/2)
    chiusuraparziale= (positionprice*10000*0.0025)
    livellolong=  (close-positionprice)*10000
    livelloshort= (positionprice-close)*10000
    
    if not onmarket then
    massimo=0
    minimo=0
    endif
    
    If longonmarket and halfposition=2 and high > massimo then
    massimo = high
    endif
    If shortonmarket and halfposition=2 and low<minimo then
    minimo = low
    endif
    
    If halfposition=1 then
    If longonmarket and livellolong*pipsize > chiusuraparziale*pipsize then
    sell partial shares at market
    halfposition=2
    massimo=high
    endif
    If shortonmarket and livelloshort*pipsize > chiusuraparziale*pipsize  then
    exitshort partial shares at market
    halfposition=2
    minimo=low
    endif
    endif
    
    If Not OnMarket Then
    NewSL = 0
    endif
    if longonmarket and halfposition=2 Then
    NewSL = positionprice+(5*pipsize)
    endif
    if shortonmarket and halfposition=2 then
    NewSl=positionprice-(5*pipsize)
    endif
    
    
    If newSL>0  then
    if longonmarket then
    newSL= max (newSL, (massimo-(17*pipsize)))
    elsif shortonmarket then
    newSL=min (newSL, (minimo+(17*pipsize)))
    Endif
    endif
    
    //timeframe (1mn)
    If NewSL > 0 Then
    SELL at NewSL Stop
    EXITSHORT at NewSL Stop
    Endif
    #159647 quote
    robertogozzi
    Moderator
    Master

    Se hai già indicato TIMEFRAME(5 minute,UpdateOnClose) nella prima parte, basta che metti:

    TIMEFRAME(default)

    alla riga 23.

    Se non l’hai indicato, dovrai indicare all’inizio (subito dopo i vari DEFPARAM… se ne hai messi):

    TIMEFRAME(5 minute,UpdateOnClose)

    C’è solo un problema, NON puoi usare le stesse variabili in diversi timeframe. Quindi HALFPOSITION (e anche altre, se ci sono) non puoi usarla sia sul 5 minuti che su 1 minuto.

    Se cerchi MTF o MULTI TIME FRAME, potrai trovare articoli del Blog, post e moltissimi codici che usano più TF nel codice per capire come fare.

    #159653 quote
    supermyguel
    Participant
    Average

    Grazie Roberto (come sempre disponibilissimo….)

    Assegnando una variabile alternativa ad HALFPOSITION sono riuscito a far “digerire” il TF.

    Quando faccio il backtest noto che, ad esempio per il mese corrente, entra in posizione un giorno si e dieci no….. mentre se faccio il test con il TF 5 minuti entra ogni giorno.

    Se non sbaglio la riduzione del TF genera meno storicità ma non dovrebbe influenzare gli altri TF? Cioè se faccio un test con 10k candele 5 minuti o 50k 1 minuto l’apertura delle posizioni dovrebbe essere la medesima? E dovrebbe essere solo la chiusura parziale/totale ad essere diversa giusto?

    #159669 quote
    robertogozzi
    Moderator
    Master

    No, non può essere la stessa, perché sono diverse le uscite, quindi può capitare che sul 5 minuti la posizione risulti ancora aperta, mentre su 1 minuti si era chiusa 3-4 minuti prima.

    Non è possibile fare un confronto, puoi forse andarci vicino, ma non di più.

    #159671 quote
    supermyguel
    Participant
    Average

    Quello che non capisco è perchè le APERTURE sono diverse….. in entrambi le versioni (tutto 5m o 5m/1m) il timeframe di riferimento per entrare long/short è il 5 minuti quindi dovrebbero essere le stesse….e differenziarsi sulle chiusure (che è quello che certo difatti)

    Ma con il Tf 5+1 passano giorni e giorni senza alcuna posizione aperta…..

    #159673 quote
    robertogozzi
    Moderator
    Master

    Probabilmente dipende da come hai messo le variabili, senza il codice non so dirti.

    #159692 quote
    supermyguel
    Participant
    Average

    In allegato i codici completi con timeframe 5minuti e timeframe 5minuti+1minuti

    Grazie

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

CHIUSURA POSIZIONE SU TIMEFRAME DIVERSO


ProOrder: Trading Automatico & Backtesting

New Reply
Author
Summary

This topic contains 6 replies,
has 2 voices, and was last updated by supermyguel
5 years ago.

Topic Details
Forum: ProOrder: Trading Automatico & Backtesting
Language: Italian
Started: 01/27/2021
Status: Active
Attachments: 2 files
Logo Logo
Loading...