Pine editor tradingview indicator to PRT

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #226987 quote
    Robbie555
    Participant
    New
    //@version=4
    study("TN Alerts v13", overlay=true)
    // This indicator is designed to run with period setting "week"
    // Settings Inputs Section
    tsPercent= input(defval = 20, title = "Trailing Stop")/100
    wma4_sw = input(true, title="Display wma4")
    wma62_sw = input(true, title="Display wma62")
    TSswitch = input(true, title="Display Stoploss")
    BGswitch = input(true, title="Display BG Color")
    REswitch = input(true, title="Display Re-entry?")
    // Calculation Section
    enterlong = (wma(close,62)>wma(close,62)[1]) and (close>wma(close,4)) and (close[1]>wma(close,4)[1]) and (close>close[1])
    entershort = (wma(close,62)<wma(close,62)[1]) and (close<wma(close,4)) and (close[1]<wma(close,4)[1]) and (close<close[1])
    trail_top = float(na)
    trail_top := (close>trail_top[1]) or (close<trail_top[1]*(1-tsPercent)) or (entershort)?close:na(trail_top[1])?close:trail_top[1]
    plot(trail_top)
    trail_bot = float(na)
    trail_bot := (close<trail_bot[1]) or (close>trail_bot[1]*(1+tsPercent)) or (enterlong)?close:na(trail_bot[1])?close:trail_bot[1]
    exitlong = trail_top<trail_top[1]
    exitshort = trail_bot>trail_bot[1]
    inlong = bool(na)
    inlong := enterlong?true:(entershort or exitlong)?false:inlong[1]
    inshort = bool(na)
    inshort := entershort?true:(enterlong or exitshort)?false:inshort[1]
    // Output section
    plot(wma4_sw ? wma(close,4) : na, title="WMA 4", color=color.blue, linewidth=2)
    plot(wma62_sw ? wma(close,62) : na, title="WMA 62", color=color.purple, linewidth=2)
    plot(inlong and TSswitch?trail_top * (1-tsPercent):na, title="Trading Stop Long", linewidth=4, style=plot.style_circles,color=color.red)
    plot(inshort and TSswitch?trail_bot * (1+tsPercent):na, title="Trading Stop Short", linewidth=4, style=plot.style_circles,color=color.green)
    bgcolor(BGswitch and inlong ? color.new(color.green, 85) : na, title="Background Long Period")
    bgcolor(BGswitch and inshort ? color.new(color.red, 85) : na, title="Background Short Period")
    plotshape(enterlong and not inlong[1], title="Buy Signal", color=color.green, style=shape.arrowup, text="Buy", location=location.belowbar, offset=0, size=size.small)
    plotshape(entershort and not inshort[1], title="Sell Signal", color=color.red, style=shape.arrowdown, text="Sell", location=location.abovebar, offset=0, size=size.small)
    plotshape(exitlong and inlong[1] and not entershort, title="Stoploss Long Signal", color=color.black, style=shape.triangledown, text="Buy Exit", location=location.abovebar, offset=0, size=size.small)
    plotshape(exitshort and inshort[1] and not enterlong, title="Stoploss Short Signal", color=color.black, style=shape.triangleup, text="Sell Exit", location=location.belowbar, offset=0, size=size.small)
    plotshape(REswitch and enterlong and inlong and inlong[1], title="Re-entry Long signal" ,color=color.aqua, style=shape.arrowup, text="RE", location=location.belowbar, offset=0, size=size.small)
    plotshape(REswitch and entershort and inshort and inshort[1], title="Re-entry Short signal" ,color=color.silver, style=shape.arrowdown, text="RES", location=location.abovebar, offset=0, size=size.small)
    // Alert section Create 'Alert' see also https://uk.tradingview.com/pine-script-reference/v4/#fun_alertcondition 
    alertcondition(enterlong and not inlong[1] or exitshort and inshort[1] , title="There is a Buy- or STOPLOSS SHORT Signal", message="Buy/STOPLOSS SHORT signal! \n{{exchange}}:{{ticker}}, price= {{'Source'}}\n{{time}}, volume= {{volume}}")
    alertcondition(entershort and not inshort[1] or exitlong and inlong[1] , title="There is a Sell- or STOPLOSS LONG Signal", message="Sell/STOPLOSS LONG signal! \n{{exchange}}:{{ticker}}, price={{'Source'}}\n{{time}}, volume= {{volume}}")
    plot(close)
    #229582 quote
    Iván González
    Moderator
    Master

    Good morning

    //PRC_TN alerts
    //version = 0
    //11.03.24
    //Iván González @ www.prorealcode.com
    //Sharing ProRealTime knowledge
    //inputs
    TS = 20 //% Trailing stop
    TSswitch = 1 // Display Stoploss
    BGswitch = 1 // Display BG color
    REswtich = 1 // Display Re-entry
    ////
    wma62 = average[62,2](close)
    wma4 = average[4,2](close)
    tsPercent = TS/100 //Trailing stop
    
    enterlong = wma62>wma62[1] and close>wma4 and close[1]>wma4[1] and close>close[1]
    entershort = wma62<wma62[1] and close<wma4 and close[1]<wma4[1] and close<close[1]
    
    //(close>trail_top[1]) or (close<trail_top[1]*(1-tsPercent)) or (entershort
    once trailTop = close
    
    if close>trailtop[1] or close<trailtop[1]*(1-tspercent) or entershort then
    trailTop = close
    else
    trailTop = trailTop[1]
    endif
    //trail_bot := (close<trail_bot[1]) or (close>trail_bot[1]*(1+tsPercent)) or (enterlong)?close:na(trail_bot[1])?close:trail_bot[1]
    once trailBot = close
    
    if close<trailBot[1] or close>trailBot[1]*(1+tspercent) or enterlong then
    trailBot = close
    else
    trailBot = trailBot[1]
    endif
    
    exitlong = trailTop < trailTop[1]
    exitsh = trailBot > trailBot[1]
    
    if enterlong then
    inlong = 1
    elsif entershort or exitlong then
    inlong = 0
    else
    inlong = inlong[1]
    endif
    
    if entershort then
    inshort = 1
    elsif enterlong or exitsh then
    inshort = 0
    else
    inshort = inshort
    endif
    ////Drawing trails
    if inlong and Tsswitch then
    drawpoint(barindex,TrailTop*(1-tspercent),3)coloured("red")
    elsif inshort and Tsswitch then
    drawpoint(barindex,TrailBot*(1+tspercent),3)coloured("green")
    endif
    ////Background colors
    if inlong and BGswitch then
    backgroundcolor("green",15)
    elsif inshort and BGswitch then
    backgroundcolor("red",15)
    endif
    ////Plot signals
    if enterlong and not inlong[1] then
    drawarrowup(barindex,low-0.25*tr)coloured("green")
    elsif entershort and not inshort[1] then
    drawarrowdown(barindex,high+0.25*tr)coloured("red")
    elsif REswtich and enterlong and inlong and inlong[1] then
    drawarrowup(barindex,low-0.25*tr)coloured("blue",85)
    elsif REswtich and entershort and inshort and inshort[1] then
    drawarrowdown(barindex,high+0.25*tr)coloured("gray",85)
    elsif exitlong and inlong[1] and not entershort then
    drawtext("▼",barindex,high+0.25*tr)coloured("black")
    elsif exitsh and inshort[1] and not enterlong then
    drawtext("▲",barindex,low-0.25*tr)coloured("black")
    endif
    
    return wma4 as "WMA4"coloured("blue"), wma62 as "WMA62"coloured("purple")
    
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.

Pine editor tradingview indicator to PRT


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
Robbie555 @robbie555 Participant
Summary

This topic contains 1 reply,
has 2 voices, and was last updated by Iván González
1 year, 11 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 01/28/2024
Status: Active
Attachments: No files
Logo Logo
Loading...