Breakeven Stop non mantenuto

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #184774 quote
    elfuego77
    Participant
    Junior

    Ciao a tutti, ho inserito la seguente parte di codice portare lo stop in pari dopo un tot di punti. Nel caso di specie, sul mio TS, lo stop è a 90 ed il target a 100.

    Il sistema è entrato, andato a favore di mercato, superato i 50 punti richiesti, lo stop è stato messo sul livello di entry +5. Non è arrivato a target, il mercato ha ritracciato ad un certo punto e mentre veniva giù anche lo stop si è spostato tornando a punto di partenza.

    Dov’è l’errore? Grazie anticipatamente per il l’aiuto.

     

    Startbreakeven=50
    Pointstokeep=5
    If NOT Onmarket then
    breakevenlevel=0
    endif
    If longonmarket and close-tradeprice(1) >= startbreakeven*1 then //
    breakevenlevel = tradeprice(1)+Pointstokeep*1
    If breakevenlevel>0 then
    sell at breakevenlevel stop
    endif
    endif

    If shortonmarket and tradeprice(1)-close>= startbreakeven*1 then//indica un euro a punto per i contratti grandi va modificato
    breakevenlevel= tradeprice(1)-Pointstokeep*1
    If breakevenlevel>0 then
    exitshort at breakevenlevel stop
    endif
    endif

    #184776 quote
    robertogozzi
    Moderator
    Master

    Non moltiplicare POINTSTOKEEP per 1, ma per PIPSIZE, per essere sicuro che funzioni su ogni strumento/asset.
    Eccolo modificato:

    Startbreakeven=50
    Pointstokeep=5
    If NOT Onmarket then
    breakevenlevel=0
    endif
    if breakevenlevel = 0 then
    If longonmarket and close-tradeprice(1) >= startbreakeven*pipsize then //
    breakevenlevel = tradeprice(1)+Pointstokeep*1
    sell at breakevenlevel stop
    endif
    If shortonmarket and tradeprice(1)-close>= startbreakeven*pipsize then//indica un euro a punto per i contratti grandi va modificato
    breakevenlevel= tradeprice(1)-Pointstokeep*1
    exitshort at breakevenlevel stop
    endif
    endif
    #184993 quote
    elfuego77
    Participant
    Junior

    Grazie Mille Roberto. Ho modificato come indicato ma succede sempre la stessa cosa ed in particolare che lo stop viene spostato dopo 50 punti a 5 punti di TP. Se però il mercato ritraccia viene nuovamente rispostato al punto di origine se poi continua nella sua direzione lo sposta nuovamente. Quindi il problema è che lo sposta ma poi non lo mantiene… Come si deve fare per far si che quando lo sposta in pari rimanga li?

    #185027 quote
    fifi743
    Participant
    Master
    Startbreakeven=50
    Pointstokeep=5
    If NOT Onmarket then
    breakevenlevel=0
    endif
    if breakevenlevel = 0 then
    If longonmarket and close-tradeprice(1) >= startbreakeven*pipsize then //
    breakevenlevel = tradeprice(1)+Pointstokeep*1
    
    endif
    If shortonmarket and tradeprice(1)-close>= startbreakeven*pipsize then//indica un euro a punto per i contratti grandi va modificato
    breakevenlevel= tradeprice(1)-Pointstokeep*1
    
    endif
    if breakevenlevel > 0 then 
    sell at breakevenlevel stop
    exitshort at breakevenlevel stop
    endif

    prova questo

    #185039 quote
    elfuego77
    Participant
    Junior

    Provato con le modifiche, il problema rimane… Lo stop torna al punto di partenza in caso di ritracciamento… @Roberto Gozzi hai qualche suggerimento su come e cosa modificare?

    #185040 quote
    phoentzs
    Participant
    Master

    Uso questo e un codice simile in tutti i miei sistemi e funziona davvero bene. Forse c’è un bug nel tuo codice di sistema?

    #185059 quote
    robertogozzi
    Moderator
    Master

    Posta il codice completo, e indica su quale strumento e timeframe lo hai utilizzazto.

    Meglio se indichi anche una data ed un’ora di una o più operazioni errate.

    #185092 quote
    elfuego77
    Participant
    Junior

    Mercato DAX. E’ entrato correttamente alle 9.48 del 11.01.2022, il mercato è salito ha messo lo stop in pari dopo 40 punti non ha raggiunto il target ha ritracciato e lo stop lo ha spostato a punto di partenza.

     

     

    defparam FLATBEFORE =090000
    defparam FLATAFTER = 173000
    defparam CUMULATEORDERS= false

    TIMEFRAME (DAILY,UPDATEONCLOSE)
    cond1=AverageTrueRange[14](close)
    Cond2=AverageTrueRange[8](close)
    Condlong=cond1>cond2
    Condshort=cond2>cond1

    TIMEFRAME(1mn,UPDATEONCLOSE)
    ST = Supertrend[3,10]
    Long= close crosses over ST and Condlong
    Short = close crosses under ST and Condshort

    Once Contratto = 1
    Once Minimo = 1
    If StrategyProfit > StrategyProfit[1] then
    Contratto = max(Minimo,Contratto -25) //diminuisce se la volta prima ha vinto
    ElsIf StrategyProfit < StrategyProfit[1] then
    Contratto = max(Minimo,Contratto *2) // raddoppia se la volta prima ha perso
    Endif

    if long then
    buy contratto contract at market
    elsif short then
    sellshort contratto contract at market
    endif

    Startbreakeven=40
    Pointstokeep=5
    If NOT Onmarket then
    breakevenlevel=0
    endif

    If longonmarket and close-tradeprice(1) >= startbreakeven*pipsize then
    breakevenlevel = tradeprice(1)+Pointstokeep*1
    If breakevenlevel>0 then
    sell at breakevenlevel stop
    endif
    endif

    If shortonmarket and tradeprice(1)-close>= startbreakeven*pipsize then
    breakevenlevel= tradeprice(1)-Pointstokeep*1
    If breakevenlevel>0 then
    exitshort at breakevenlevel stop
    endif
    endif

     

    SET TARGET PPROFIT 75

    SET STOP PLOSS 55

    #185122 quote
    fifi743
    Participant
    Master

    Buongiorno,
    la lettura è dall’alto verso il basso.
    lo stop deve essere sopra il breakeven e il trailling

    defparam FLATBEFORE =090000
    defparam FLATAFTER = 173000
    defparam CUMULATEORDERS= false
    
    TIMEFRAME (DAILY,UPDATEONCLOSE)
    cond1=AverageTrueRange[14](close)
    Cond2=AverageTrueRange[8](close)
    Condlong=cond1>cond2
    Condshort=cond2>cond1
    
    TIMEFRAME(1mn,UPDATEONCLOSE)
    ST = Supertrend[3,10]
    Long= close crosses over ST and Condlong
    Short = close crosses under ST and Condshort
    
    Once Contratto = 1
    Once Minimo = 1
    If StrategyProfit > StrategyProfit[1] then
    Contratto = max(Minimo,Contratto -25) //diminuisce se la volta prima ha vinto
    ElsIf StrategyProfit < StrategyProfit[1] then
    Contratto = max(Minimo,Contratto *2) // raddoppia se la volta prima ha perso
    Endif
    
    if long then
    buy contratto contract at market
    elsif short then
    sellshort contratto contract at market
    endif
    SET TARGET PPROFIT 75
    SET STOP PLOSS 55
    Startbreakeven=40
    Pointstokeep=5
    If NOT Onmarket then
    breakevenlevel=0
    endif
    
    If longonmarket and close-tradeprice(1) >= startbreakeven*pipsize then
    breakevenlevel = tradeprice(1)+Pointstokeep*1
    endif
    If breakevenlevel>0 then
    sell at breakevenlevel stop
    
    endif
    
    If shortonmarket and tradeprice(1)-close>= startbreakeven*pipsize then
    breakevenlevel= tradeprice(1)-Pointstokeep*1
    endif
    If breakevenlevel>0 then
    exitshort at breakevenlevel stop
    
    endif
    
     
    
    
    robertogozzi thanked this post
    #185132 quote
    elfuego77
    Participant
    Junior

    Grazie!!!

    #185233 quote
    elfuego77
    Participant
    Junior

    Ho provato con le modifiche suggerite il problema rimane. Lo stop viene spostato ma se poi il mercato ritraccia viene riportato al punto di partenza. Poi se i prezzi tornano nella direzione giusta viene rimesso in pari. Dunque il problema è che il sistema non tiene fisso il nuovo livello di stop in pari. E’ evidente che sia un errore di calcolo/programmazione. Dov’è l’errore?

    #185281 quote
    robertogozzi
    Moderator
    Master

    Scusami, ma come pensi di farla girare questa strategia?

    In meno di 2 mesi apre un’operazione con oltre 5.47 milioni di contratti!?

    A parte il fatto che ti servirebbero miliardi di capitale (che nessun broker potrebbe sopportare), credo che tu abbia voluto incrementare i contratti ma abbia fatto qualche errore di calcolo.

    Se mi spieghi i dettagli su quando incrementare/decrementare magari posso aiutarti a correggerli.

    Io ho fatto le prove mettendo 1 alle righe 16 e 18, ma ti ho lasciato le tue originali accanto, basta che togli 1 e le due barre dei commenti.

    Adesso funziona, ho spostato le uscite FUORI dal calcolo del trailing stop:

    efparam FLATBEFORE =090000
    defparam FLATAFTER = 173000
    defparam CUMULATEORDERS= false
    TIMEFRAME (DAILY,UPDATEONCLOSE)
    cond1=AverageTrueRange[14](close)
    Cond2=AverageTrueRange[8](close)
    Condlong=cond1>cond2
    Condshort=cond2>cond1
    TIMEFRAME(1mn,UPDATEONCLOSE)
    ST = Supertrend[3,10]
    Long= close crosses over ST and Condlong
    Short = close crosses under ST and Condshort
    Once Contratto = 1
    Once Minimo = 1
    If StrategyProfit > StrategyProfit[1] then
    Contratto = 1//max(Minimo,Contratto -25) //diminuisce se la volta prima ha vinto
    ElsIf StrategyProfit < StrategyProfit[1] then
    Contratto = 1//max(Minimo,Contratto *2) // raddoppia se la volta prima ha perso
    Endif
    if long then
    buy contratto contract at market
    elsif short then
    sellshort contratto contract at market
    endif
    Startbreakeven=40
    Pointstokeep=5
    If NOT Onmarket then
    breakevenlevel=0
    endif
    If longonmarket and close-tradeprice(1) >= startbreakeven*pipsize then
    breakevenlevel = tradeprice(1)+Pointstokeep*1
    //If breakevenlevel>0 then
    //sell at breakevenlevel stop
    //endif
    endif
    If shortonmarket and tradeprice(1)-close>= startbreakeven*pipsize then
    breakevenlevel= tradeprice(1)-Pointstokeep*1
    //If breakevenlevel>0 then
    //exitshort at breakevenlevel stop
    //endif
    endif
    If breakevenlevel>0 then
    sell      at breakevenlevel stop
    exitshort at breakevenlevel stop
    endif
    SET TARGET PPROFIT 75
    SET STOP PLOSS 55
    graphonprice breakevenlevel
    graph positionperf * positionprice / pipsize AS "Profitto"
    #185300 quote
    elfuego77
    Participant
    Junior

    Ciao Roberto Grazie mille. Chiaramente è da impostare sui contratti micro… Con i contratti regolari non sarebbe sostenibile. Il -25 serve proprio per fargli scaricare i contratti perchè altrimenti sarebbe tutto sballato. Grazie ancora!!

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

Breakeven Stop non mantenuto


ProOrder: Trading Automatico & Backtesting

New Reply
Author
author-avatar
elfuego77 @elfuego77 Participant
Summary

This topic contains 12 replies,
has 4 voices, and was last updated by elfuego77
4 years, 1 month ago.

Topic Details
Forum: ProOrder: Trading Automatico & Backtesting
Language: Italian
Started: 01/06/2022
Status: Active
Attachments: No files
Logo Logo
Loading...