supertrend con filtro orario e primo cambio colore

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #203399 quote
    Gabriele BattistaGabriele Battista
    Participant
    Senior

    Buongiorno vorrei un TS che utilizzando il SuperTrend oltre a fare entrate regolari al cambio colore e chiudere a fine giornata (lo vorrei usare sul dax m3 8:00-22:00) mi escluda l’eventuale cambio colore della prima candela delle 8 (e quindi aspetti flat il successivo cambio colore) e escluda anche cambi colore nell’intervallo 11:30-14:00 (chiudendo eventuali posizioni aperte e rimanendo anche in questo caso flat fino al al primo cambio colore fuori dall’intervallo “no trades”). Allego il codice che non prevede però le due richieste “aggiuntive”. Grazie

    // Chiusura temporale alla chiusura cash
    DEFPARAM FlatAfter = 215700 //per TF m3 WARNING!!!
    DEFPARAM FlatBefore = 080600 //per TF m3 WARNING!!!
    
    // solo un ordine a mercato
    DEFPARAM CumulateOrders=False
    REM Compra
    
    indicator1 = close
    indicator2 = SuperTrend[3.7,8]
    c1 = (indicator1 > indicator2)
    
    IF c1 THEN
    //BUY 250 SHARES AT MARKET // NUMERO TITOLI
    BUY 1 CONTRACT AT MARKET //FUTURES
    //BUY 5000 CASH ROUNDEDUP AT MARKET // TITOLI A VALORE
    ENDIF
    
    
    REM Vendi
    
    indicator3 = close
    indicator4 = SuperTrend[3.7,8]
    c2 = (indicator3 < indicator4)
    
    IF c2 THEN
    //SELLSHORT 250 SHARES AT MARKET //NUMERO TITOLI
    SELLSHORT 1 CONTRACT AT MARKET //FUTURES
    //SELLSHORT 5000 CASH ROUNDEDUP AT MARKET // TITOLI A VALORE
    ENDIF
    #203402 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    Eccolo:

    // Chiusura temporale alla chiusura cash
    DEFPARAM FlatAfter      = 215700 //per TF m3 WARNING!!!
    DEFPARAM FlatBefore     = 080600 //per TF m3 WARNING!!!
    DEFPARAM CumulateOrders = False
    
    ONCE PrimoCambio = 0
    IF (Time = 080000) OR ((Time > 080000) AND (Time[1] < 080000)) THEN
       PrimoCambio = 0
    ENDIF
    indicator1 = close
    indicator2 = SuperTrend[3.7,8]
    c1         = (indicator1 > indicator2)
    c2         = (indicator1 < indicator2)
    c3         = (indicator1 CROSSES OVER  indicator2)
    c4         = (indicator1 CROSSES UNDER indicator2)
    Cambio     = c3 OR c4
    IF Cambio = 0 THEN
       Cambio = Cambio[1]
    ENDIF
    
    IF Cambio THEN
       IF PrimoCambio = 0 THEN
          Cambio      = 0
          PrimoCambio = 1
       ENDIF
    ENDIF
    
    REM Compra
    IF c1 AND Cambio THEN
       //BUY 250 SHARES AT MARKET // NUMERO TITOLI
       BUY 1 CONTRACT AT MARKET //FUTURES
       //BUY 5000 CASH ROUNDEDUP AT MARKET // TITOLI A VALORE
       Cambio = 0
    ENDIF
    
    REM Vendi
    IF c2 AND Cambio THEN
       //SELLSHORT 250 SHARES AT MARKET //NUMERO TITOLI
       SELLSHORT 1 CONTRACT AT MARKET //FUTURES
       //SELLSHORT 5000 CASH ROUNDEDUP AT MARKET // TITOLI A VALORE
       Cambio = 0
    ENDIF
    #203415 quote
    Gabriele BattistaGabriele Battista
    Participant
    Senior

    Grazie. Provato funziona per il cambio colore all’open delle 8 ma non considera l’altra richiesta: “escluda anche cambi colore nell’intervallo 11:30-14:00”.

    #203427 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    Ok, è stata una svista:

    // Chiusura temporale alla chiusura cash
    DEFPARAM FlatAfter      = 215700 //per TF m3 WARNING!!!
    DEFPARAM FlatBefore     = 080600 //per TF m3 WARNING!!!
    DEFPARAM CumulateOrders = False
     
    ONCE PrimoCambio = 0
    IF (Time = 080000) OR ((Time > 080000) AND (Time[1] < 080000)) THEN
       PrimoCambio = 0
    ENDIF
    indicator1 = close
    indicator2 = SuperTrend[3.7,8]
    c1         = (indicator1 > indicator2)
    c2         = (indicator1 < indicator2)
    c3         = (indicator1 CROSSES OVER  indicator2)
    c4         = (indicator1 CROSSES UNDER indicator2)
    Cambio     = c3 OR c4
    IF Cambio = 0 THEN
       Cambio = Cambio[1]
    ENDIF
     
    IF Cambio THEN
       IF PrimoCambio = 0 THEN
          Cambio      = 0
          PrimoCambio = 1
       ENDIF
    ENDIF
    
    IF (Time >= 113000) AND (Time <= 140000) THEN
       Cambio = 0
       SELL      at Market
       EXITSHORT at Market
    ENDIF
     
    REM Compra
    IF c1 AND Cambio THEN
       //BUY 250 SHARES AT MARKET // NUMERO TITOLI
       BUY 1 CONTRACT AT MARKET //FUTURES
       //BUY 5000 CASH ROUNDEDUP AT MARKET // TITOLI A VALORE
       Cambio = 0
    ENDIF
     
    REM Vendi
    IF c2 AND Cambio THEN
       //SELLSHORT 250 SHARES AT MARKET //NUMERO TITOLI
       SELLSHORT 1 CONTRACT AT MARKET //FUTURES
       //SELLSHORT 5000 CASH ROUNDEDUP AT MARKET // TITOLI A VALORE
       Cambio = 0
    ENDIF
    #203468 quote
    Gabriele BattistaGabriele Battista
    Participant
    Senior

    Ciao, grazie prima di tutto. Il tuo codice chiude l’operazione aperta all’orario 11:30 definito, io in realtà volevo che non fossero aperte in quell’intervallo nuove posizioni ma, se il ST dava segnali di chiusura della posizione aperta la chiudesse. A mo di esempio se ho una posizione LONG aperta alle 10:0o con il ST che cambia colore alle 12:00 vorrei che fosse chiusa alle 12:00 (orario dell’effettivo cambio colore) e non alle 11:30 (inizio della finestra di “no trade”). E’ possibile? Grazie

    #203479 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    Questo è il codice aggiornato:

    // Chiusura temporale alla chiusura cash
    DEFPARAM FlatAfter      = 215700 //per TF m3 WARNING!!!
    DEFPARAM FlatBefore     = 080600 //per TF m3 WARNING!!!
    DEFPARAM CumulateOrders = False
     
    ONCE PrimoCambio = 0
    IF (Time = 080000) OR ((Time > 080000) AND (Time[1] < 080000)) THEN
    PrimoCambio = 0
    ENDIF
    indicator1 = close
    indicator2 = SuperTrend[3.7,8]
    c1         = (indicator1 > indicator2)
    c2         = (indicator1 < indicator2)
    c3         = (indicator1 CROSSES OVER  indicator2)
    c4         = (indicator1 CROSSES UNDER indicator2)
    Cambio     = c3 OR c4
    //
    IF Cambio THEN
    IF LongOnMarket AND c2 THEN
    SELL AT MARKET
    ELSIF ShortOnMarket AND c1 THEN
    EXITSHORT AT MARKET
    ENDIF
    ENDIF
    //
    IF Cambio = 0 THEN
    Cambio = Cambio[1]
    ENDIF
     
    IF Cambio THEN
    IF PrimoCambio = 0 THEN
    Cambio      = 0
    PrimoCambio = 1
    ENDIF
    ENDIF
     
    IF (Time >= 113000) AND (Time <= 140000) THEN
    Cambio = 0
    ENDIF
     
    REM Compra
    IF c1 AND Cambio THEN
    //BUY 250 SHARES AT MARKET // NUMERO TITOLI
    BUY 1 CONTRACT AT MARKET //FUTURES
    //BUY 5000 CASH ROUNDEDUP AT MARKET // TITOLI A VALORE
    Cambio = 0
    ENDIF
     
    REM Vendi
    IF c2 AND Cambio THEN
    //SELLSHORT 250 SHARES AT MARKET //NUMERO TITOLI
    SELLSHORT 1 CONTRACT AT MARKET //FUTURES
    //SELLSHORT 5000 CASH ROUNDEDUP AT MARKET // TITOLI A VALORE
    Cambio = 0
    ENDIF
    #203755 quote
    Gabriele BattistaGabriele Battista
    Participant
    Senior

    Scusa ancora se volessi evitare di aprire posizioni in un giorno della settimana (ad esempio il martedì) come si modificherebbe il codice?

    Grazie

    #203816 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    Eccolo:

    // Chiusura temporale alla chiusura cash
    DEFPARAM FlatAfter      = 215700 //per TF m3 WARNING!!!
    DEFPARAM FlatBefore     = 080600 //per TF m3 WARNING!!!
    DEFPARAM CumulateOrders = False
    
    Aprire = OpenDayOfWeek <> 2                     //1=Lun,2=Mar,ecc...
    
    ONCE PrimoCambio = 0
    IF (Time = 080000) OR ((Time > 080000) AND (Time[1] < 080000)) THEN
    PrimoCambio = 0
    ENDIF
    indicator1 = close
    indicator2 = SuperTrend[3.7,8]
    c1         = (indicator1 > indicator2)
    c2         = (indicator1 < indicator2)
    c3         = (indicator1 CROSSES OVER  indicator2)
    c4         = (indicator1 CROSSES UNDER indicator2)
    Cambio     = c3 OR c4
    //
    IF Cambio THEN
    IF LongOnMarket AND c2 THEN
    SELL AT MARKET
    ELSIF ShortOnMarket AND c1 THEN
    EXITSHORT AT MARKET
    ENDIF
    ENDIF
    //
    IF Cambio = 0 THEN
    Cambio = Cambio[1]
    ENDIF
     
    IF Cambio THEN
    IF PrimoCambio = 0 THEN
    Cambio      = 0
    PrimoCambio = 1
    ENDIF
    ENDIF
     
    IF (Time >= 113000) AND (Time <= 140000) THEN
    Cambio = 0
    ENDIF
     
    REM Compra
    IF c1 AND Cambio AND Aprire THEN
    //BUY 250 SHARES AT MARKET // NUMERO TITOLI
    BUY 1 CONTRACT AT MARKET //FUTURES
    //BUY 5000 CASH ROUNDEDUP AT MARKET // TITOLI A VALORE
    Cambio = 0
    ENDIF
     
    REM Vendi
    IF c2 AND Cambio AND Aprire THEN
    //SELLSHORT 250 SHARES AT MARKET //NUMERO TITOLI
    SELLSHORT 1 CONTRACT AT MARKET //FUTURES
    //SELLSHORT 5000 CASH ROUNDEDUP AT MARKET // TITOLI A VALORE
    Cambio = 0
    ENDIF
    Gabriele Battista thanked this post
    #203943 quote
    Gabriele BattistaGabriele Battista
    Participant
    Senior

    Grazie! gentilissimo come sempre.

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

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

supertrend con filtro orario e primo cambio colore


ProOrder: Trading Automatico & Backtesting

New Reply
Summary

This topic contains 8 replies,
has 2 voices, and was last updated by Gabriele BattistaGabriele Battista
3 years, 10 months ago.

Topic Details
Forum: ProOrder: Trading Automatico & Backtesting
Language: Italian
Started: 11/02/2022
Status: Active
Attachments: No files
ProRealCode ProRealCode
Loading...