Pine Script - 价格/ATR 不正确

问题描述 投票:0回答:0

问题一 我正在尝试用股票收盘价除以 ATR 来表示自己的比率。 手算显示一个数字,但代码中的数学显示另一个数字。

显然我遗漏了一些东西,但我不知道是什么。 可能真的很简单,但我是新手,正在努力通过。

Price / ATR = Var1

Hand calc Ex: 
NVDA on Fri Mar 17, 2023 
Price = 257.25
ATR = 10.02
Var1 = 25.6

The script is showing Var1 = 12.86

(不是我的剧本,而是改变别人没有的东西。站在他们的肩膀上)

Improvement 1:
After the math is figured out, I'd like to add an If Then statements.

Output < 20 = color1
Output > 20 and Output < 30 = color 2
Output > 30 and Output < 40 = color 3
Output > 40 = color 4


// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ArmerSchlucker
// Credit to MikeC / TheScrutiniser and GlinckEastwoot for ADR% formula

//@version=4

study(title="ADR% / ATR / Market Cap", overlay=true)

show_price = close
price = close
show_adrp = input(true, title="Show ADR%")
show_atr = input(false, title="Show ATR")
show_market_cap = input(true, title="Show Market Cap")
adrp_len = input(20, title="ADR% Length", 
  tooltip="The number of daily bars used in the calculation of the ADR%")
atr_len = input(20, title="ATR Length",
  tooltip="The number of daily bars used in the calculation of the ATR")
bg_col = input(#00000000, title="Background Color")
adrp_col = input(color.white, title="Text Color (ADR%)")
atr_col = input(color.white, title="Text Color (ATR)")
market_cap_col = input(color.orange, title="Text Color (Market Cap)")
price_col = input(color.green, title="Text Color (Price)")
wmtr_col = input(color.orange, title="Text Color (WMTR)")
show_empty_row = input(false, title="Add an empty row above the displayed values", 
  tooltip="Serves the purpose of not having the pane icons overlap with the " + 
  "text in the table if multiple panes are shown and the chart pane is hovered")
wmtr = price / atr_len
show_wmtr = wmtr

arp = 100 * (sma(high / low, adrp_len) - 1)
adrp = security(syminfo.tickerid, 'D', arp)
atr = security(syminfo.tickerid, 'D', atr(atr_len))
market_cap = ((financial(syminfo.tickerid, "TOTAL_SHARES_OUTSTANDING", "FQ")) * close)

table t = table.new(position.bottom_right, 2, 6, bgcolor=bg_col)
if barstate.islast and timeframe.period != "W" and timeframe.period != "M"
    if show_empty_row
        table.cell(t, 0, 0, "")
        table.cell(t, 1, 0, "")
    if show_adrp
        table.cell(t, 0, 1, "ADR%", text_color=adrp_col)
        table.cell(t, 1, 1, tostring(round(adrp, 2)) + "%", text_color=adrp_col)
    if show_market_cap
        table.cell(t, 0, 2, "Market Cap", text_color=market_cap_col)
        table.cell(t, 1, 2, tostring(round(market_cap)), text_color=market_cap_col)
    if show_price
        table.cell(t, 0, 3, "Price", text_color=price_col)
        table.cell(t, 1, 3, tostring(price), text_color=price_col)
    if show_atr
        table.cell(t, 0, 4, "ATR", text_color=atr_col)
        table.cell(t, 1, 4, tostring(round(atr,2)), text_color=atr_col)
    if show_wmtr
        table.cell(t, 0, 5, "WMTR", text_color=wmtr_col)
        table.cell(t, 1, 5, tostring(round(wmtr,2)), text_color=wmtr_col)
pine-script price
© www.soinside.com 2019 - 2024. All rights reserved.