lunghezza segmento magicTrend

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #202249 quote
    MauroPro
    Participant
    Veteran

    Ciao Roberto, non riesco a quantificare la lunghezza dell’ultimo segmento dello stesso colore, prima del cambio di colore, del magicTrend (per usare tale paramentro come filtro).

    Esempio : acquisito quando cambia il colore del magicTrend SOLO se il segmento (la linea) del magicTrend precedente (chiaramente di colore opposto) è maggiore, ad esempio, di 20 (barre).

    Nella formula seguente ho già codificato il cambio di colore, potresti indicarmi come misurare la lunghezza dell’ultimo passsaggio di colore del magicTrend ? ( se la cosa non è chiara ti posto una bozza embrionale di TS  che stò costruendo) Grazie

    ,//******************************************************************** MagicTrend
    cciP = max(1,min(999,14)) //cciP = 20
    atrP = max(1,min(999,14)) //atrP = 14
    atrM = max(0.0000001,min(999,1)) //atrM = 1
    smaP = max(1,min(999,5)) //smaP = 5
    IF BarIndex > max(cciP,atrP) THEN
    lastCCI = thisCCI
    thisCCI = CCI[cciP](typicalPrice)
    myATR = AverageTrueRange[atrP](close)
    temp1 = myATR * atrM
    upT = low – temp1
    downT = high + temp1
    temp2 = Average[smaP,0](myATR) * atrM
    buffDN = high + temp2
    buffUP = low – temp2
    IF (thisCCI >= 0) AND (lastCCI < 0) THEN
    buffUP = buffDN[1]
    ENDIF
    IF (thisCCI <= 0) AND (lastCCI > 0) THEN
    buffDN = buffUP[1]
    ENDIF
    IF (thisCCI >= 0) THEN
    IF (buffUP < buffUP[1]) THEN
    buffUP = buffUP[1]
    ENDIF
    ELSIF (thisCCI <= 0) THEN
    IF (buffDN > buffDN[1]) THEN
    buffDN = buffDN[1]
    ENDIF
    ENDIF
    IF thisCCI >= 0 THEN
    MagicTrend = buffUP
    ELSIF thisCCI <= 0 THEN
    MagicTrend = buffDN
    ENDIF
    ELSE
    thisCCI = 0
    lastCCI = 0
    myATR = 0
    buffUP = 0
    buffDN = 0
    buffDN = 0
    buffUP = 0
    MagicTrend = 0
    ENDIF
    //————-
    if bullMagicTrend then // linea verde magicTrend
    bullMagicTrend = magicTrend >= magicTrend[1]
    if bullMagicTrend then
    bearMagicTrend = 0
    endif
    else
    bullMagicTrend = magicTrend > magicTrend[1]
    if bullMagicTrend then
    bearMagicTrend = 0
    endif
    endif
    //
    if bearMagicTrend then
    bearMagicTrend = magicTrend <= magicTrend[1] // linea rossa magicTrend
    if bearMagicTrend then
    bullMagicTrend = 0
    endif
    else
    bearMagicTrend = MagicTrend < MagicTrend[1]
    if bearMagicTrend then
    bullMagicTrend = 0
    endif
    endif
    //——————————–
    increaseMagic = magicTrend > magicTrend[1] // rialzo magicTrend
    decreaseMagic = magicTrend < magicTrend[1] // ribasso magicTrend
    change = (bullMagicTrend and bearMagicTrend[1]) OR (bearMagicTrend and bullMagicTrend[1])
    changeMagicUp = change and increaseMagic // passaggio rialzista magicTrend
    changeMagicDown = change and decreaseMagic // passaggio ribassista magicTrend

    #202271 quote
    robertogozzi
    Moderator
    Master

    Il seguente codice conteggia le barre, ContoP  è il conteggio del segmento precedente, Conto di quello corrente:

    ONCE Verde  = 1
    ONCE Rosso  = 1
    ONCE ContoP = 0
    ONCE Conto  = 0
    MT = CALL "Magic Trend custom"[20, 14, 1, 5]
    IF MT <> MT[1] THEN
       IF MT > MT[1] THEN
          IF Rosso THEN
             Rosso  = 0
             Verde  = 1
             ContoP = Conto
             Conto  = 0
          ENDIF
       ELSE
          IF Verde THEN
             Verde = 0
             Rosso = 1
             ContoP = Conto
             Conto  = 0
          ENDIF
       ENDIF
    ENDIF
    Conto = Conto + 1
    MauroPro thanked this post
    #202381 quote
    MauroPro
    Participant
    Veteran

    Ciao Roberto, ho fatto numerose prove e funziona bene (ho provato quello che mi interessava: ContoP).

    Ti volevo chiedere un altra cosa: è possibile in qualche modo visualizzare il guadagno mensile (in euro) di un TS sul grafico (in pratica la differenza dell’equity del primo ed ultimo del mese) ?

    #202392 quote
    robertogozzi
    Moderator
    Master

    Si, occorre salvare in una variabile il valore ad inizio mese, poi fare la differenza a fine mese e con GRAPH la vedrai:

    ONCE Equity     = 0
    ONCE Differenza = 0
    IF Month <> Month[1] THEN
       Differenza = StrategyProfit - Equity
       Equity     = StrategyProfit
    ENDIF
    GRAPH Differenza
    #202400 quote
    MauroPro
    Participant
    Veteran

    Ciao Roberto devo capire una cosa,  se quando cambia il mese l’operazione è ancora aperta (diciamo che il TS la apre il 27 e la chiude il 03) questa viene scartata dal calcolo del mese o viene calcolato il profitto attuale? Mi sembra che l’operazione non viene calcolata, ti risulta?

    #202403 quote
    robertogozzi
    Moderator
    Master

    Esatto, strategyprofit viene aggiornato solo alla chiusura, anche perché è l’unico momento in cui il risultato è definitivo.

    #202433 quote
    MauroPro
    Participant
    Veteran

    Esatto, le operazioni in corso non vengono conteggiate.. Riusciresti ad aggiungere un drawtext della differenza?

    #202446 quote
    robertogozzi
    Moderator
    Master

    La differenza la vedi con GRAPH (come ho fatto io sopra). I comandi grafici non possono essere usati con le strategie.

    #202447 quote
    MauroPro
    Participant
    Veteran

    Infatti, mi sembrava che con graph non si potevano visualizzare delle scritte però volevo esserne certo. Grazie

    #203164 quote
    MauroPro
    Participant
    Veteran

    Ciao Roberto, riusciresti ad aggiungere nella formula sopra in cui si plotta con DIFFERENZA il gain/loss in euro dei singoli mesi, anche un  graph con il DD, sempre mensile, calcolato come minimo rispetto alla chiusura del mese precedente  e non in generale?

    (ES. se  il proftto mensile precedente è stato 1000 e si scende, nel nuovo mese,  a 800 poi si sale a 1500 e si termina il mese a 1100, vorrei che venisse segnalato di DD 200 e non 400).

    Puoi utilizzare questa formula di base sul DD che avevi scritto tempo fa (non so se serve tempProfit in quanto si parla di operazioni chiude mensili):

    ONCE Capital = 10000

    ONCE MinPoint = Capital

    ONCE MaxPoint = 0

    ONCE MaxDD = 0

    //——————————————

    // EQUITY

    Equity = Capital + StrategyProfit

    TempProfit = PositionPerf * PositionPrice / PipSize

    TempEquity = Equity + TempProfit

    //——————————————

    // DrawDown

    MaxPoint = max(MaxPoint,TempEquity)

    DD = MaxPoint – TempEquity

    MaxDD = max(MaxDD,DD)

    //

    #203208 quote
    robertogozzi
    Moderator
    Master

    Eccolo:

    ONCE Equity1  = 0
    ONCE Diff     = 0
    IF Month <> Month[1] THEN
       Diff       = StrategyProfit - Equity1
       Equity1    = StrategyProfit
       MaxPoint   = 0
       MaxDD      = 0
    ENDIF
    //
    ONCE Capital  = 10000
    ONCE MinPoint = Capital
    ONCE MaxPoint = 0
    ONCE MaxDD    = 0
    //——————————————
    // EQUITY
    Equity2       = Capital + StrategyProfit
    TempProfit    = PositionPerf * PositionPrice / PipSize
    TempEquity    = Equity2 + TempProfit
    //——————————————
    // DrawDown
    MaxPoint      = max(MaxPoint,TempEquity)
    DD            = MaxPoint - TempEquity
    MaxDD         = max(MaxDD,DD)
    //---------------------------------------------------------
    //      esempio
    //
    once N = 20
    if close crosses over average[N,0](close) then
       buy at market
    elsif close crosses under average[N,0](close) then
       sellshort at market
    endif
    //
    GRAPH Diff  AS "Differenza Mese"
    GRAPH MaxDD AS "DrawDown Mese"
    MauroPro thanked this post
    #203215 quote
    MauroPro
    Participant
    Veteran

    Prende il DD generale non quello dalla chiusura del mese precedente al picco sotto questa chiusura.

    “DD calcolato come minimo rispetto alla chiusura del mese precedente e non in generale”

    Comunque ho riscritto così la formula e funziona:

    once capital = 10000
    equityThisMonth = capital + strategyProfit
    DD = min (DD,equityThisMonth-equityPrevMonth)
    if month <> month[1] then
    DDprevMonth = DD
    equityPrevMonth = capital + strategyProfit
    equityThisMonth = equityPrevMonth
    DD = 0
    performancePrevMonth = strategyProfit – actualSP
    actualSP = strategyProfit
    endif
    graph performancePrevMonth
    graph DDPrevMonth coloured(255,20,147)

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

lunghezza segmento magicTrend


ProOrder: Trading Automatico & Backtesting

New Reply
Author
author-avatar
MauroPro @mauropro Participant
Summary

This topic contains 11 replies,
has 2 voices, and was last updated by MauroPro
3 years, 3 months ago.

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