TS BREAK PRIMA ORA

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #56662 quote
    traderwin
    Participant
    Average

    Salve, ho questo indicatore che calcola il range della prima ora di contrattazione (dalle ore 08:00 alle ore 09:00)  sull’indice dax e io lo uso su time frame a 5 minuti.

    Vorrei creare un Ts su time frame 5 minuti mi entri in posizione long se dopo le ore 9 e cioe’ dopo che si e’ formato il range della prima ora, la candela mi chiude sopra il max del range creato dall’indicatore, e mi entri short se le candela mi chiude sotto il range.

    Le posizioni verranno gestite con trailing stop.

    Un grazie a chi mi puo’ aiutare.

    Allego indicatore

    
    defparam drawonlastbaronly = false
    once upper=0
    once lower=0
    
    starttime = 080000
    endtime = 090000
    
    If Time = endtime then
    upper=highest[12](high)
    lower=lowest[12](low)
    dif=round(abs((lower-upper)*pipsize*pointvalue))
    //bars=barindex
    DRAWTEXT("#dif# pips", barindex-6, upper+10,SansSerif,bold, 16)
    DRAWARROWDOWN (barindex-6,upper+5)
    DRAWARROWup (barindex-6,upper+15)
    DRAWTEXT("#upper#", barindex-6, upper,SansSerif,bold, 16)
    DRAWTEXT("#lower#", barindex-6, lower,SansSerif,bold, 16)
    endif
    //if time >=080500 and Time <=090000 then
    ////backgroundcolor(0,255,255)
    //DRAWRECTANGLE(barindex-6,upper,barindex-6,lower) COLOURED(0,255,0)
    //endif
    if time >=090500 and Time <=220000 then
    count=count+1
    DRAWsegment(barindex-count,upper,barindex,upper)coloured(0,0,0)
    DRAWsegment(barindex-count,lower,barindex,lower)coloured(0,0,0)
    else
    count=0
    endif
    
    if intradaybarindex=0 then
    hh = 0
    ll = 0
    alreadydrawn = 0
    endif
    
    if time=starttime then
    startbar=barindex
    endif
    
    if time=endtime then
    endbar=barindex
    endif
    
    if time>=starttime and time<=endtime then
    if high>hh then
    hh = high
    endif
    if low<ll or ll=0 then
    ll = low
    endif
    endif
    
    if time>endtime and alreadydrawn=0 then
    drawrectangle(startbar,hh,endbar,ll) coloured(0,255,255)
    alreadydrawn=1
    endif
    
    RETURN
    #56663 quote
    traderwin
    Participant
    Average

    dimenticavo. Il ts verra’ settato su time frame 5 minuti

    #56666 quote
    robertogozzi
    Moderator
    Master

    Eccolo, per il trailing stop (qui settato a 5 pips di partenza e 5 pips di incremento successivo) ho usato il codice di Nicolas (https://www.prorealcode.com/blog/trading/complete-trailing-stop-code-function/):

    DEFPARAM CumulateOrders = false
    DEFPARAM FLATBefore     = 090000                         //09:00
    DEFPARAM FLATAfter      = 210000                         //21:00
    DEFPARAM PreLoadBars    = 2000
    
    ONCE nLots              = 1
    ONCE MaxPrice           = 999999
    ONCE MinPrice           = 0
    ONCE FirstHour          = 090000
    
    IF time = FirstHour THEN
    MaxPrice = highest[12](high)                          //Il massimo/minimo delle ultime 12 barre
    MinPrice = lowest[12](low)                            //   (ogni ora = 12 barre da 5 minuti)
    ENDIF
    //************************************************************************
    //     trailing stop function
    trailingstart = 5    //5    trailing will start @trailinstart points profit
    trailingstep  = 5    //5    trailing step to move the "stoploss"
    //
    //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)>=trailingstart*pipsize THEN
    newSL = tradeprice(1)+trailingstep*pipsize
    ENDIF
    //next moves
    IF newSL>0 AND close-newSL>=trailingstep*pipsize THEN
    newSL = newSL+trailingstep*pipsize
    ENDIF
    ENDIF
    //manage short positions
    IF SHORTONMARKET THEN
    //first move (breakeven)
    IF newSL=0 AND tradeprice(1)-close>=trailingstart*pipsize THEN
    newSL = tradeprice(1)-trailingstep*pipsize
    ENDIF
    //next moves
    IF newSL>0 AND newSL-close>=trailingstep*pipsize THEN
    newSL = newSL-trailingstep*pipsize
    ENDIF
    ENDIF
    //stop order to exit the positions
    IF newSL>0 THEN
    SELL AT newSL STOP
    EXITSHORT AT newSL STOP
    ENDIF
    //************************************************************************
    //                           LONG
    a1 = close > MaxPrice
    IF a1 THEN
    Buy nLots CONTRACT AT MARKET
    MaxPrice = 999999
    MinPrice = 0
    ENDIF
    
    //                           SHORT
    b1 = close < MinPrice
    IF b1 THEN
    Sellshort nLots CONTRACT AT MARKET
    MaxPrice = 999999
    MinPrice = 0
    ENDIF

    Ho aggiunto delle righe per fare in modo che entri solo una volta al giorno. Basta che tu commenti (mettendo le due barre oblique all’inizio della riga) le righe 56-57 e 64-65 e il TS potrà entrare anche più volte.

    Roberto

    #56667 quote
    robertogozzi
    Moderator
    Master

    Ovviamente tu lo modificherai come preferisci, puoi togliere/modificare i limiti (DEFPARAM) in apertura e chiusura, il numero di barre tra le parentesi di highest e lowest se vuoi usarlo su un grafico a 10 o 15 minuti, ecc….

    Eric thanked this post
    #56757 quote
    traderwin
    Participant
    Average

    Ciao Roberto provato ora e va benissimo 🙂

    Grazie tante 🙂

    #56758 quote
    traderwin
    Participant
    Average

    Se puoi, potresti darmi un aiutino sul forum indicatori?

    Ho inserito un post proprio oggi

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

TS BREAK PRIMA ORA


ProOrder: Trading Automatico & Backtesting

New Reply
Author
author-avatar
traderwin @traderwin Participant
Summary

This topic contains 5 replies,
has 2 voices, and was last updated by traderwin
8 years, 1 month ago.

Topic Details
Forum: ProOrder: Trading Automatico & Backtesting
Language: Italian
Started: 12/27/2017
Status: Active
Attachments: No files
Logo Logo
Loading...