traduzione codice TW Hoffman’s scalp indicator

Forums ProRealTime forum Italiano Supporto ProBuilder traduzione codice TW Hoffman’s scalp indicator

Viewing 3 posts - 1 through 3 (of 3 total)
  • #229748

    Buongiorno a tutti,

    vorrei testare questo interessante codice trovato su TW, che mi sembra interessante (se non ho capito male combina i cross delle medie mobili ma tiene conto anche dell’ampiezza di eventuali ritracciamenti).

    Un grande grazie per il consueto aiuto.

     

    https://it.tradingview.com/script/QXyZfgBb-T-I-P-Hoffman-s-scalp-indicator/

    //@version=5
    indicator(“Hoffman’s scalp indicator [T.I.P.]”, overlay=true)

    PlotMA = input(defval=false, title=”Show MA lines”)

    AutoProfit = input(defval=true, title=”Stop loss according to Moving Average (with risk reward ratio)” , group=”Profit settings”)
    useATR = input(false, “Use ATR for stop loss (with risk reward ratio)”, group = “Profit settings”)
    riskreward = input(1.5, title = “Risk reward ratio”, group=”Profit settings”)
    OpenPositionTreshold = input(defval=1, title=”Open position threshold %” , group=”Profit settings”)
    myTakeProfit = input(defval=1.50, title=”TakeProfit % (if not in use ATR or MA for SL)” , group=”Profit settings”)
    myStopLos = input(defval=1.00, title=”StopLoss % (if not in use ATR or MA for SL)”, group=”Profit settings”)
    Show_TPSLLines = input(defval=true, title=”Show take profit & stop loss lines”, group=”Profit settings”)

    sma5 = ta.sma(close,5)
    ema18 = ta.ema(close,18)
    ema20 = ta.ema(close,20)
    ema35 = ta.ema(close,35)
    sma50 = ta.sma(close,50)
    sma89 = ta.sma(close,89)
    ema144 = ta.ema(close,144)

    //—————Hoffmans bar retracements————————————–
    z = input.int(45, title=”Inventory Retracement Percentage %”, maxval=100, group=”Retracements settings”)

    // Candle Range
    a = math.abs(high – low)
    // Candle Body
    b = math.abs(close – open)
    // Percent to Decimal
    c = z/100

    // Range Verification
    rv = b < c*a

    // Price Level for Retracement
    x = low + (c * a)
    y = high – (c * a)

    sl = rv == 1 and high > y and close < y and open < y
    ss = rv == 1 and low < x and close > x and open > x

    // Line Definition
    li = sl ? y : ss ? x : (x+y)/2
    //——————————————————————————

    //———–Volume Oscillator————————————————–
    useVOL = input(false, “Use volume oscillator for signals”, group = “Volume Oscillator”)
    var cumVol = 0.
    cumVol += nz(volume)
    if barstate.islast and cumVol == 0
    runtime.error(“No volume is provided by the data vendor.”)
    shortlen = input.int(5, minval=1, title = “Short Length”, group = “Volume Oscillator”)
    longlen = input.int(10, minval=1, title = “Long Length”, group = “Volume Oscillator”)
    short = ta.ema(volume, shortlen)
    long = ta.ema(volume, longlen)
    osc = 100 * (short – long) / long
    //hline(0, color = #787B86, title=”Zero”)
    //plot(osc, color=#2962FF)
    //——————————————————————————

    //———————ATR——————————————————
    showATR = input(false, “Show ATR on chart”, group = “ATR”)
    atrlength = input.int(title=”Length”, defval=14, minval=1, group=”ATR”)
    atrsmoothing = input.string(title=”Smoothing”, defval=”RMA”, options=[“RMA”, “SMA”, “EMA”, “WMA”], group=”ATR”)
    atrm = input(0.85, “Multiplier”, group=”ATR”)
    atrsrc1 = input(high, group=”ATR”)
    atrsrc2 = input(low, group=”ATR”)
    atrpline = input(false, “Show ATR Price Lines”, group = “ATR”)

    atrcollong = input(color.teal, “Low Line Color”,inline =”1″, group=”ATR”)
    atrcolshort = input(color.red, “High Line Color”,inline =”2″, group=”ATR”)

    atrma_function(source, atrlength) =>
    if atrsmoothing == “RMA”
    ta.rma(source, atrlength)
    else
    if atrsmoothing == “SMA”
    ta.sma(source, atrlength)
    else
    if atrsmoothing == “EMA”
    ta.ema(source, atrlength)
    else
    ta.wma(source, atrlength)

    atra = atrma_function(ta.tr(true), atrlength) * atrm
    atrx = atrma_function(ta.tr(true), atrlength) * atrm + atrsrc1
    atrx2 = atrsrc2 – atrma_function(ta.tr(true), atrlength) * atrm

    atrp1 = plot(showATR ? atrx : na, title = “ATR Short Stop Loss”, color = color.new(atrcolshort, 20), trackprice = atrpline ? true : false)
    atrp2 = plot(showATR ? atrx2 : na, title = “ATR Long Stop Loss”, color = color.new(atrcollong, 20), trackprice = atrpline ? true : false)
    //——————————————————————————

    //————-Plot Statement—————————————————
    LongHoff = sl and sma5>ema18 and ema18>ema20 and ema20>ema144 and low>sma5
    ShortHoff = ss and sma5<ema18 and ema18<ema20 and ema20<ema144 and high<sma5
    plotshape(LongHoff, style=shape.triangledown, location=location.abovebar, color=color.red, title = “Long Bar”, transp = 0)
    plotshape(ShortHoff, style=shape.triangleup, location=location.belowbar, color=color.green, title = “Short Bar”, transp = 0)

    long_condition = false
    short_condition = false
    if useVOL
    long_condition := LongHoff and close > sma50 and osc > 0
    short_condition := ShortHoff and close < sma50 and osc > 0
    else
    long_condition := LongHoff and close > sma50
    short_condition := ShortHoff and close < sma50

    //label Short = na
    //label Long = na
    plotshape(short_condition, style=shape.circle, location=location.abovebar, color=color.red, title = “short signal”, transp = 0)
    plotshape(long_condition, style=shape.circle, location=location.belowbar, color=color.green, title = “long signal”, transp = 0)

    if barstate.isconfirmed
    if short_condition
    Short = label.new(bar_index,high + (((high-low)/100)*5),text=”Short”,size=size.normal,color=color.red,style=label.style_label_down,textcolor=color.white)
    label.delete(Short[1])

    if barstate.isconfirmed
    if long_condition
    Long = label.new(bar_index,low – (((high-low)/100)*5),text=”Long”,size=size.normal,color=color.green,style=label.style_label_up,textcolor=color.white)
    label.delete(Long[1])

    plot(PlotMA ? sma50 : na, title=”SMA50″, color = color.white,linewidth=2)
    plot(PlotMA ? sma5 : na, title=”SMA5″, color = color.purple,linewidth=2)
    plot(PlotMA ? ema18 : na, title=”EMA18″, color = color.green,linewidth=2)
    plot(PlotMA ? ema20 : na, title=”EMA20″, color = color.silver,linewidth=1)
    plot(PlotMA ? sma89 : na, title=”SMA89″, color = color.silver,linewidth=1)
    plot(PlotMA ? ema144 : na, title=”EMA144″, color = color.silver,linewidth=1)
    plot(PlotMA ? ema35 : na, title=”EMA35″, color = color.silver,linewidth=1)
    //——————————————————————————

    //———–Plot SL & TP lines————————————————-
    StopLosY = sma5
    TakeProfitY = high + (OpenPositionTreshold * ((high-low)/100)) + (riskreward * ((high+ (OpenPositionTreshold * ((high-low)/100)))-sma5))

    if useATR
    StopLosY := atrx2
    TakeProfitY := high + (OpenPositionTreshold * ((high-low)/100)) + (riskreward * ((high+ (OpenPositionTreshold * ((high-low)/100)))-atrx2))
    else
    StopLosY := AutoProfit ? sma5 : (high + (OpenPositionTreshold * ((high-low)/100))) – ((myStopLos/(((high + (OpenPositionTreshold * ((high-low)/100)))-low)/(low/100)))*((high + (OpenPositionTreshold * ((high-low)/100)))-low))
    TakeProfitY := AutoProfit ? high + (OpenPositionTreshold * ((high-low)/100)) + (riskreward * ((high+ (OpenPositionTreshold * ((high-low)/100)))-sma5)) : high + (OpenPositionTreshold * ((high-low)/100)) +((myTakeProfit/((high-low)/(low/100)))*(high-low))

    if barstate.isconfirmed
    if long_condition and Show_TPSLLines
    OpenLineLong = line.new(bar_index + 1, high + (OpenPositionTreshold * ((high-low)/100)),bar_index + 30,high + (OpenPositionTreshold * ((high-low)/100)),color=color.gray,style=line.style_dotted,width=3)
    OpenLabelLong = label.new(bar_index + 1,high + (OpenPositionTreshold * ((high-low)/100)),text=”open position here”,size=size.small,color=color.gray,style=label.style_label_right,textcolor=color.white)
    OpenLabelLongPrice = label.new(bar_index + 30,high + (OpenPositionTreshold * ((high-low)/100)),text = str.tostring(high + (OpenPositionTreshold * ((high-low)/100))),size=size.small,color=color.gray,style=label.style_label_left,textcolor=color.white)
    StopLosLine = line.new(bar_index + 1, StopLosY,bar_index + 50,StopLosY,color=color.maroon,style=line.style_dotted,width=3)
    StopLosLabel = label.new(bar_index + 1,StopLosY,text=”stop loss”,size=size.small,color=color.maroon,style=label.style_label_upper_right,textcolor=color.white)
    StopLosLabelPrice = label.new(bar_index + 50,StopLosY,text=str.tostring(StopLosY),size=size.small,color=color.maroon,style=label.style_label_upper_left,textcolor=color.white)
    TakeProfitLine = line.new(bar_index + 1,TakeProfitY,bar_index + 50,TakeProfitY,color=color.teal,style=line.style_dotted,width=3)
    TakeProfitLabel = label.new(bar_index + 1,TakeProfitY,text=”take profit”,size=size.small,color=color.teal,style=label.style_label_lower_right,textcolor=color.white)
    TakeProfitLabelPrice = label.new(bar_index + 50,TakeProfitY,text=str.tostring(TakeProfitY),size=size.small,color=color.teal,style=label.style_label_lower_left,textcolor=color.white)
    line.delete(OpenLineLong[1])
    line.delete(StopLosLine[1])
    line.delete(TakeProfitLine[1])
    label.delete(StopLosLabel[1])
    label.delete(TakeProfitLabel[1])
    label.delete(OpenLabelLong[1])
    label.delete(OpenLabelLongPrice[1])
    label.delete(StopLosLabelPrice[1])
    label.delete(TakeProfitLabelPrice[1])
    l_alert = “LONG alarm, Entry price:” + str.tostring(high + (OpenPositionTreshold * ((high-low)/100))) + “, SL:” + str.tostring(StopLosY) + “, TP:” + str.tostring(TakeProfitY)
    alert(l_alert,alert.freq_once_per_bar_close)

    sStopLosY = sma5
    sTakeProfitY = (low – (OpenPositionTreshold * ((high-low)/100))) – (riskreward * (sma5 – (low – (OpenPositionTreshold * ((high-low)/100)))))

    if useATR
    sStopLosY := atrx
    sTakeProfitY := (low – (OpenPositionTreshold * ((high-low)/100))) – (riskreward * (atrx – (low – (OpenPositionTreshold * ((high-low)/100)))))
    else
    sStopLosY := AutoProfit ? sma5 : (low – (OpenPositionTreshold * ((high-low)/100))) + ((myStopLos/((high-(low – (OpenPositionTreshold * ((high-low)/100))))/((low – (OpenPositionTreshold * ((high-low)/100)))/100)))*(high-(low – (OpenPositionTreshold * ((high-low)/100)))))
    sTakeProfitY := AutoProfit ? (low – (OpenPositionTreshold * ((high-low)/100))) – (riskreward * (sma5 – (low – (OpenPositionTreshold * ((high-low)/100))))) : (low – (OpenPositionTreshold * ((high-low)/100))) – ((myTakeProfit/((high-(low – (OpenPositionTreshold * ((high-low)/100))))/((low – (OpenPositionTreshold * ((high-low)/100)))/100)))*(high-(low – (OpenPositionTreshold * ((high-low)/100)))))

    if barstate.isconfirmed
    if short_condition and Show_TPSLLines
    OpenLineShort = line.new(bar_index + 1, (low – (OpenPositionTreshold * ((high-low)/100))), bar_index + 30, (low – (OpenPositionTreshold * ((high-low)/100))), color=color.gray,style=line.style_dotted,width=3)
    OpenLabelShort = label.new(bar_index + 1,(low – (OpenPositionTreshold * ((high-low)/100))),text=”open position here”,size=size.small,color=color.gray,style=label.style_label_right,textcolor=color.white)
    OpenLabelShortPrice = label.new(bar_index + 30,(low – (OpenPositionTreshold * ((high-low)/100))),text= str.tostring(low – (OpenPositionTreshold * ((high-low)/100))),size=size.small,color=color.gray,style=label.style_label_left,textcolor=color.white)
    sTakeProfitLine = line.new(bar_index + 1, sTakeProfitY,bar_index + 50,sTakeProfitY,color=color.teal,style=line.style_dotted,width=3)
    sTakeProfitLabel = label.new(bar_index + 1,sTakeProfitY,text=”take profit”,size=size.small,color=color.teal,style=label.style_label_upper_right,textcolor=color.white)
    sTakeProfitLabelPrice = label.new(bar_index + 50,sTakeProfitY,text= str.tostring(sTakeProfitY),size=size.small,color=color.teal,style=label.style_label_upper_left,textcolor=color.white)
    sStopLosLine = line.new(bar_index + 1,sStopLosY,bar_index + 50,sStopLosY,color=color.maroon,style=line.style_dotted,width=3)
    sStopLosLabel = label.new(bar_index + 1,sStopLosY,text=”stop loss”,size=size.small,color=color.maroon,style=label.style_label_lower_right,textcolor=color.white)
    sStopLosLabelPrice = label.new(bar_index + 50,sStopLosY,text= str.tostring(sStopLosY),size=size.small,color=color.maroon,style=label.style_label_lower_left,textcolor=color.white)
    line.delete(OpenLineShort[1])
    line.delete(sStopLosLine[1])
    line.delete(sTakeProfitLine[1])
    label.delete(sStopLosLabel[1])
    label.delete(sTakeProfitLabel[1])
    label.delete(OpenLabelShort[1])
    label.delete(OpenLabelShortPrice[1])
    label.delete(sTakeProfitLabelPrice[1])
    label.delete(sStopLosLabelPrice[1])
    s_alert = “SHORT alarm, Entry price:” + str.tostring(low – (OpenPositionTreshold * ((high-low)/100))) + “, SL:” + str.tostring(sStopLosY) + “, TP:” + str.tostring(sTakeProfitY)
    alert(s_alert,alert.freq_once_per_bar_close)
    //——————————————————————————

    //———Send alert to TV alarm sub-system————————————
    alertcondition(long_condition, title=”LONG alarm”, message=”Long signal!!! OP:{{open position here}}, SL:{{sl_level}}, TP:{{tp_level}}”)
    alertcondition(short_condition, title=”SHORT alarm”, message=”Short signal!!! OP:{{open position here}}, SL:{{ssl_level}}, TP:{{stp_level}}”)
    //——————————————————————————

    #229759

    Aquí tienes:

    #229771

    Grazie e mille, velocissimo!

     

Viewing 3 posts - 1 through 3 (of 3 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login