【问题标题】:How to apply formula to several securities如何将公式应用于几种证券
【发布时间】:2021-01-23 11:24:05
【问题描述】:

我想将以下内容应用于几种证券。

最终产品将显示 3 行显示从 1700 到 2100 的百分比变化,使用从 1500 到 1700 的中点基线,使用该时期的最低和最高蜡烛。

例如我想监控这 3 只证券:

BINANCE:NEBLUSD
BINANCE:RSRUSD
BINANCE:TRXUSD
study("Baseline", overlay=false)

Coin01 = input(title = "Coin Selection", defval="BINANCE:NEBLUSD")
Coin02 = input(title = "Coin Selection", defval="BINANCE:RSRUSD")
Coin03 = input(title = "Coin Selection", defval="BINANCE:TRXUSD")

baselinetime = input('1500-1700:1234567', title="Baseline")
blt = time(timeframe.period, baselinetime)

analysisrange = input('1700-2100:1234567', title="analysisrange")
ar = time(timeframe.period, analysisrange)

var highe_01 = 0.0
var lowe_01  = 10e10
if blt
    if not blt[1]
        highe_01 := high
        lowe_01  := low
    else
        highe_01 := max(high, highe_01)
        lowe_01  := min(low, lowe_01)

midpoint = (highe_01+lowe_01)/2
inc = (close - midpoint)//change(close, length)
p = (inc/close)*100

//This enables me to view the chosen coin on the chart
plot(ar ? p : na, title="Percentage Change", color=color.blue, linewidth=2, style=plot.style_linebr)

//How do I apply the above formula to several coins? The below doesn't work, but can't get my head around how to apply it
plot(Coin01 : p : na, title="Coin01", color=color.red, linewidth=2, style=plot.stle_linebr)
plot(Coin02 : p : na, title="Coin01", color=color.green, linewidth=2, style=plot.stle_linebr)
plot(Coin03 : p : na, title="Coin01", color=color.blue, linewidth=2, style=plot.stle_linebr)

【问题讨论】:

  • 取出作为函数计算p值的块。执行security 计算每个证券的函数p
  • @AnyDozer 感谢您的回复,您有任何示例,您也可以指出我。我只配置了图表上的安全性。
  • here
  • 是您自己解决的还是这个问题仍然相关?
  • @AnyDozer 我仍在阅读它(似乎无法让它工作)。如果/当我成功时,我将发布更新。如果您有任何进一步的提示,请按我的方式提出。

标签: pine-script


【解决方案1】:
//@version=4

study("Baseline", overlay=false)

Coin01 = input(title = "Coin Selection", defval="BINANCE:NEBLUSD")
Coin02 = input(title = "Coin Selection", defval="BINANCE:RSRUSD")
Coin03 = input(title = "Coin Selection", defval="BINANCE:TRXUSD")

baselinetime = input("0930-1130", "Baseline", input.session)
blt = time(timeframe.period, baselinetime+":1234567")

analysisrange = input("1130-1730", "analysisrange", input.session)
ar = time(timeframe.period, analysisrange+":1234567")

p (_blt, _ar) =>
    highe_01 = 0.0
    lowe_01  = 10e10
    p=0.
    var midpoint=0.
    if _blt
        if not _blt[1]
            highe_01 := high
            lowe_01  := low
        else
            highe_01 := max(high, highe_01)
            lowe_01  := min(low, lowe_01)
            midpoint := (highe_01+lowe_01)/2
    if _ar 
        p:=((close - midpoint)/midpoint)*100
    else 
        p:=na
    p

//This enables me to view the chosen coin on the chart
//plot(ar ? p : na, title="Percentage Change", color=color.blue, linewidth=2, style=plot.style_linebr)

//How do I apply the above formula to several coins? The below doesn't work, but can't get my head around how to apply it
 
//p0 = p(blt, ar) // for the current ticker
p1 = security(Coin01, timeframe.period, p(blt, ar))
p2 = security(Coin02, timeframe.period, p(blt, ar))
p3 = security(Coin03, timeframe.period, p(blt, ar))

plot(p1, title="Coin01", color=color.red,   linewidth=2, style=plot.style_linebr)
plot(p2, title="Coin02", color=color.green, linewidth=2, style=plot.style_linebr)
plot(p3, title="Coin03", color=color.blue,  linewidth=2, style=plot.style_linebr)

【讨论】:

  • 5 颗星,5 颗星,非常感谢。我现在要重新申请和学习。
猜你喜欢
  • 1970-01-01
  • 2015-02-24
  • 1970-01-01
  • 1970-01-01
  • 2021-05-15
  • 1970-01-01
  • 1970-01-01
  • 2016-08-09
  • 1970-01-01
相关资源
最近更新 更多