kcwolfy
Pine Script Scholar
Pine Script Scholar
Posts: 2
Joined: July 29th, 2021

Bar volume in $ + help

Hey guys, I wrote a simple script to show the bar average price (high+low /2) and more importantly for me the volume of the bar in USD. For me, it's easier to understand. Here's the thing - I just get an astronomical number. :whoops: . Is there a simple way to break it down and show it in a string, to 3 decimal places? I use this specifically on altcoin charts to see the actual BTC value in $.

e.g.
$1000
$1.000K
$123.000K
$1.000M
.... etc.

I'm especially interested in showing that value for the bar the cursor is focused on. Any help is much appreciated. And thanks.

Image

Code: Select all

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © PorkkChop

//@version=4
study("Average Bar Price & Volume $")

BTCpriceInUSD = security("BINANCE:BTCUSD", "", close)
averagePrice = ((abs((high + low)/2))*BTCpriceInUSD)
plot(averagePrice, title = 'Av Price $')

totalVolume = volume * averagePrice
//totalVolumeString = tostring(totalVolume, '#,#,#.###') 

plot (totalVolume, linewidth=2, color=color.red, title = 'Volume $')

kcwolfy
Pine Script Scholar
Pine Script Scholar
Posts: 2
Joined: July 29th, 2021

Re: Bar volume in $ + help

Is anyone out there?

processingclouds
Pine Script Master
Pine Script Master
Posts: 115
Joined: January 30th, 2022

Re: Bar volume in $ + help

Hey,

I am new to this forum, and as i see you have had a query and no response, so though of replying to it.

Your question is not really clear.

I infer from the example given that you want to display the numbers formatted as suffix with K as thousands, M as million, B as billion

You can add parameter to your study function as format=format.volume
so your line 4 of code becomes

Code: Select all

study("Average Bar Price & Volume $", format=format.volume )
This will show the numbers formatted with suffixes.


Note: If you have a question on strategy itself, I can help you with that, if you can provide more context on what you are trying to achieve.

Return to “Share Your Scripts”