inserimento indicatore in strategia

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

    Salve, vorrei inserire l’indicatore di Nicolas all’interno della mia strategia, ma senza usare la funzione call e cioè senza richiamarlo.

    Vorrei ad esempio creare una condizione che dice: quando il prezzo è superiore a “questo indicatore”

    Per “questo indicatore” non so pero’ quale stringa prendere di riferimento all’interno del codice.

    Allego L’indicatore di Nicolas

    //PRC_Adaptive-ATR-ADX-Trend-V2 | indicator
    //29.06.2017
    //Nicolas @ www.prorealcode.com
    //Sharing ProRealTime knowledge
    //translated from tradingview code
    
    // --- settings
    //atrLen = 21
    //m1 = 3.5 //"ATR Multiplier - ADX Rising"
    //m2 = 1.75 //"ATR Multiplier - ADX Falling"
    //adxLen = 14
    //adxThresh = 30 //"ADX Threshold"
    //aboveThresh = 1 //true, title = "ADX Above Threshold uses ATR Falling Multiplier Even if Rising?")
    //useHeiken = 1 //(false, title = "Use Heiken-Ashi Bars (Source will be ohlc4)")
    // --- end of settings
    
    source = MedianPrice
        
    // DI-Pos, DI-Neg, ADX
    
    hR = high-high[1]
    lR = -(low-low[1])
    
    if hr>lr then
    dmPos=max(hr,0)
    else
    dmPos=0
    endif
    if lr>hr then
    dmNeg=max(lr,0)
    else
    dmNeg=0
    endif
    
    sTR = (sTR[1] - sTR[1]) / adxLen + tr
    
    sDMPos = (sDMPos[1] - sDMPos[1]) / adxLen + dmPos
    sDMNeg = (sDMNeg[1] - sDMNeg[1]) / adxLen + dmNeg
    
    DIP = sDMPos / sTR * 100
    DIN = sDMNeg / sTR * 100
    DX = abs(DIP - DIN) / (DIP + DIN) * 100
    aadx = average[adxLen](DX)
    
    // Heiken-Ashi
    
    if barindex<2 then
    xClose = close
    xOpen = open
    else
    xClose = TotalPrice
    xOpen = (xOpen[1] + close[1]) / 2
    endif
    xHigh = max(high, max(xOpen, xClose))
    xLow = min(low, min(xOpen, xClose))
    
    // Trailing ATR
    
    v1 = abs(xHigh - xClose[1])
    v2 = abs(xLow - xClose[1])
    v3 = xHigh - xLow
    
    trueRange = max(v1, max(v2, v3))
    if useHeiken then
    atr = WilderAverage[atrLen](trueRange)
    else
    atr = AverageTrueRange[atrLen]
    endif
    
    if aadx>aadx[1] and (adx < adxThresh or not aboveThresh) then
    m=m1
    elsif aadx<aadx[1] or (adx > adxThresh and aboveThresh) then
    m=m2
    else
    m = m[1]
    endif
    
    if DIP >= DIN then
    mUp=m
    else
    mUp=m2
    endif
    if DIN >= DIP then
    mDn=m
    else
    mDn=m2
    endif
    
    if useHeiken then
    src=xClose
    c=Xclose
    t=(xHigh+xLow)/2
    else
    src=source
    c=close
    t=MedianPrice
    endif
    
    up = t - mUp * atr
    dn = t + mDn * atr
    
    if max(src[1], c[1]) > TUp[1] then
    TUp = max(up,TUp[1])
    else
    TUp = up
    endif
    
    if min(src[1], c[1]) < TDown[1] then
    TDown = min(dn, TDown[1])
    else
    TDown = dn
    endif
    
    //trend
    if min(src,min(c,close))>TDown[1] then
    trend=1
    elsif max(src,max(c,close))<TUp[1] then
    trend=-1
    else
    trend=trend[1]
    endif
    
    if trend=1 then
    sstop=TUp
    r=0
    g=255
    else
    sstop=TDown
    r=255
    g=0
    endif
    
    if trend<>trend[1] then
    drawtext("•",barindex,sstop,Dialog,Standard,30) coloured(r,g,0)
    endif
    
    return sstop coloured(r,g,0) style(line,2)
    
    #77203 quote
    robertogozzi
    Moderator
    Master

    Togli le righe da 133 fino in fondo e poi togli le variabili che ti verranno segnalate come INUTILUZZATE, dovrebbero essere R, G e forse TREND, salvo sviste.

    A questo punto puoi scrivere:

    IF close > sstop then....

    sstop è il dato restituito dall’indicatore, quindi devi fare riferimento solo ad esso.

    Ovviamente fai attenzione a non usare per le tue variabili uno stesso nome già utilizzato dall’indicatore, quali TN, C oppure T, ecc…

    #77246 quote
    traderwin
    Participant
    Average

    Provato e tutto ok.

    Mille grazie  Roberto 🙂

    #77605 quote
    luxrun
    Participant
    Master

    Gentile Roberto, ho provato anche io a utilizzare l’indicatore Adaptive-ATR-ADX-Trend-V2 per realizzare un trading system seguendo le istruzioni da te suggerite a traderwin. Sotto inserisco il codice; io vorrei come risultato un ts che mi faccia stare long quando i prezzi sono sopra lo sstop e short viceversa. Invece il ts fa continui acquisti e vendite e non segue la linea dello sstop. Non riesco a capire se ho sbagliato io la codifica di entrata/uscita o è il ts che lavora in questa modalità per via della sua costruzione intrinseca, con atr, doppio moltiplicatore, heiken ashi etc. etc.. Se  mi puoi aiutare immagino che possa aiutare anche altri! Grazie Luciano

    
    // --- settings fissi
    //atrLen = 21
    //m1 = 3.5 //"ATR Multiplier - ADX Rising"
    //m2 = 1.75 //"ATR Multiplier - ADX Falling"
    //adxLen = 14
    //adxThresh = 30 //"ADX Threshold"
    //aboveThresh = 1 //true, title = "ADX Above Threshold uses ATR Falling Multiplier Even if Rising?")
    //useHeiken = 1 //(false, title = "Use Heiken-Ashi Bars (Source will be ohlc4)")
    // --- end of settings
    
    DEFPARAM CUMULATEORDERS = false
    
    source = MedianPrice
        
    // DI-Pos, DI-Neg, ADX
    
    hR = high-high[1]
    lR = -(low-low[1])
    
    if hr>lr then
    dmPos=max(hr,0)
    else
    dmPos=0
    endif
    
    if lr>hr then
    dmNeg=max(lr,0)
    else
    dmNeg=0
    endif
    
    sTR = (sTR[1] - sTR[1]) / adxLen + tr
    
    sDMPos = (sDMPos[1] - sDMPos[1]) / adxLen + dmPos
    sDMNeg = (sDMNeg[1] - sDMNeg[1]) / adxLen + dmNeg
    
    DIP = sDMPos / sTR * 100
    DIN = sDMNeg / sTR * 100
    DX = abs(DIP - DIN) / (DIP + DIN) * 100
    aadx = average[adxLen](DX)
    
    // Heiken-Ashi
    
    if barindex<2 then
    xClose = close
    xOpen = open
    else
    xClose = TotalPrice
    xOpen = (xOpen[1] + close[1]) / 2
    endif
    xHigh = max(high, max(xOpen, xClose))
    xLow = min(low, min(xOpen, xClose))
    
    // Trailing ATR
    
    v1 = abs(xHigh - xClose[1])
    v2 = abs(xLow - xClose[1])
    v3 = xHigh - xLow
    
    trueRange = max(v1, max(v2, v3))
    if useHeiken then
    atr = WilderAverage[atrLen](trueRange)
    else
    atr = AverageTrueRange[atrLen]
    endif
    
    if aadx>aadx[1] and (adx < adxThresh or not aboveThresh) then
    m=m1
    elsif aadx<aadx[1] or (adx > adxThresh and aboveThresh) then
    m=m2
    else
    m = m[1]
    endif
    
    if DIP >= DIN then
    mUp=m
    else
    mUp=m2
    endif
    if DIN >= DIP then
    mDn=m
    else
    mDn=m2
    endif
    
    if useHeiken then
    src=xClose
    c=Xclose
    t=(xHigh+xLow)/2
    else
    src=source
    c=close
    t=MedianPrice
    endif
    
    up = t - mUp * atr
    dn = t + mDn * atr
    
    if max(src[1], c[1]) > TUp[1] then
    TUp = max(up,TUp[1])
    else
    TUp = up
    endif
    
    if min(src[1], c[1]) < TDown[1] then
    TDown = min(dn, TDown[1])
    else
    TDown = dn
    endif
    
    //trend
    if min(src,min(c,close))>TDown[1] then
    trend=1
    elsif max(src,max(c,close))<TUp[1] then
    trend=-1
    else
    trend=trend[1]
    endif
    
    if trend=1 then
    sstop=TUp
    //r=0
    //g=255
    //else
    sstop=TDown
    //r=255
    //g=0
    endif
    
    c1 = (close crosses over sstop and close > sstop)
    c2 = (close crosses under sstop and close < sstop)
    
    IF NOT LONGONMARKET AND c1 THEN
    
    BUY 50 shares AT MARKET
    Endif
    
    IF  NOT SHORTONMARKET AND c2 THEN
    SELLSHORT 50 shares AT MARKET
    endif
    #77609 quote
    robertogozzi
    Moderator
    Master

    Perché alla riga 124 hai messo il commento ad ELSE, prova a toglierlo.

    #77616 quote
    luxrun
    Participant
    Master

    Ecco l’errore dov’era, grazie Roberto! Adesso dovrò lavorare con stop loss e trailing stop per il management del trade in quanto le equity line sono molto instabili e non significative su molte azioni. Inoltre va provato anche sui diversi time frame. Grazie

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

inserimento indicatore in strategia


ProOrder: Trading Automatico & Backtesting

New Reply
Author
author-avatar
traderwin @traderwin Participant
Summary

This topic contains 5 replies,
has 3 voices, and was last updated by luxrun
7 years, 6 months ago.

Topic Details
Forum: ProOrder: Trading Automatico & Backtesting
Language: Italian
Started: 07/31/2018
Status: Active
Attachments: No files
Logo Logo
Loading...