Skip to content

Commit

Permalink
HBS-0: input pine optimization to nyc copy
Browse files Browse the repository at this point in the history
  • Loading branch information
stimofeev-tv committed Feb 15, 2024
1 parent f210f4c commit 2239911
Show file tree
Hide file tree
Showing 22 changed files with 1,443 additions and 1,521 deletions.
33 changes: 21 additions & 12 deletions links/24h_volume.pine.link
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
// 24h volume
price = close
currency = "USD"
msIn24h = 24*60*60*1000
countOfFiveMinsInDay = 24*60/5
maxBufferSize = 2*countOfFiveMinsInDay
cumVolTF = "5"
cum24hVol(s) =>
src = s
if bar_index==0
src := src[maxBufferSize] * time[maxBufferSize] * 0
expr(offset, maxBufferSize) =>
if (syminfo.volumetype == "quote")
max_bars_back(volume, maxBufferSize)
volume[offset]
else
if syminfo.volumetype == "base"
max_bars_back(close, maxBufferSize)
max_bars_back(volume, maxBufferSize)
close[offset] * volume[offset]
else
na

cum24hVol() =>
max_bars_back(time, maxBufferSize)
var cumSum = 0.
var int firstBarTimeIndex = na
if na(firstBarTimeIndex) // 24 H have not elapsed yet
Expand All @@ -17,20 +26,20 @@ cum24hVol(s) =>
if (time - time[i]) >= msIn24h
firstBarTimeIndex := bar_index - i + 1
break
sum += src[i]
sum += expr(i, maxBufferSize)
cumSum := sum
else
cumSum += nz(src)
cumSum += nz(expr(0, maxBufferSize))
for i = firstBarTimeIndex to bar_index
if (time - time[bar_index - i]) < msIn24h
firstBarTimeIndex := i
break
cumSum -= nz(src[bar_index - i])
cumSum -= nz(expr(bar_index - i, maxBufferSize))
if cumSum <= 0
cumSum := 0
cumSum
expr = syminfo.volumetype == "quote" ? volume : ( syminfo.volumetype == "base" ? price*volume : na )
vol24h = request.security(syminfo.tickerid, cumVolTF, cum24hVol(expr), lookahead = barmerge.lookahead_off, currency = currency, ignore_invalid_symbol=true)

vol24h = request.security(syminfo.tickerid, cumVolTF, cum24hVol(), lookahead = barmerge.lookahead_off, currency = currency, ignore_invalid_symbol=true)
plot(vol24h, title = "24h_vol", style = plot.style_columns)

// volume in base and quote currencies
Expand All @@ -42,8 +51,8 @@ plot(volQuote, title = "volume_quote", style = plot.style_columns)
// 24h prev value (generic)
prev24hVal(source) =>
src = source
if bar_index == 0
src := src[maxBufferSize] * time[maxBufferSize] * 0
max_bars_back(src, maxBufferSize)
max_bars_back(time, maxBufferSize)
int BB24h = na
for i = 0 to countOfFiveMinsInDay
if (time - time[i]) >= msIn24h
Expand Down
Loading

0 comments on commit 2239911

Please sign in to comment.