Strategia Bollinger Band 2h

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #62229 quote
    GianlucaGianluca
    Participant
    Master

    Ciao a tutti, ho messo su una strategia molto semplice, va a comprare quando la candela chiude sotto la banda inferioer di bollinger, e va a vendere quando chiude sopra.

    La strategia si dimostra pero’ profittevole solo con le operazioni long, e per questo ho inserito nel codice la possibilità di disabilitarla.

    Ho preso poi la gestione delle operazioni dal sistema Pathfinder per la chiusura dopo tot candele non in profit.

    Chiedo a chi vuole ed ha tempo qualche consiglio o idea per eliminare il problema dei loss sulle operazioni short, o suggerimenti per gestire meglio le operazioni in loss ed in profit.

    Grazie!

     

    ps. negli screen la strategia è settata sul nasdaq, penso possa essere configurata agilmente anche su altri mercati.

    Che ne pensate?

     

    // Definizione dei parametri del codice
    DEFPARAM CumulateOrders = false // Posizioni cumulate disattivate
    ONCE startTime                     = 90000  // start time of trading window
    ONCE endTime                       = 210000 // end time of trading window
    ///PARAMETRI
    ONCE OKLONG                        = 1    // 1 LONG ON 0 LONG OFF
    ONCE OKSHORT                       = 0    // 1 SHORT ON 0 SHORT OFF
    ONCE stopLossLong                  = 5.2  // in %
    ONCE stopLossShort                 = 0.8  // in %
    ONCE takeProfitLong                = 2.2  // in %
    ONCE takeProfitShort               = 0.4  // in %
    ONCE maxCandlesLongWithProfit      = 10    //takelong profit latest after x
    ONCE maxCandlesShortWithProfit     = 2    // take short profit latest after
    ONCE maxCandlesLongWithoutProfit   = 38   // limit long loss latest after x
    ONCE maxCandlesShortWithoutProfit  = 9    // limit short loss latest after
    ONCE trailingStartLong             = 2  // in % * changed from 1.25
    ONCE trailingStartShort            = 2    // in %
    ONCE trailingStepLong              = 0.1   // in %
    ONCE trailingStepShort             = 0.1   // in % * changed from 0.6
    
    //Indicatori
    boldo = BollingerDown[20](close)
    bolu = bollingerup[20](close)
    stoc = Stochastic[8,3](close)
    //mm20 = average[20]
    test1 = stoc < 44
    test2 = stoc > 44
    // Condizioni per entrare su posizioni long
    c1 = (close[1] < boldo[1])
    //esci = (close crosses under mm20)
    
    // Condizioni per entrare su posizioni short
    c2 = (close[1] > bolu[1])
    
    
    //////////trade
    IF Time >= startTime AND Time <= endTime THEN
    IF OKLONG > 0 THEN
    IF c1 and test1 THEN
    BUY 1 CONTRACT AT MARKET
    stopLoss = stopLossLONG
    takeProfit = takeProfitLONG
    ENDIF
    ENDIF
    
    IF OKSHORT > 0 THEN
    IF c2 and test2 THEN
    SELLSHORT 1 CONTRACT AT MARKET
    stopLoss = stopLossShort
    takeProfit = takeProfitShort
    ENDIF
    endif
    ENDIF
    
    //if longonmarket then
    //if esci then
    //sell at market
    //endif
    //endif
    
    
    
    // stop and profit management
    posProfit = (((close - positionprice) * pointvalue) * countofposition) / pipsize
    numberCandles = (BarIndex - TradeIndex)
    
    m1 = posProfit > 0 AND numberCandles >= maxCandlesLongWithProfit
    m2 = posProfit > 0 AND numberCandles >= maxCandlesShortWithProfit
    m3 = posProfit < 0 AND numberCandles >= maxCandlesLongWithoutProfit
    m4 = posProfit < 0 AND numberCandles >= maxCandlesShortWithoutProfit
    
    // take profit after max candles
    IF LONGONMARKET AND (m1 OR m3) THEN
    SELL AT MARKET
    ENDIF
    IF SHORTONMARKET AND (m2 OR m4) THEN
    EXITSHORT AT MARKET
    ENDIF
    
    // trailing stop function (convert % to pips)
    trailingStartLongInPoints = tradeprice(1) * trailingStartLong / 100
    trailingStartShortInPoints = tradeprice(1) * trailingStartShort / 100
    trailingStepLongInPoints = tradeprice(1) * trailingStepLong / 100
    trailingStepShortInPoints = tradeprice(1) * trailingStepShort / 100
    
    // reset the stoploss value
    IF NOT ONMARKET THEN
    newSL = 0
    ENDIF
    
    // manage long positions
    IF LONGONMARKET THEN
    // first move (breakeven)
    IF newSL = 0 AND close - tradeprice(1) >= trailingStartLongInPoints * pipsize THEN
    newSL = tradeprice(1) + trailingStepLongInPoints * pipsize
    //stopLoss = stopLossLong * 0.1
    //takeProfit = takeProfitLong * 2
    ENDIF
    // next moves
    IF newSL > 0 AND close - newSL >= trailingStepLongInPoints * pipsize THEN
    newSL = newSL + trailingStepLongInPoints * pipsize
    ENDIF
    ENDIF
    
    // manage short positions
    IF SHORTONMARKET THEN
    // first move (breakeven)
    IF newSL = 0 AND tradeprice(1) - close >= trailingStartShortInPoints * pipsize THEN
    newSL = tradeprice(1) - trailingStepShortInPoints * pipsize
    ENDIF
    // next moves
    IF newSL > 0 AND newSL - close >= trailingStepShortInPoints * pipsize THEN
    newSL = newSL - trailingStepShortInPoints * pipsize
    ENDIF
    ENDIF
    
    // stop order to exit the positions
    IF newSL > 0 THEN
    IF LONGONMARKET THEN
    SELL AT newSL STOP
    ENDIF
    IF SHORTONMARKET THEN
    EXITSHORT AT newSL STOP
    ENDIF
    ENDIF
    
    // Stop e target
    SET STOP %LOSS stopLoss
    SET TARGET %PROFIT takeProfit
    
    PERFORMANCE.jpg PERFORMANCE.jpg PERF-2.jpg PERF-2.jpg Bollinger-Band.itf
    #62233 quote
    GianlucaGianluca
    Participant
    Master

    Un altro problema che ha questa strategia è che i gain sono tanti ma piccoli, mentre i loss quando ci sono sono corposi, c’e’ il rischio che a lanciarla in rial si prendano 2/3 loss che ti azzerano il conto.

    #62407 quote
    ALEALE
    Moderator
    Master

    1 time frame basso piuttosto erratico

    2 usa una media lunga per filtrare le posizioni long / short

    3 usa un oscillatore per filtrare Le entrare

    #62408 quote
    ALEALE
    Moderator
    Master

    Comunque non è male…

    puoi anche considerare di utilizzarla solo long

    #73686 quote
    GianlucaGianluca
    Participant
    Master

    Ciao, ecco un piccolo aggiornamento dell’andamento del TS in Demo. 1 Contratto per trade.

    [attachment file=”Andamento Demo Bollinger.JPG”]

    Nicolas thanked this post
    Andamento-Demo-Bollinger.jpg Andamento-Demo-Bollinger.jpg
    #73772 quote
    NicolasNicolas
    Keymaster
    Legend

    Buon lavoro, si spera che il mercato continuerà a salire 🙂

    Grazie per dare notizie sulla demo / live trading della tua strategia, dimostra che le cose semplici possono funzionare.
    Quindi presumo che tu abbia ottimizzato le variabili? Come fai ad adattarli per periodi futuri? Hai provato a utilizzare l’analisi Walk Forward?

    #74446 quote
    GianlucaGianluca
    Participant
    Master

    Buon lavoro, si spera che il mercato continuerà a salire

    Grazie per dare notizie sulla demo / live trading della tua strategia, dimostra che le cose semplici possono funzionare.

    Quindi presumo che tu abbia ottimizzato le variabili? Come fai ad adattarli per periodi futuri? Hai provato a utilizzare l’analisi Walk Forward?

    La strategia quando è nata ottimizzata (profit e loss e il numero di barre) senza particolare attenzione alle ottimizzazioni, ma senza il walkforward, sto usando questi sei mesi come walkforward 🙂
    Per quanto riguarda i mercati in salita che salgano o no alla strategia in se non importa, anzi forse per come è nata è meglio che scendano, visto che va a comprare gli ipervenduti segnalati dalle bande, certo il loss peggiore è avvenuto proprio in concomitanza con il crollo di febbraio/marzo, ma ha continuato a lavorare abbastanza bene.

    Nicolas thanked this post
    #74448 quote
    NicolasNicolas
    Keymaster
    Legend

    ok, grazie per averlo condiviso qui comunque!

    #119123 quote
    Raniero MarconiRaniero Marconi
    Participant
    New

    wella…avevi apportato altre modifiche a questo codice.?
    era stato migliorato ? somiglia ad una strategià che ho già.

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

Strategia Bollinger Band 2h


ProOrder: Trading Automatico & Backtesting

New Reply
Author
author-avatar
Gianluca @altares Participant
Summary

This topic contains 8 replies,
has 4 voices, and was last updated by Raniero MarconiRaniero Marconi
6 years, 8 months ago.

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