Chiusura parziale posizione

Viewing 14 posts - 31 through 44 (of 44 total)
  • Author
    Posts
  • #176598 quote
    MauroPro
    Participant
    Veteran

    Perfetto grazie

    #176633 quote
    MauroPro
    Participant
    Veteran

    Un dubbio: se sostituisco “PerCentGain = 0.005”  con  la formula che hai riportato:

    ONCE PipsGain = 100

    poi come devo modificare  le seguenti righe? (perchè non basta sostituire 0.005 con il 100 del PipsGain)

    IF partialclose AND LongOnMarket and close >= (PositionPrice * (1 + PerCentGain))  AND Flag THEN
    IF partialclose AND ShortOnMarket and close <= (PositionPrice * (1 PerCentGain))  AND Flag THEN
    #176651 quote
    robertogozzi
    Moderator
    Master

    Così:

    IF partialclose AND LongOnMarket  and close >= PipsGain*Pipsize  AND Flag THEN
    IF partialclose AND ShortOnMarket and close <= PipsGain*Pipsize) AND Flag THEN
    #176655 quote
    MauroPro
    Participant
    Veteran

    Ho provato il codice ma non funziona. Chiude sempre metà posizione dopo la prima barra. Prova da te se va bene, ecco il codice:

    once partialcloseGain = 1

    If partialcloseGain then
    ONCE PerCent = 0.5
    ONCE PipsGain = 100 //PUNTI
    ONCE MinLotSize = 0.5
    ExitQuantity = abs(CountOfPosition) * PerCent
    LeftQty = max(MinLotSize,abs(CountOfPosition) – ExitQuantity)
    CloseQuantity = abs(CountOfPosition) – LeftQty

    IF Not OnMarket THEN
    Flag = 1
    ENDIF

    IF partialcloseGain AND LongOnMarket and close >= pipsGain*pointSize AND Flag THEN
    SELL CloseQuantity Contracts AT Market
    Flag = 0
    endif

    IF partialcloseGain AND ShortOnMarket and close <= pipsGain*pointSize AND Flag THEN
    exitshort CloseQuantity Contracts AT Market
    Flag = 0
    endif
    endif

    #176658 quote
    robertogozzi
    Moderator
    Master

    Posta un codice funzionante.

    #176663 quote
    MauroPro
    Participant
    Veteran

    Ok. Stò riscrivendo e ripulendo profondamente un codice del forum inglese di proOrder per il Nasdaq 15minuti (così mi dici anche cosa nè pensi). Appena completato lo posto lì per dare il mio contributo. Ancora mancano delle aggiunte da provare se migliorano il TS.

    Oltre queste volevo provare anche lo split della posizione (long-short separati e poi entrambi). E’ sempre una prova.

    I codici in % li ho entrambi e funzionano, però siccome il TS in questione usa i punti, ecco il motivo per cui ti stò chiedendo queste cose, ossia la traduzione del codice in punti.

    Questo è il TS con lo split solo long 1% (ossia chiude metà posizione al target di 1%.) Prova ad usare 100 punti con le formule scambiate sopra (rif. 176651).

    Non funziona insert PRt  quindi uso il copia ed incolla.

    //TS KD Mean Reverting v2-TrP (TrP = trailingProfit) – Nasdaq 15 minuti cfd 1 contratto
    DEFPARAM CUMULATEORDERS = FALSE
    PositionSize=1
    //——————————————————
    avgHull=average[150,7] //150-7
    cVol = Volume
    volBars=15 //15
    lowBars=10 //10
    c1 = close>avgHull
    c2 = cVol < cVol[volBars]
    If close > lowest[lowBars](low) and c1 and c2 and openDayOfWeek <> 5 then
    Buy PositionSize CONTRACTS AT MARKET
    ENDIF
    //———————————————————
    SET STOP pLOSS 130 //SL 100
    SET TARGET pPROFIT 180 //TP 175
    //———————————————————
    pointToReachLong=35*pointSize // 30
    pointToKeepLong=10*pointSize // 12
    If not onMarket then
    newSL=0
    endif
    If longOnMarket then
    If newSL=0 and high-tradePrice(1)>pointToReachLong then
    newSL=tradePrice(1)+ pointToKeepLong
    endif
    If newSL>0 and close-newSL>pointToReachLong then
    newSL = newSL+pointToKeepLong
    endif
    endif
    If newSL>0 then
    sell at newSL STOP
    endif
    //————————————————————
    myrsiM5=rsi[14](close)
    if myrsiM5<30 and longonmarket and close>positionprice then
    sell at market
    endif
    if myrsiM5>70 and shortonmarket and close<positionprice then
    exitshort at market
    endif
    //—————————————————————-
    once partialcloseGain = 1
    If partialcloseGain then
    ONCE PerCent = 0.5 //close 1/2 size
    ONCE PerCentGain = 0.01 // = 1%
    ONCE MinLotSize = 0.5
    ExitQuantity = abs(CountOfPosition) * PerCent
    LeftQty = max(MinLotSize,abs(CountOfPosition) – ExitQuantity)
    CloseQuantity = abs(CountOfPosition) – LeftQty

    IF Not OnMarket THEN
    Flag = 1
    ENDIF
    IF partialcloseGain AND LongOnMarket and close >= (PositionPrice * (1 + PerCentGain)) AND Flag THEN
    SELL CloseQuantity Contracts AT Market
    Flag = 0
    endif
    IF partialcloseGain AND ShortOnMarket and close <= (PositionPrice * (1 – PerCentGain)) AND Flag THEN
    exitshort CloseQuantity Contracts AT Market
    Flag = 0
    endif
    endif
    //————————————————————————————————————————————-

    #176667 quote
    robertogozzi
    Moderator
    Master

    Avevo fatto un paio di errori logici.

    Sostituisci tutte le righe, dalla 42 fino alla fine, con queste:

    once partialcloseGain = 1
    If partialcloseGain then
    ONCE PerCent = 0.5 //close 1/2 size
    ONCE PerCentGain = 0.001 //0.1%    = 1%
    ONCE MinLotSize = 0.5
    PipsGain = 100//PositionPrice * PerCentGain / PipSize
    ExitQuantity = abs(CountOfPosition) * PerCent
    LeftQty = max(MinLotSize,abs(CountOfPosition) - ExitQuantity)
    CloseQuantity = max(0,abs(CountOfPosition) - LeftQty)
    TempGain = PositionPerf * PositionPrice / PipSize
    IF Not OnMarket THEN
    Flag = 1
    ENDIF
    IF partialcloseGain AND LongOnMarket and TempGain >= PipsGain*pipsize AND Flag THEN
    SELL CloseQuantity Contracts AT Market
    Flag = 0
    endif
    IF partialcloseGain AND ShortOnMarket and TempGain >= PipsGain*pipsize AND Flag THEN
    exitshort CloseQuantity Contracts AT Market
    Flag = 0
    endif
    endif
    //————————————————————————————————————————————-
    //graphonprice PositionPrice                                  coloured(0,0,255,255)
    //graphonprice PositionPrice + (PositionPerf * PositionPrice) coloured(255,0,0,255)
    //graphonprice PositionPrice * (1 + PerCentGain)              coloured(0,255,0,255)
    //graph abs(CountOfPosition)                                  coloured(255,0,0,255)
    //graph LeftQty
    //Graph CloseQuantity
    //graph PositionPrice * PositionPerf / PipSize
    //graph PipsGain
    #176668 quote
    robertogozzi
    Moderator
    Master

    Qui faccio riferimento al numero di riga della parte che ho postata (il resto non l’ho modificato).

    Alla riga 6 ho messo 100. Se lo lasci così va bene anche ONCEdavanti, ma se togli 100 e lasci la riga dopo i commenti ONCE non va messo, perché il calcolo va fatto ad ogni barra. Quindi conviene non usare ONCE su questa riga.

    Alla riga 10 ho inserito il calcolo, in Pips, del profitto temporaneo (corrente), che serve per fare il confronto alle righe 14 e 18, righe che ho modificato per usare i Pips.

    #176670 quote
    MauroPro
    Participant
    Veteran
    OK ora funziona bene! Puoi fare anche la parte per lo split della perdita in punti? (dovrebbe essere una piccola modifica). E’ il corrispettivo in punti del secondo (B) di questi codici in % (verificati) (vd sotto)  che posto come sintesi per gli utenti del forum.  

    CODICE PER SPLITTARE UNA POSIZIONE

    //A splittare una posizione long

    once partialcloseGain = 1 If partialcloseGain then ONCE PerCent = 0.5 //close 1/2 size ONCE PerCentGain = 0,01 //0,01 = 1% – 0.005 = 0.5% ONCE MinLotSize = 0.5 ExitQuantity = abs(CountOfPosition) * PerCent LeftQty = max(MinLotSize,abs(CountOfPosition) – ExitQuantity) CloseQuantity = abs(CountOfPosition) – LeftQty   IF Not OnMarket THEN Flag = 1 ENDIF   IF partialcloseGain AND LongOnMarket and close >= (PositionPrice * (1 + PerCentGain)) AND Flag THEN SELL CloseQuantity Contracts AT Market Flag = 0 endif IF partialcloseGain AND ShortOnMarket and close <= (PositionPrice * (1 – PerCentGain)) AND Flag THEN exitshort CloseQuantity Contracts AT Market Flag = 0 endif endif //———————————————————————————————- //B splittare una posizione short once partialcloseLoss = 1 If partialcloseLoss then ONCE PerCent = 0.5 //close ½ size ONCE PerCentLoss = 0,01 //0,01 = 1% – 0.005 = 0.5% ONCE MinLotSize = 0.5 ExitQuantity = abs(CountOfPosition) * PerCent LeftQty = max(MinLotSize,abs(CountOfPosition) – ExitQuantity) CloseQuantity = abs(CountOfPosition) – LeftQty   IF Not OnMarket THEN Flag = 1 ENDIF   IF partialcloseLoss AND LongOnMarket and close <= (PositionPrice * (1 – PerCentLoss)) AND Flag THEN SELL CloseQuantity Contracts AT Market Flag = 0 endif IF partialcloseLoss AND ShortOnMarket and close >= (PositionPrice * (1 + PerCentLoss)) AND Flag THEN exitshort CloseQuantity Contracts AT Market Flag = 0 endif endif //————————————————————————————–
    #176674 quote
    robertogozzi
    Moderator
    Master
    E’ quella che ho postato sopra. Alla riga 6 ho messo i punti ed ho variato le righe 14 e 18.
    #176684 quote
    MauroPro
    Participant
    Veteran
    La formula riportata con i punti splitta correttamente una posizione VINCENTE long o short, proprio come fa il codice A, in percentuale, sopra riportato. Vorrei invece modificare il tuo codice in punti come il codice B, ossia splittare una posizione PERDENTE long o short. Praticamente: quando una posizione long o short (magari con uno SL in punti di 200 punti) perde 100 punti splitta in due la posizione.
    #176685 quote
    MauroPro
    Participant
    Veteran
    ho fatto un errore nello scrivere velocemente i rem iniziali del codice in %: il codice A splitta una posizione vincente (long o short che sia) e NON una long il codice B splitta una posizione perdente (long o short che sia) e NON una short
    #176690 quote
    MauroPro
    Participant
    Veteran
    Ciao Roberto, ho creato questo per lo split in punti di posizioni perdenti (modificando il tuo codice sopra – rif. 176667 – per lo split in punti di posizioni vincenti). Sembra che funzioni. Volevo solo sapere se è logicamente corretto (dato che è stata una prova empirica più che logica!) chiudendo così questo topic. once partialcloseLoss = 1 If partialcloseLoss then ONCE PerCent = 0.5 //close 1/2 size PipsLoss = -100 //PositionPrice * PerCentGain / PipSize ONCE MinLotSize = 0.5 ExitQuantity = abs(CountOfPosition) * PerCent LeftQty = max(MinLotSize,abs(CountOfPosition) – ExitQuantity) CloseQuantity = max(0,abs(CountOfPosition) – LeftQty) TempGain = PositionPerf * PositionPrice / PipSize IF Not OnMarket THEN Flag = 1 ENDIF IF partialcloseLoss AND LongOnMarket and TempGain <= PipsLoss*pipsize AND Flag THEN SELL CloseQuantity Contracts AT Market Flag = 0 endif IF partialcloseLoss AND ShortOnMarket and TempGain <= PipsLoss*pipsize AND Flag THEN exitshort CloseQuantity Contracts AT Market Flag = 0 endif endif
    #176696 quote
    robertogozzi
    Moderator
    Master
    Alle righe 14 e 18  del mio post basta che verifichi se sono in perdita:
    and TempGain <= -PipsLoss*pipsize AND
    dovrai mettere nella variabile PipsLoss i pips di perdita a cui chiudere la prima parte.
    MauroPro thanked this post
Viewing 14 posts - 31 through 44 (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, 6 months ago.

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