Sostituire set target % profit X

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #201891 quote
    MauroPro
    Participant
    Veteran

    Ciao Roberto, ho provato a sostituire set target %profit X in una banale formule (test su cfd  Dax  1 ora) ma i risultati non sono equivalenti. Probabilmente c’è qualche difformità nel calcolo della percentuale rggiunta nella formula B  (ho provato a cambiare close con high, ma rimangono risultati differenti).

    Puoi controllare? Grazie

    A)

    defParam cumulateOrders = false
    cLong = close crosses over average[50](close)
    if not longOnMarket and cLong then
    buy 1 contract at market
    set stop %loss 1
    set target %profit 1.5
    endif

    B)

    defParam cumulateOrders = false
    cLong = close crosses over average[50](close)
    if not longOnMarket and cLong then
    buy 1 contract at market
    set stop %loss 1
    //set target %profit 1.5
    endif

    targetLong = (close*1.5/100)/pointSize
    If not longOnMarket then
    myExit = 0
    endif
    If longOnMarket and (close – tradePrice) > targetLong then
    myExit = tradePrice + targetLong
    endif
    if myExit > 0 then
    sell at myExit STOP
    endif

    #201899 quote
    robertogozzi
    Moderator
    Master

    Vedo che alla riga 14 verifichi se il target è stato superato, dopodichè piazzi un ordine d’uscita STOP.Scusami, se hai già superato il terget dovresti uscire, perché attendere che il prezzo torni indietro?

    Alla riga 10 dovresti usare

    targetLong = (close*1.5/100) // /pointSize

    in quanto lavori sul prezzo, non sui pips (nel caso di quasi tutti gli indici, al contrario del Forex,  questo può non avere conseguenze, ma è logicamente inesatto).

    La riga 10 devi spostarla all’interno di IF…ENDIF (cambiando anche la condizione). Inoltre l’uscita è in LIMIT, non STOP, in quanto esci ad un prezzo più vantaggioso rispetto a quello corrente al momento in cui l’ordine viene piazzato.

    Anche la variabile TradeLong non serve, puoi usare solo myExit:

    // A
    defParam cumulateOrders = false
    cLong = close crosses over average[50](close)
    //
    if not longOnMarket and cLong then
       buy 1 contract at market
       set stop %loss 1
       set target %profit 1.5
       myExit = close*1.015////myExit = 0
    endif
    //
    graphonprice myEXit
    // B
    defParam cumulateOrders = false
    cLong = close crosses over average[50](close)
    if not longOnMarket and cLong then
       buy 1 contract at market
       set stop %loss 1
       //set target %profit 1.5
       myExit = close*1.015
    endif
    if LongOnMarket then
       sell at myExit LIMIT
    endif
    //
    graphonprice myEXit

    nonostante le modifiche una differenza resta (l’ho provati su 200K unità e ci sono oltre 2K euro di differenza). Ho provato anche ad usare una volta 2 come spread ed una volta 0, ma non cambia.
    Provo a fare altre verifiche e ti farò sapere.

    #201902 quote
    MauroPro
    Participant
    Veteran

    ok grazie

    #201903 quote
    MauroPro
    Participant
    Veteran

    Già a 5 k con spread = 1 si vede come nella versione B (quella senza set target…), quasi in ogni operazione profittevole si perde qualcosa.

    L’importante è capire quale è più vicina all’operatività reale (quella B in ogni caso essendo svantaggiata è più attendibile).

    #201910 quote
    robertogozzi
    Moderator
    Master

    Aggiungendo un ordine pendente di uscita immediatamente subito dopo il BUY, riduce molto il divario (testato sempre su 200K, Dax, H1).
    Resta ancora una differenza. Cercherò di saperne di più.
    Ecco il nuovo codice B:

    // B
    if not longOnMarket and cLong then
       buy 1 contract at market
       set stop %loss 1
       //set target %profit 1.5
       myExit = close*1.015
       sell at myExit LIMIT
    endif
    if LongOnMarket then
       sell at myExit LIMIT
    endif
    graphonprice myEXit
    MauroPro thanked this post
    #201913 quote
    MauroPro
    Participant
    Veteran

    Ho visto che in questo modo si riduce il divario. Non capisco però il motivo, non sono due ordini limite uguali?

    La formula con set ho visto che chiude idealmente, forse in modo irreale dal vivo,  sempre con il target a 1.5%, mentre le altre formule chiudono anche a 1.49%, ma anche, ultima tua formula,  a 1.64% (15 marzo 2019)   o 1.44% (31 dicembre 2018).  Vd immagine ( a sx l’ultima formula, a destra quella con “set”).

    PS: In generale ho notato, anche in altri codici di TS complessi, che le istruziioni “set” tendono a performare nei backtest di più di quelle cotruite.

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

Sostituire set target % profit X


ProOrder: Trading Automatico & Backtesting

New Reply
Author
author-avatar
MauroPro @mauropro Participant
Summary

This topic contains 5 replies,
has 2 voices, and was last updated by MauroPro
3 years, 4 months ago.

Topic Details
Forum: ProOrder: Trading Automatico & Backtesting
Language: Italian
Started: 10/04/2022
Status: Active
Attachments: 2 files
Logo Logo
Loading...