最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to convert TradingView Pine Script code to JavaScript? - Stack Overflow

programmeradmin2浏览0评论

There are some indicators on TradingView website that are in pine script and I like to add them to chart library so I have them on my website. But I've done a lot of search, and didn't find how to do that. Any help would be appreciated.

This is on of those indicators that I like to convert to JavaScript:

// This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) .0/
// © LuxAlgo
//@version=4

study("Nadaraya-Watson Estimator [LUX]",overlay=true,max_lines_count=500,max_bars_back=500)
h = input(8.,'Bandwidth')
src = input(close,'Source')
//----
n = bar_index
var ln = array.new_line(0) 
if barstate.isfirst
    for i = 0 to 499
        array.push(ln,line.new(na,na,na,na))
//----
float y2 = na
float y1 = na
float y1_d = na
//----
line l = na
label lb = na
if barstate.islast
    for i = 0 to min(499,n-1)
        sum = 0.
        sumw = 0.
        for j = 0 to min(499,n-1)
            w = exp(-(pow(i-j,2)/(h*h*2)))
            sum += src[j]*w
            sumw += w
        y2 := sum/sumw
        d = y2 - y1

        l := array.get(ln,i)
        line.set_xy1(l,n-i+1,y1)
        line.set_xy2(l,n-i,y2)
        line.set_color(l,y2 > y1 ? #ff1100 : #39ff14)
        line.set_width(l,2)
        
        if d > 0 and y1_d < 0
            label.new(n-i+1,src[i],'▲',color=#00000000,style=label.style_label_up,textcolor=#39ff14,textalign=text.align_center) 
        if d < 0 and y1_d > 0
            label.new(n-i+1,src[i],'▼',color=#00000000,style=label.style_label_down,textcolor=#ff1100,textalign=text.align_center) 

        y1 := y2
        y1_d := d

There are some indicators on TradingView website that are in pine script and I like to add them to chart library so I have them on my website. But I've done a lot of search, and didn't find how to do that. Any help would be appreciated.

This is on of those indicators that I like to convert to JavaScript:

// This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) https://creativemons/licenses/by-nc-sa/4.0/
// © LuxAlgo
//@version=4

study("Nadaraya-Watson Estimator [LUX]",overlay=true,max_lines_count=500,max_bars_back=500)
h = input(8.,'Bandwidth')
src = input(close,'Source')
//----
n = bar_index
var ln = array.new_line(0) 
if barstate.isfirst
    for i = 0 to 499
        array.push(ln,line.new(na,na,na,na))
//----
float y2 = na
float y1 = na
float y1_d = na
//----
line l = na
label lb = na
if barstate.islast
    for i = 0 to min(499,n-1)
        sum = 0.
        sumw = 0.
        for j = 0 to min(499,n-1)
            w = exp(-(pow(i-j,2)/(h*h*2)))
            sum += src[j]*w
            sumw += w
        y2 := sum/sumw
        d = y2 - y1

        l := array.get(ln,i)
        line.set_xy1(l,n-i+1,y1)
        line.set_xy2(l,n-i,y2)
        line.set_color(l,y2 > y1 ? #ff1100 : #39ff14)
        line.set_width(l,2)
        
        if d > 0 and y1_d < 0
            label.new(n-i+1,src[i],'▲',color=#00000000,style=label.style_label_up,textcolor=#39ff14,textalign=text.align_center) 
        if d < 0 and y1_d > 0
            label.new(n-i+1,src[i],'▼',color=#00000000,style=label.style_label_down,textcolor=#ff1100,textalign=text.align_center) 

        y1 := y2
        y1_d := d

Share Improve this question edited Jan 9, 2022 at 16:35 Bjorn Mistiaen 6,9153 gold badges23 silver badges47 bronze badges asked Oct 20, 2021 at 8:10 yaghoob_pryaghoob_pr 411 silver badge4 bronze badges 2
  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. – Community Bot Commented Oct 20, 2021 at 8:21
  • I doubt you can, it’s especially designed to run on their servers “Pine is cloud-based and therefore different in nature to client-side programming languages.” – nanobar Commented Oct 20, 2021 at 8:38
Add a ment  | 

3 Answers 3

Reset to default 3

There is no converter for such things. Pine Language has nothing to do with JavaScript, so you will need to write your own implementation for each function.

There is no converter for that. TradingView had provide a way to write custom indicators code using javascript. The guide link is below.

https://github./tradingview/charting_library/wiki/Creating-Custom-Studies

You can write your PineJs logic in javascript easily.

just in case you or someone else is still looking for a solution, I have a library for that exactly. basically it allows you to port pinescript indicators to JS and run them on nodejs or browser.

https://github./alaa-eddine/PineTS

发布评论

评论列表(0)

  1. 暂无评论