我可以创建一个Pine Editor中的扫描器/股票筛选器吗?我试过但遇到了问题。

huangapple go评论57阅读模式
英文:

Can I create a scanner/stock screener in Pine Editor? I am having problems trying

问题

我是新手使用TradingView - 我想使用它的主要原因是创建我自己的自定义扫描,使用了Interactive Brokers扫描器上看不到的13和30小时图上的简单移动平均线。

在TradingView的股票筛选器中,似乎没有选项来更改移动平均线。

我尝试了Pine编辑器的代码,但将其编写到编辑器后,它似乎只能保存,没有其他操作。

英文:

I am new to TradingView - the main reason I want to use it is to create my own custom scan using moving averages that I cannot seem to be able to use on Interactive Brokers scanner - the 13 and 30 Simple moving averages on the hourly chart.

On the Stock Screener in Trading View filters it doesn't seem to give the option to change the moving averages.

I have tried a pine editor code but after writing it into the editor the only things it seemed to be able to do was save it and nothing else.

答案1

得分: 1

以下是您提供的代码的翻译部分:

"You can't currently scan based on Pine. You can however create a script that you can input symbols to and have it return if they meet your MA criteria like mentioned in the answer above.

Here's an example that will test if the 60 minute close is greater than both moving averages and then return true or false in a table. You can add more symbols, I only used two for the example.

//@version=5
indicator("My script", overlay = true)

sym1 = input.symbol('TSLA', 'Symbol 1')
sym2 = input.symbol('NVDA', 'Symbol 2')

method mas(string symbol) =>
ma1 = request.security(symbol, '60', ta.sma(close,13))
ma2 = request.security(symbol, '60', ta.sma(close,30))
price = request.security(symbol, '60', close)
priceLow = request.security(symbol, '60', low)
[ma1, ma2, price, priceLow]

[sym1MA13, sym1MA30, sym1Close, sym1Low] = sym1.mas()
[sym2MA13, sym2MA30, sym2Close, sym2Low] = sym2.mas()

sym1lower = false
sym2lower = false
for i = 0 to 9
if sym1Low < sym1MA13 or sym1Low < sym1MA30
sym1lower := true
for i = 0 to 9
if sym2Low < sym2MA13 or sym2Low < sym2MA30
sym2lower := true

var table screener = table.new(position.top_right, 3, 2, bgcolor = color.white, border_color = color.black, border_width = 2, frame_color = color.black, frame_width = 2)

if barstate.islast
screener.cell(0,0, str.tostring(sym1))
screener.cell(0,1, str.tostring(sym2))
screener.cell(1,0, str.tostring(sym1Close > sym1MA13 and sym1Close > sym1MA30), bgcolor = (sym1Close > sym1MA13 and sym1Close > sym1MA30 ? color.green : color.red))
screener.cell(1,1, str.tostring(sym2Close > sym2MA13 and sym2Close > sym2MA30), bgcolor = (sym2Close > sym2MA13 and sym2Close > sym2MA30 ? color.green : color.red))
screener.cell(2,0, str.tostring(sym1lower), bgcolor = sym1lower == false ? color.green : color.red)
screener.cell(2,1, str.tostring(sym2lower), bgcolor = sym2lower == false ? color.green : color.red)"

请注意,代码中的HTML实体已被翻译为正常的字符。如果您有任何其他翻译需求,请随时告诉我。

英文:

You can't currently scan based on Pine. You can however create a script that you can input symbols to and have it return if they meet your MA criteria like mentioned in the answer above.

Here's an example that will test if the 60 minute close is greater than both moving averages and then return true or false in a table. You can add more symbols, I only used two for the example.

//@version=5
indicator(&quot;My script&quot;, overlay = true)

sym1 = input.symbol(&#39;TSLA&#39;, &#39;Symbol 1&#39;)
sym2 = input.symbol(&#39;NVDA&#39;, &#39;Symbol 2&#39;)

method mas(string symbol) =&gt;
    ma1 = request.security(symbol, &#39;60&#39;, ta.sma(close,13))
    ma2 = request.security(symbol, &#39;60&#39;, ta.sma(close,30))
    price = request.security(symbol, &#39;60&#39;, close)
    priceLow = request.security(symbol, &#39;60&#39;, low)
    [ma1, ma2, price, priceLow]

[sym1MA13, sym1MA30, sym1Close, sym1Low] = sym1.mas()
[sym2MA13, sym2MA30, sym2Close, sym2Low] = sym2.mas()

sym1lower = false
sym2lower = false
for i = 0 to 9
    if sym1Low &lt; sym1MA13 or sym1Low &lt; sym1MA30
        sym1lower := true
for i = 0 to 9
    if sym2Low &lt; sym2MA13 or sym2Low &lt; sym2MA30
        sym2lower := true

var table screener = table.new(position.top_right, 3, 2, bgcolor = color.white, border_color = color.black, border_width = 2,  frame_color = color.black, frame_width = 2)

if barstate.islast
    screener.cell(0,0, str.tostring(sym1))
    screener.cell(0,1, str.tostring(sym2))
    screener.cell(1,0, str.tostring(sym1Close &gt; sym1MA13 and sym1Close &gt; sym1MA30), bgcolor = (sym1Close &gt; sym1MA13 and sym1Close &gt; sym1MA30 ? color.green : color.red))
    screener.cell(1,1, str.tostring(sym2Close &gt; sym2MA13 and sym2Close &gt; sym2MA30), bgcolor = (sym2Close &gt; sym2MA13 and sym2Close &gt; sym2MA30 ? color.green : color.red))
    screener.cell(2,0, str.tostring(sym1lower), bgcolor = sym1lower == false ? color.green : color.red)
    screener.cell(2,1, str.tostring(sym2lower), bgcolor = sym2lower == false ? color.green : color.red)

答案2

得分: 0

你无法将你的脚本连接到Tradingview的筛选器。

你可以做的是,创建自己的筛选器。为了做到这一点,你需要使用security()函数并从不同的股票请求数据。你的脚本中最多只能有40次security调用,所以你的筛选器会受到限制。

在获取数值之后,你可以使用table.new()函数将它们显示在表格中。

英文:

You cannot connect your script to Tradingview's screener.

What you can do is, make your own screener. In order to do that, you need to use the security() function and request data from different tickers. You can only have maximum of 40 security calls in your script so your screener will be limited.

After you get the values, you can display them in a table using the table.new() function.

huangapple
  • 本文由 发表于 2023年5月18日 03:16:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/76275512.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定