Chiusura parziale posizione

Viewing 15 posts - 16 through 30 (of 44 total)
  • Author
    Posts
  • #174429 quote
    MauroPro
    Participant
    Veteran

    Il TS base (long) SI in quanto non ha split.

    Il primo codice (long) NO: chiude troppo presto il secondo contratto.

    Il secondo codice (long) NO: spesso è corretto, ma a volte chiude la posizione in 3 parti e non in due (ma temporalmente, sia che splitta correttamente in due parti, che erroneamente in 3 parti, rispetta sempre il tempo del TS base per la chiusura completa della posizione).

    #174430 quote
    MauroPro
    Participant
    Veteran

    [attachment file=”174431″]

    Image-002-2.jpg Image-002-2.jpg
    #174435 quote
    MauroPro
    Participant
    Veteran

    Secondo esempio

    Image-003.jpg Image-003.jpg
    #174438 quote
    robertogozzi
    Moderator
    Master

    Dimmi quale codice vuoi che controlli e in che data ed ora (e strumento e TF) è iniziato un trade errato.

    Non posso eseguire tutti i codici e analizzare tutte le operazioni, ma solo quelle errate che mi segnali. E’ inutile che controlli quelle corrette.

    #174440 quote
    MauroPro
    Participant
    Veteran

    Partiamo da:

    2 codice (solo long, riportato sopra nell’elenco per ultimo) –

    data 29 giugno 2021 (ultima foto sopra nel secondo esempio) ora apertura posizione: 7:45 -TF 15 minuti – Cdf Dax

    Tipo di error: ci sono 3 chiusure in split

    #174456 quote
    robertogozzi
    Moderator
    Master

    Io ho usato quete righe per il debugging:

    graphonprice (PositionPrice * (1 + (PerCentGain * Increments)))[1] AS "Uscita Parziale"
    graphonprice positionprice coloured(0,0,255,255)
    graph abs(countofposition)
    graph (PerCentGain * Increments)[1] AS "PerCentGain * Increments"
    graph ExitQuantity
    graph CloseQuantity
    #174470 quote
    MauroPro
    Participant
    Veteran

    I due codici sopra non funzionano, ognuno ha i problemi già descritti che non sono stati sistemati.

    Ho risolto ristudiando lo snippetcode 286. Bastava settare come vero il flag iniziale.

    #174471 quote
    MauroPro
    Participant
    Veteran

    Ecco il codice corretto, da aggiungere in fondo al proprio Ts per splittare la posizione:

    once partialclose = 1                                        //N.B. nello snippet questa variabile è posta a 0, ma cosi non si ottiene nessuno split della posizione!

    If partialclose then
    ONCE PerCent = 0.5 //0.1 = 10% positions to close
    ONCE PerCentGain = 0.005 //0.005 = 0.5% gain
    ONCE MinLotSize = 0.5 //IG minimum
    ExitQuantity = abs(CountOfPosition) * PerCent
    LeftQty = max(MinLotSize,abs(CountOfPosition) – ExitQuantity)
    CloseQuantity = abs(CountOfPosition) – LeftQty

    IF Not OnMarket THEN
    Flag = 1
    ENDIF

    IF partialclose AND LongOnMarket and close >= (PositionPrice * (1 + PerCentGain)) AND Flag THEN
    SELL CloseQuantity Contracts AT Market
    Flag = 0
    endif

    IF partialclose AND ShortOnMarket and close <= (PositionPrice * (1 – PerCentGain)) AND Flag THEN
    exitshort CloseQuantity Contracts AT Market
    Flag = 0
    endif
    endif
    //—————————————————–
    GRAPHONPRICE (PositionPrice * (1 + PerCentGain)) coloured(0,255,0,255) AS “ProfittoL”
    GRAPHONPRICE (PositionPrice * (1 – PerCentGain)) coloured(255,0,0,255) AS “ProfittoS”
    graph abs(countofposition)

    Image-002-3.jpg Image-002-3.jpg
    #174473 quote
    robertogozzi
    Moderator
    Master

    Mancava la prima metà della risposta al mio post, non so cosa ho fatto, ma è sparita.

    Ad ogni modo:

    • ha aperto una posizione
    • ne ha chiusa metà (1)
    • ne ha chiusa un’altra metà (0.5)
    • ha chiuso tutto all’orario DEFPARAM

    Mi pare tutto corretto.

    #174636 quote
    MauroPro
    Participant
    Veteran

    Ciao Roberto, conosci un modo per ottimizzare cifre piccole come il PerCentGain, che  è 0.005?

    #174638 quote
    robertogozzi
    Moderator
    Master

    Come al solito, puoi scrivere:

    a)  da 0.001

    b)    a  0.010

    c) passo 0.001   (10 combinazioni)

    oppure

    c)  passo 0.0001   (100 combinazioni)

    #174652 quote
    MauroPro
    Participant
    Veteran

    Ok funziona, mi sembrava che lo zero iniziale non andava bene (come per l’ottimizzazione del tempo in cui va tolto).

    Un ultima cosa:  la formula (la riporto per semplicità) si potrebbe modificare  in modo tale  da utilizzarla NON per chiudere metà posizione in gain, ma per chiudere metà posizione in perdita, es. dello  -0.005 (e l’altra metà secondo lo  stop loss % del TS )?

    In teoria non dovrebbe essere difficile, ma ancora non sono pratico con queste operazioni di split. Grazie

    once partialclose = 1
    
    If partialclose then
    ONCE PerCent     = 0.5                           //0.1 = 10%  positions to close
    ONCE PerCentGain = 0.005                        //0.005 = 0.5% gain
    ONCE MinLotSize  = 0.5                          //IG minimum
    ExitQuantity     = abs(CountOfPosition) * PerCent
    LeftQty          = max(MinLotSize,abs(CountOfPosition) - ExitQuantity)
    CloseQuantity    = abs(CountOfPosition) - LeftQty
     
    IF Not OnMarket THEN
    Flag = 1
    ENDIF
     
    IF partialclose AND LongOnMarket and close >= (PositionPrice * (1 + PerCentGain))  AND Flag THEN
    SELL CloseQuantity Contracts AT Market
    Flag = 0
    endif
    
    IF partialclose AND ShortOnMarket and close <= (PositionPrice * (1 - PerCentGain))  AND Flag THEN
    exitshort CloseQuantity Contracts AT Market
    Flag = 0
    endif
    endif
    //-----------------------------------------------------
    //GRAPHONPRICE (PositionPrice * (1 + PerCentGain)) coloured(0,255,0,255) AS "ProfittoL"
    //GRAPHONPRICE (PositionPrice * (1 - PerCentGain)) coloured(255,0,0,255) AS "ProfittoS"
    //graph abs(countofposition)raph cLong   coloured(0,128,0)
    #174660 quote
    robertogozzi
    Moderator
    Master

    Perché nelle ore è numericamente superfluo a sinistra, ma non quello accanto al punto decimale/virgola.

    0.01 resta così mentre 01.32 diventa 1.32.

    Si, basta cambiare le righe 15 e 20 così:

    IF partialclose AND LongOnMarket and close <= (PositionPrice * (1 - PerCentGain))  AND Flag THEN  //riga 15
    IF partialclose AND ShortOnMarket and close >= (PositionPrice * (1 + PerCentGain))  AND Flag THEN //riga 20
    MauroPro thanked this post
    #176596 quote
    MauroPro
    Participant
    Veteran

    Ciao Roberto, riesci a convertire (se non è troppo complicato) la riga 5 del codice sopra riportato (riferimento 174652) da percentuale a punti?

    La riga è questa:

    ONCE PerCentGain = 0.005                        //0.005 = 0.5% gain     (vorrei, ad esempio, chiudere metà posizione dopo un guadagno di 100 punti e NON del 0.5%)

    Grazie

    #176597 quote
    robertogozzi
    Moderator
    Master

    Puoi farlo direttamente:

    ONCE PipsGain = 100      //100 pips

    oppure, se prefrisci indicare una percentuale e poi convertirla in punti:

    ONCE PerCentGain = 0.005                                 //0.005 = 0.5%
    ONCE PipsGain    = PositionPrice * PerCentGain / PipSize //Pips
    MauroPro thanked this post
Viewing 15 posts - 16 through 30 (of 44 total)
  • You must be logged in to reply to this topic.

Chiusura parziale posizione


ProOrder: Trading Automatico & Backtesting

New Reply
Author
author-avatar
MauroPro @mauropro Participant
Summary

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

Topic Details
Forum: ProOrder: Trading Automatico & Backtesting
Language: Italian
Started: 07/29/2021
Status: Active
Attachments: 6 files
Logo Logo
Loading...