Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

ATR stop loss finder convert from TV

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    ATR stop loss finder convert from TV

    Was wondering if this is a place where I can get help converting this tradingview script to ninja script
    Any help is greatly appreciated!
    Thanks

    study(title="Average True Range Stop Loss Finder", shorttitle="ATR", overlay=true)
    length = input(title="Length", defval=14, minval=1)
    smoothing = input(title="Smoothing", defval="RMA", options=["RMA", "SMA", "EMA", "WMA"])
    m = input(1.5, "Multiplier")
    src1 = input(high)
    src2 = input(low)
    pline = input(true, "Show Price Lines")
    col1 = input(color.blue, "ATR Text Color")
    col2 = input(color.teal, "Low Text Color",inline ="1")
    col3 = input(color.red, "High Text Color",inline ="2")

    collong = input(color.teal, "Low Line Color",inline ="1")
    colshort = input(color.red, "High Line Color",inline ="2")

    ma_function(source, length) =>
    if smoothing == "RMA"
    rma(source, length)
    else
    if smoothing == "SMA"
    sma(source, length)
    else
    if smoothing == "EMA"
    ema(source, length)
    else
    wma(source, length)

    a = ma_function(tr(true), length) * m
    x = ma_function(tr(true), length) * m + src1
    x2 = src2 - ma_function(tr(true), length) * m

    p1 = plot(x, title = "ATR Short Stop Loss", color= colshort, transp=20, trackprice = pline ? true : false)
    p2 = plot(x2, title = "ATR Long Stop Loss", color= collong, transp=20, trackprice = pline ? true : false)

    var table Table = table.new(position.bottom_center, 3, 1, border_width = 3)

    f_fillCell(_table, _column, _row, _value, _timeframe) =>

    _cellText = _timeframe+ tostring(_value, "#.#")
    table.cell(_table, _column, _row, _cellText, text_color = col1)
    table.cell_set_text_color(Table, 1, 0, color.new(col3, transp = 0))
    table.cell_set_text_color(Table, 2, 0, color.new(col2, transp = 0))

    if barstate.islast
    f_fillCell(Table, 0, 0, a, "ATR: " )
    f_fillCell(Table, 1, 0, x, "H: " )
    f_fillCell(Table, 2, 0, x2, "L: " )​

    #2
    Bascially what I am trying to do is make an indicator with two SMA's, above and below, with a length of 1, and using the data source of ATR high and low.

    Click image for larger version

Name:	image.png
Views:	326
Size:	170.1 KB
ID:	1215056

    Comment


      #3
      Hello ChadAnt,

      This would be the forum to ask questions about your indicator development. Was there a specific part of the code that you had a question about? If you are asking about the entire code I would suggest to look at some of the stock indicators first to get a good handle on how to make indicators and plots before trying to convert a script. You can use existing indicators like the SMA or ATR from NinjaScript.

      You can find some information about using the ATR for targets in the following post that includes a sample: https://ninjatrader.com/support/foru...42#post1142942

      Comment


        #4
        Originally posted by ChadAnt View Post
        Was wondering if this is a place where I can get help converting this tradingview script to ninja script
        Any help is greatly appreciated!
        Thanks

        study(title="Average True Range Stop Loss Finder", shorttitle="ATR", overlay=true)
        length = input(title="Length", defval=14, minval=1)
        smoothing = input(title="Smoothing", defval="RMA", options=["RMA", "SMA", "EMA", "WMA"])
        m = input(1.5, "Multiplier")
        src1 = input(high)
        src2 = input(low)
        pline = input(true, "Show Price Lines")
        col1 = input(color.blue, "ATR Text Color")
        col2 = input(color.teal, "Low Text Color",inline ="1")
        col3 = input(color.red, "High Text Color",inline ="2")

        collong = input(color.teal, "Low Line Color",inline ="1")
        colshort = input(color.red, "High Line Color",inline ="2")

        ma_function(source, length) =>
        if smoothing == "RMA"
        rma(source, length)
        else
        if smoothing == "SMA"
        sma(source, length)
        else
        if smoothing == "EMA"
        ema(source, length)
        else
        wma(source, length)

        a = ma_function(tr(true), length) * m
        x = ma_function(tr(true), length) * m + src1
        x2 = src2 - ma_function(tr(true), length) * m

        p1 = plot(x, title = "ATR Short Stop Loss", color= colshort, transp=20, trackprice = pline ? true : false)
        p2 = plot(x2, title = "ATR Long Stop Loss", color= collong, transp=20, trackprice = pline ? true : false)

        var table Table = table.new(position.bottom_center, 3, 1, border_width = 3)

        f_fillCell(_table, _column, _row, _value, _timeframe) =>

        _cellText = _timeframe+ tostring(_value, "#.#")
        table.cell(_table, _column, _row, _cellText, text_color = col1)
        table.cell_set_text_color(Table, 1, 0, color.new(col3, transp = 0))
        table.cell_set_text_color(Table, 2, 0, color.new(col2, transp = 0))

        if barstate.islast
        f_fillCell(Table, 0, 0, a, "ATR: " )
        f_fillCell(Table, 1, 0, x, "H: " )
        f_fillCell(Table, 2, 0, x2, "L: " )​
        Ha! I just converted this and was looking to see if anyone had already! Looks like people have been asking. Did you ever get this?

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        564 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        329 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        547 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        548 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X