Entrata long o short su sfondamento MIn/Max premercato su ritracciamento

Viewing 15 posts - 1 through 15 (of 39 total)
  • Author
    Posts
  • #199850 quote
    Enrico
    Participant
    New

    Buona sera a tutti avrei bisogno di ottimizzare  il codice che vi posto.

    Deve avvenire  un nuovo max/min dopo lo sfondamento del livello “min/max premarket”,

    Entrata in posizione con ordine limit quando il prezzo rimbalza sulla media esponenziale 13 periodi.

    Prendere profitto all’1% per metà della posizione.

    portare lo stop su livello di entrata.

    // Definizione dei parametri del codice
    DEFPARAM CumulateOrders = False // Posizioni cumulate disattivate
    // Il sistema cancellerà tutti gli ordini in attesa e chiuderà tutte le posizioni a 0:00. Dopo l'orario "Flat Before" non saranno piazzati nuovi ordini o posizioni.
    DEFPARAM FLATBEFORE = 153000
    // Cancellare tutti gli ordini in attesa e chiudere tutte le posizioni all'orario "Flat After"
    DEFPARAM FLATAFTER = 163000
    
    // Impedisce al sistema di tradare in giorni specifici della settimana
    daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
    OTD = (Barindex - TradeIndex(1) > IntradayBarIndex)
    // Condizioni per entrare su posizioni long
    indicator1, ignored = CALL "max/min premarket"
    c1 = (close > indicator1)
    
    IF c1 AND not daysForbiddenEntry and OTD THEN
    BUY 10000 CASH AT MARKET
    ENDIF
    
    // Condizioni per uscire da posizioni long
    indicator2 = SuperTrend[4,52]
    c2 = (close CROSSES UNDER indicator2)
    
    IF c2 THEN
    SELL AT MARKET
    ENDIF
    
    // Condizioni per entrare su posizioni short
    ignored, indicator3 = CALL "max/min premarket"
    c3 = (close < indicator3)
    
    IF c3 AND not daysForbiddenEntry and OTD THEN
    SELLSHORT 10000 CASH AT MARKET
    ENDIF
    
    // Condizioni per uscire da posizioni short
    indicator4 = SuperTrend[4,52]
    c4 = (close CROSSES OVER indicator4)
    
    IF c4 THEN
    EXITSHORT AT MARKET
    ENDIF
    
    // Stop e target
    SET STOP %LOSS 1
    SET TARGET %PROFIT 1
    

    Grazie in anticipo.

    #199881 quote
    robertogozzi
    Moderator
    Master

    L’ordine LIMIT a quale prezzo deve entrare?

    #199889 quote
    Enrico
    Participant
    New

    Buon giorno, l’ordine limit deve avvenite quando il prezzo rimbalza sulla media esponenziale 13 periodi. praticamente appena ci sono le prime condizioni si mette un ordine allo stesso prezzo della media mobile e si aspetta che il mercato se lo vada a prendere.

    grazie in anticipo.

    #199896 quote
    robertogozzi
    Moderator
    Master

    Per fare delle prove serve l’indicatore max/min premarket. Puoi postare il codice, oppure indicare un link sove trovarlo.

    #199902 quote
    Enrico
    Participant
    New

    IF (openTime = 220000) OR ((openTime > 220000) AND (OpenTime < OpenTime[1])) THEN
    HH = high
    LL = low
    ENDIF
    IF openTime < 153000 THEN
    HH = max(HH,high)
    LL = min(LL,low)
    ENDIF
    RETURN HH AS “massimo”,LL AS “minimo”

    #199978 quote
    robertogozzi
    Moderator
    Master

    Ecco fatto:

    // Definizione dei parametri del codice
    DEFPARAM CumulateOrders = False // Posizioni cumulate disattivate
    // Il sistema cancellerà tutti gli ordini in attesa e chiuderà tutte le posizioni a 0:00. Dopo l'orario "Flat Before" non saranno piazzati nuovi ordini o posizioni.
    DEFPARAM FLATBEFORE = 153000
    // Cancellare tutti gli ordini in attesa e chiudere tutte le posizioni all'orario "Flat After"
    DEFPARAM FLATAFTER = 163000
    once RotturaL = 0
    once EntrataL = 0
    once RotturaS = 0
    once EntrataS = 0
    if OnMarket THEN
    RotturaL = 0
    EntrataL = 0
    RotturaS = 0
    EntrataS = 0
    endif
    ema13 = average[13,1](close)
    // Impedisce al sistema di tradare in giorni specifici della settimana
    daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
    OTD = (Barindex - TradeIndex(1) > IntradayBarIndex)
    // Condizioni per entrare su posizioni long
    Massimo, Minimo = CALL "max/min premarket"
    c1 = (close crosses over Massimo)
    IF c1 THEN
    RotturaL = 1
    EntrataL = 0
    RotturaS = 0
    EntrataS = 0
    ENDIF
    IF RotturaL[1] AND (high > high[1]) THEN
    RotturaL = 2
    ENDIF
    IF RotturaL = 2 THEN
    IF (low <= Ema13) AND (close > ema13) THEN
    EntrataL = Ema13
    ENDIF
    ENDIF
    IF EntrataL > 0 AND not daysForbiddenEntry and OTD THEN
    BUY 10000 CASH AT EntrataL LIMIT
    RotturaS = 0
    EntrataS = 0
    ENDIF
    // Condizioni per uscire da posizioni long
    indicator2 = SuperTrend[4,52]
    c2 = (close CROSSES UNDER indicator2)
    IF c2 THEN
    SELL AT MARKET
    ENDIF
    // Condizioni per entrare su posizioni short
    c3 = (close crosses under Minimo)
    IF c3 THEN
    RotturaL = 1
    EntrataL = 0
    RotturaS = 1
    EntrataS = 0
    ENDIF
    IF RotturaS[1] AND (low < low[1]) THEN
    RotturaS = 2
    ENDIF
    IF RotturaS = 2 THEN
    IF (high >= Ema13) AND (close < ema13) THEN
    EntrataS = Ema13
    ENDIF
    ENDIF
    IF EntrataS > 0 AND not daysForbiddenEntry and OTD THEN
    SELLSHORT 10000 CASH AT EntrataS LIMIT
    RotturaL = 0
    EntrataL = 0
    ENDIF
    // Condizioni per uscire da posizioni short
    indicator4 = SuperTrend[4,52]
    c4 = (close CROSSES OVER indicator4)
    IF c4 THEN
    EXITSHORT AT MARKET
    ENDIF
    // Stop e target
    SET STOP %LOSS 1
    SET TARGET %PROFIT 1
    #199992 quote
    Enrico
    Participant
    New

    Mi dispiace, c’è qualcosa che non va.

    Non fa nulla di quello che ho descritto.

    Grazie comunque.

    #200019 quote
    robertogozzi
    Moderator
    Master

    Su quale strumento e timefrane l’hai provato?

    #200033 quote
    Enrico
    Participant
    New

    Azioni USA time frame 3 minuti.

    #200070 quote
    robertogozzi
    Moderator
    Master

    Ho fatto delle correzioni di un paio di errori che avevo fatto ed ho aggiunto la chiusura di metà posizione all’1% di profitto (ho messo 0 alla riga del SET TARGET PROFIT, altrimenti chiude tutto all’1%), dopodiché esce in pareggio (oppure quando ci sono le condizioni del SuperTrend, nel caso non ritracci fino al pareggio).

    Però ho avuto difficoltà a testare l’uscita del 50%, perché deve esserci qualche limite (che non conosco perché non opero su Azioni) nel tradare le azioni, in quanto ne apre un certo numero che può essere diverso di volta in volta (evidentemente le calcola in base al capitale ed al prezzo), però poi non ne chiude META’, ma un numero che non sono riuscito a capire. Probabilmente anche in questo caso ci saranno dei limiti imposti dal broker. Sul DAX ho visto che la chiusura di metà posizione funziona.

    // Definizione dei parametri del codice
    DEFPARAM CumulateOrders = False // Posizioni cumulate disattivate
    // Il sistema cancellerà tutti gli ordini in attesa e chiuderà tutte le posizioni a 0:00. Dopo l'orario "Flat Before" non saranno piazzati nuovi ordini o posizioni.
    DEFPARAM FLATBEFORE = 153000
    // Cancellare tutti gli ordini in attesa e chiudere tutte le posizioni all'orario "Flat After"
    DEFPARAM FLATAFTER = 163000
    once RotturaL = 0
    once EntrataL = 0
    once RotturaS = 0
    once EntrataS = 0
    once Flag     = 0
    if Not OnMarket THEN
    Flag       = 0
    Posizioni  = 0
    ENDIF
    ema13 = average[13,1](close)
    // Impedisce al sistema di tradare in giorni specifici della settimana
    daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
    OTD = (Barindex - TradeIndex(1) > IntradayBarIndex)
    // Condizioni per entrare su posizioni long
    Massimo, Minimo = CALL "max/min premarket"
    c1 = (close crosses over Massimo)
    IF c1 THEN
    RotturaL = 1
    EntrataL = 0
    RotturaS = 0
    EntrataS = 0
    ENDIF
    IF RotturaL[1] = 1 AND (high > high[1]) THEN
    RotturaL = 2
    ENDIF
    IF RotturaL = 2 THEN
    IF (low <= Ema13) AND (close > ema13) THEN
    EntrataL = Ema13
    ENDIF
    ENDIF
    IF Time < 153000 OR Time > 163000 THEN
    RotturaL = 0
    EntrataL = 0
    ENDIF
    IF EntrataL > 0 AND not daysForbiddenEntry and OTD THEN
    BUY 10000 CASH AT EntrataL LIMIT
    RotturaS = 0
    EntrataS = 0
    ENDIF
    // Condizioni per uscire da posizioni long
    indicator2 = SuperTrend[4,52]
    c2 = (close CROSSES UNDER indicator2)
    IF c2 THEN
    SELL AT MARKET
    ENDIF
    // Condizioni per entrare su posizioni short
    c3 = (close crosses under Minimo)
    IF c3 THEN
    RotturaL = 0
    EntrataL = 0
    RotturaS = 1
    EntrataS = 0
    ENDIF
    IF RotturaS[1] = 1 AND (low < low[1]) THEN
    RotturaS = 2
    ENDIF
    IF RotturaS = 2 THEN
    IF (high >= ema13) AND (close < ema13) THEN
    EntrataS = ema13
    ENDIF
    ENDIF
    IF Time < 153000 OR Time > 163000 THEN
    RotturaS = 0
    EntrataS = 0
    ENDIF
    IF EntrataS > 0 AND not daysForbiddenEntry and OTD THEN
    SELLSHORT 10000 CASH AT EntrataS LIMIT
    RotturaL = 0
    EntrataL = 0
    ENDIF
    // Condizioni per uscire da posizioni short
    indicator4 = SuperTrend[4,52]
    c4 = (close CROSSES OVER indicator4)
    IF c4 THEN
    EXITSHORT AT MARKET
    ENDIF
    //
    if OnMarket THEN
    RotturaL = 0
    EntrataL = 0
    RotturaS = 0
    EntrataS = 0
    endif
    // Stop e target
    IF OnMarket AND ((PositionPerf * 100) >= 1) AND Flag = 0 THEN
    Posizioni = abs(CountOfPosition) / 2
    Flag = 1
    IF LongOnMarket THEN
    SELL Posizioni CASH AT Market
    ELSE
    EXITSHORT Posizioni CASH AT Market
    ENDIF
    Set Stop Breakeven
    ENDIF
    SET STOP   %LOSS   1
    SET TARGET %PROFIT 0
    //
    //graphonprice Massimo coloured(0,0,255,255)
    //graphonprice Minimo  coloured(255,0,0,255)
    //graphonprice ema13   coloured(0,128,0,155)
    //graph RotturaL       coloured(0,0,255,255)
    //graph RotturaS       coloured(255,0,0,255)
    //graph c1
    //graph c3
    //graph PositionPerf
    //graph PositionPerf * 100
    //graph PositionPrice * PositionPerf / PipSize * PipValue
    //graph abs(CountOfPosition)
    //graph Posizioni
    #200071 quote
    Enrico
    Participant
    New

    VERAMENTE OTTIMO LAVORO! Per quanto riguarda il fatto della chiusura di metà posizione si potrebbe risolvere inserendo in entrata una quantità di azioni (variabile manualmente per ogni trade) al posto di cash. E in uscita al posto del 50% una quantità di azioni ( variabile manualmente). Mi diresti come inserire i dati? Veramente un grosso MILLE GRAZIE!

    #200077 quote
    robertogozzi
    Moderator
    Master

    Eccolo, i due dati sono alle righe 7 e 8:

    // Definizione dei parametri del codice
    DEFPARAM CumulateOrders = False // Posizioni cumulate disattivate
    // Il sistema cancellerà tutti gli ordini in attesa e chiuderà tutte le posizioni a 0:00. Dopo l'orario "Flat Before" non saranno piazzati nuovi ordini o posizioni.
    DEFPARAM FLATBEFORE = 153000
    // Cancellare tutti gli ordini in attesa e chiudere tutte le posizioni all'orario "Flat After"
    DEFPARAM FLATAFTER  = 163000
    once AzioniEntrata = 10000     //Numero di azioni da tradare all'entrata
    once AzioniUscita  = 5000      //Numero di azioni da chiudere al raggiongimento dell'1% di profitto
    once RotturaL = 0
    once EntrataL = 0
    once RotturaS = 0
    once EntrataS = 0
    once Flag     = 0
    if Not OnMarket THEN
    Flag       = 0
    Posizioni  = 0
    ENDIF
    ema13 = average[13,1](close)
    // Impedisce al sistema di tradare in giorni specifici della settimana
    daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
    OTD = (Barindex - TradeIndex(1) > IntradayBarIndex)
    // Condizioni per entrare su posizioni long
    Massimo, Minimo = CALL "max/min premarket"
    c1 = (close crosses over Massimo)
    IF c1 THEN
    RotturaL = 1
    EntrataL = 0
    RotturaS = 0
    EntrataS = 0
    ENDIF
    IF RotturaL[1] = 1 AND (high > high[1]) THEN
    RotturaL = 2
    ENDIF
    IF RotturaL = 2 THEN
    IF (low <= Ema13) AND (close > ema13) THEN
    EntrataL = Ema13
    ENDIF
    ENDIF
    IF Time < 153000 OR Time > 163000 THEN
    RotturaL = 0
    EntrataL = 0
    ENDIF
    IF EntrataL > 0 AND not daysForbiddenEntry and OTD THEN
    BUY AzioniEntrata CASH AT EntrataL LIMIT
    RotturaS = 0
    EntrataS = 0
    ENDIF
    // Condizioni per uscire da posizioni long
    indicator2 = SuperTrend[4,52]
    c2 = (close CROSSES UNDER indicator2)
    IF c2 THEN
    SELL AT MARKET
    ENDIF
    // Condizioni per entrare su posizioni short
    c3 = (close crosses under Minimo)
    IF c3 THEN
    RotturaL = 0
    EntrataL = 0
    RotturaS = 1
    EntrataS = 0
    ENDIF
    IF RotturaS[1] = 1 AND (low < low[1]) THEN
    RotturaS = 2
    ENDIF
    IF RotturaS = 2 THEN
    IF (high >= ema13) AND (close < ema13) THEN
    EntrataS = ema13
    ENDIF
    ENDIF
    IF Time < 153000 OR Time > 163000 THEN
    RotturaS = 0
    EntrataS = 0
    ENDIF
    IF EntrataS > 0 AND not daysForbiddenEntry and OTD THEN
    SELLSHORT AzioniEntrata CASH AT EntrataS LIMIT
    RotturaL = 0
    EntrataL = 0
    ENDIF
    // Condizioni per uscire da posizioni short
    indicator4 = SuperTrend[4,52]
    c4 = (close CROSSES OVER indicator4)
    IF c4 THEN
    EXITSHORT AT MARKET
    ENDIF
    //
    if OnMarket THEN
    RotturaL = 0
    EntrataL = 0
    RotturaS = 0
    EntrataS = 0
    endif
    // Stop e target
    IF OnMarket AND ((PositionPerf * 100) >= 1) AND Flag = 0 THEN
    Posizioni = abs(CountOfPosition) / 2
    Posizioni = AzioniUscita
    Flag = 1
    IF LongOnMarket THEN
    SELL Posizioni CASH AT Market
    ELSE
    EXITSHORT Posizioni CASH AT Market
    ENDIF
    Set Stop Breakeven
    ENDIF
    SET STOP   %LOSS   1
    SET TARGET %PROFIT 0
    //
    //graphonprice Massimo coloured(0,0,255,255)
    //graphonprice Minimo  coloured(255,0,0,255)
    //graphonprice ema13   coloured(0,128,0,155)
    //graph RotturaL       coloured(0,0,255,255)
    //graph RotturaS       coloured(255,0,0,255)
    //graph c1
    //graph c3
    //graph PositionPerf
    //graph PositionPerf * 100
    //graph PositionPrice * PositionPerf / PipSize * PipValue
    //graph abs(CountOfPosition)
    //graph Posizioni

    allego anche il file ITF, se preferisci importarlo.

    #200079 quote
    Enrico
    Participant
    New
    • Perfetto, lo proverò…. E se volessi variare anche la % dell’uscita qual’e’ il valore modificabile? Grazie in anticipo.
    #200082 quote
    robertogozzi
    Moderator
    Master

    Sostituisci la riga 8 con:

    once AzioniUscita  = AzioniEntrata * 0.30   //chiudere il 30% delle Azioni
    #200086 quote
    Enrico
    Participant
    New

    VERAMENTE…..GRAZIE MILLE!

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

Entrata long o short su sfondamento MIn/Max premercato su ritracciamento


ProOrder: Trading Automatico & Backtesting

New Reply
Author
author-avatar
Enrico @ocirne Participant
Summary

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

Topic Details
Forum: ProOrder: Trading Automatico & Backtesting
Language: Italian
Started: 08/29/2022
Status: Active
Attachments: 1 files
Logo Logo
Loading...