traduzione codice TW Trend reversal Predictor

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #230240 quote
    Msport71
    Participant
    Junior

    Buongiorno a tutti,

    vorrei provare questo interessante codice trovato su TW, abbastanza recente e che mi sembra interessante.

    Un grande grazie per il consueto aiuto.

    https://www.tradingview.com/script/T7AZI0z6-Trend-Reversal-Predictor/

    //@version=5
    indicator(“Danger Zones”, overlay=true)

    // Step 1: Trend Identification
    length = input.int(200, minval=1)
    src = input(close, title=”Source”)
    hma = ta.wma(2 * ta.wma(src, length / 2) – ta.wma(src, length), math.floor(math.sqrt(length)))
    start = input(0.02)
    increment = input(0.02)
    maximum = input(0.2, “Max Value”)
    sar = ta.sar(start, increment, maximum)

    trendUp = close > hma and close > sar
    trendDown = close < hma and close < sar
    trendNeutral = not trendUp and not trendDown

    // Step 2: Danger Zone Identification
    buyingVolumeSlowdownPeriod = input(5, title=”Buying Volume Slowdown Period”)
    sellingVolumeSlowdownPeriod = input(5, title=”Selling Volume Slowdown Period”)
    buyingVolumeRateOfChange = ta.change(volume, buyingVolumeSlowdownPeriod)
    sellingVolumeRateOfChange = ta.change(volume, sellingVolumeSlowdownPeriod)
    adrPeriod = input(14, title=”Average Daily Range (ADR) Period”)
    adr = ta.atr(adrPeriod)

    // Calculate average volume rate of change and net price movement
    averageBuyingVolumeRateOfChange = ta.sma(buyingVolumeRateOfChange, 5)
    averageSellingVolumeRateOfChange = ta.sma(sellingVolumeRateOfChange, 5)
    averageNetPriceMovement = ta.sma(close – close[1], 5)

    // RSI Integration
    ma(source, length, type) =>
    switch type
    “SMA” => ta.sma(source, length)
    “Bollinger Bands” => ta.sma(source, length)
    “EMA” => ta.ema(source, length)
    “SMMA (RMA)” => ta.rma(source, length)
    “WMA” => ta.wma(source, length)
    “VWMA” => ta.vwma(source, length)

    rsiLengthInput = input.int(14, minval=1, title=”RSI Length”, group=”RSI Settings”)
    rsiSourceInput = input.source(close, “Source”, group=”RSI Settings”)
    maTypeInput = input.string(“SMA”, title=”MA Type”, options=[“SMA”, “Bollinger Bands”, “EMA”, “SMMA (RMA)”, “WMA”, “VWMA”], group=”MA Settings”)
    maLengthInput = input.int(14, title=”MA Length”, group=”MA Settings”)
    bbMultInput = input.float(2.0, minval=0.001, maxval=50, title=”BB StdDev”, group=”MA Settings”)

    up = ta.rma(math.max(ta.change(rsiSourceInput), 0), rsiLengthInput)
    down = ta.rma(-math.min(ta.change(rsiSourceInput), 0), rsiLengthInput)
    rsi = down == 0 ? 100 : up == 0 ? 0 : 100 – (100 / (1 + up / down))
    rsiMA = ma(rsi, maLengthInput, maTypeInput)
    isBB = maTypeInput == “Bollinger Bands”
    rsiBelowMA = rsi < rsiMA
    rsiAboveMA = rsi > rsiMA

    // Step 3: Trend Ending Prediction

    // Combine Conditions
    uptrendDangerZone = trendUp and buyingVolumeRateOfChange <= averageBuyingVolumeRateOfChange and averageNetPriceMovement < 0 and rsiBelowMA
    downtrendDangerZone = trendDown and sellingVolumeRateOfChange <= averageSellingVolumeRateOfChange and averageNetPriceMovement > 0 and rsiAboveMA
    rsiConditionUp = trendUp and rsiBelowMA
    rsiConditionDown = trendDown and rsiAboveMA
    trendReversalConditionUp = uptrendDangerZone and rsiConditionUp
    trendReversalConditionDown = downtrendDangerZone and rsiConditionDown

    // Final Trend Ending Prediction
    trendEndingPredictionUp = trendReversalConditionUp and rsiBelowMA
    trendEndingPredictionDown = trendReversalConditionDown and rsiAboveMA

    bgcolor(uptrendDangerZone ? color.orange : downtrendDangerZone ? color.blue : na, transp=70)

    #230268 quote
    Iván González
    Moderator
    Master

    Ecco cosa hai:
    https://www.prorealcode.com/prorealtime-indicators/danger-zones-indicator/

    //PRC_Danger Zones
    //version = 0
    //22.03.24
    //Iván González @ www.prorealcode.com
    //Sharing ProRealTime knowledge
    //////////////////////////////////////////////////
    //------Inputs: Trend Identification--------------------//
    //----HMA
    length = 200
    src = customclose
    //----SAR
    start = 0.02
    increment = 0.02
    maximum = 0.2
    //-------Inputs: Danger Zone Identification--------------//
    //----Volume
    buyingVolumeSlowdownPeriod = 5 //Buying Volume Slowdown Period
    sellingVolumeSlowdownPeriod = 5 //Selling Volume Slowdown Period
    //----Moving average
    maTypeInput = 0 // MA Type
    maLengthInput = 14 // MA Length
    //----RSI
    rsiLengthInput = 14 // RSI Length
    rsiSourceInput = close // Source
    //-------------------------------------------------------//
    //-----Trend identification------------------------------//
    hma = hullaverage[length](src)
    psar = SAR[start,increment,maximum]
    trendup = close > hma and close > psar
    trenddown = close < hma and close < psar
    trendneutral = not trendup or not trenddown
    //-------------------------------------------------------//
    //-------Danger Zone Identification----------------------//
    // Calculate average volume rate of change
    buyingVolumeRateOfChange = Momentum[buyingVolumeSlowdownPeriod](volume)
    sellingVolumeRateOfChange = momentum[sellingVolumeSlowdownPeriod](volume)
    averageBuyingVolumeRateOfChange = average[5,0](buyingVolumeRateOfChange)
    averageSellingVolumeRateOfChange = average[5,0](sellingVolumeRateOfChange)
    // Calculate net price movement
    averageNetPriceMovement = average[5,0](close-close[1])
    // RSI integration
    src1 = max(momentum[1](rsiSourceInput),0)
    alpha1 = 1/rsiLengthInput
    if barindex = rsiLengthInput then
    up = average[rsiLengthInput](src1)
    else
    up = alpha1*src1 + (1-alpha1)*up[1]
    endif
    src2 = -min(momentum[1](rsiSourceInput),0)
    alpha2 = 1/rsiLengthInput
    if barindex = rsiLengthInput then
    down = average[rsiLengthInput](src2)
    else
    down = alpha2*src2 + (1-alpha2)*down[1]
    endif
    
    if down = 0 then
    myrsi = 100
    elsif up = 0 then
    myrsi = 0
    else
    myrsi = 100-(100/(1+up/down))
    endif
    rsiMa = average[maLengthInput,maTypeInput](myrsi)
    
    rsibelowMA = myrsi < rsiMA
    rsiaboveMA = myrsi > rsiMA
    //-----------------------------------------------------//
    //-----Trend ending Prediction-------------------------//
    // Combine Conditions
    uptrendDangerZone = trendUp and buyingVolumeRateOfChange <= averageBuyingVolumeRateOfChange and averageNetPriceMovement < 0 and rsiBelowMA
    downtrendDangerZone = trendDown and sellingVolumeRateOfChange <= averageSellingVolumeRateOfChange and averageNetPriceMovement > 0 and rsiAboveMA
    //-----------------------------------------------------//
    if uptrendDangerZone then
    backgroundcolor(255,152,0,70)
    elsif downtrendDangerZone then
    backgroundcolor(33,150,243,70)
    endif
    
    return
    
    Msport71 thanked this post
    #230277 quote
    Msport71
    Participant
    Junior

    Gentilissimo, geazie!

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

traduzione codice TW Trend reversal Predictor


ProBuilder: Indicatori & Strumenti Personalizzati

New Reply
Author
author-avatar
Msport71 @carlo-pasca Participant
Summary

This topic contains 2 replies,
has 2 voices, and was last updated by Msport71
1 year, 11 months ago.

Topic Details
Forum: ProBuilder: Indicatori & Strumenti Personalizzati
Language: Italian
Started: 03/22/2024
Status: Active
Attachments: No files
Logo Logo
Loading...