0

I'm writing a code which calculates the average volume over a 200 day period multiplied by the average close price over the same period. In the chart, I'm using the dividend adjusted price (this is required for other indicators I'm also running), but I want the close price in the average volume script to be the actual close, so that it accurately represents the dollar amount of trading. The script defaults to whatever the chart is set to.

Anybody know how I might use the unadjusted close in the script, while keeping the chart on the adjusted close?

Here's the code: Code

Also, here's a screenshot of the code running on a dividend adjusted chart. (See the blue 'ADJ' in bottom right corner). As you can see, the value of the script on June 17, 1997 is 103,367. This however is using the adjusted close.Screenshot of code on adjusted chart

Here's the code running on an unadjusted chart. This is the value I want, as it reflects the actual close price at the time. This time the value on June 17, 1997 is 278,054. Screenshot of code on unadjusted chart

  • With the information you provided, it’s difficult to answer your question. Could you please share your code and if possible, some screen captures so that we can better understand the issue? – Gu5tavo71 Jul 03 '23 at 15:12
  • @Gu5tavo71, I've edited the question to include the things you mentioned. Thank you. – Elie Rozner Jul 03 '23 at 21:30

1 Answers1

0

use ticker.new() function with desired adjustment parameter:

https://www.tradingview.com/pine-script-reference/v5/#fun_ticker.new

adjustment (simple string) Adjustment type. Optional argument. Possible values: adjustment.none, adjustment.splits, adjustment.dividends. If adjustment is not given, then default adjustment value is used (can be different depending on particular instrument).
//@version=5
indicator("My script")

exp = ta.sma(volume, 256) * ta.sma(close, 256)

t = ticker.new(syminfo.prefix, syminfo.ticker, session = syminfo.session, adjustment = adjustment.none)
s = request.security(t, timeframe.period, exp)

plot(s)
plot(exp)

Starr Lucky
  • 1,578
  • 1
  • 7
  • 8