Tradingview Pine 脚本 - 如何使自定义交易量指标表现得像内置交易量 [英] Tradingview Pine script - how can I make custom volume indicator behave like a built-in Vol

查看:294
本文介绍了Tradingview Pine 脚本 - 如何使自定义交易量指标表现得像内置交易量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了一个自定义交易量指标,但是当应用于图表时,它不像内置指标那样自动缩放,不会自动粘在图表面板的底部,也不能没有自己的明确显示侧面有额外的刻度.

I made a custom volume indicator, but when applied to the chart, it doesn't autoscale like the built-in one, doesn't auto stick to the bottom of the chart panel, nor can it go without its own explicit extra scale on the side.

有没有办法让它做所有这些事情?

Is there a way for it to do all these things?

我在原始指标代码中也没有发现任何帮助.例如.当我尝试应用 format.volume 时,它​​根本拒绝编译.

I found no help in the original indicator code neither. E.g. when I tried to apply format.volume, it just refused to compile at all.

下面是我的代码,原始代码在下面:

Below is my code, the original is further below that:

//This inddicator will show volume inversely. So if you are looking at an Altcoin, it will show volume in BTC, if you are looking at for example BTC/USD it will show volume in USD and so on. Works with all altcoins and fiat pairs.
//I find this most useful when shopping for alts to quickly get an idea of their liquidity.

//title the indicator and dont use decimals. (Otherwise when viewing fiat volume you get unreadably large numbers) you can change this in the settings dialog tho if you want.
study("Vol in Base asset 20MA", precision=0)

//Make the moving average user configurable
showMA = input(true)

//Get volume for current bar and multiply with vwap
vInverse = volume * vwap

//Plot fiat volume.
plot(vInverse, color = orange, title="VolumeBTC", style=columns, transp=65)

//Plot 20 candle moving average (changable in settings)
plot(showMA ? sma(vInverse,20) : na, color = white, title="Volume MA", style=area, transp=65)

原代码:

//@version=4
study(title="Volume", shorttitle="Vol", format=format.volume)
showMA = input(true)
barColorsOnPrevClose = input(title="Color bars based on previous close", type=input.bool, defval=false)

palette = barColorsOnPrevClose ? close[1] > close ? color.red : color.green : open > close ? color.red : color.green

plot(volume, color = palette, style=plot.style_columns, title="Volume", transp=65)
plot(showMA ? sma(volume,20) : na, style=plot.style_area, color=color.blue, title="Volume MA", transp=65)

推荐答案

对您的问题的简短回答是否定的,目前不可能做您想做的所有事情.要完成内置音量独立游戏的功能,我们需要两件我们没有的东西:

The short answer to your question is no, it's currently not possible to do everything you want. To do what the built-in volume indie does we would need 2 things we don't have:

  1. 在图表上显示哪些条形图的松树可见性(因此我们可以动态缩放交易量列的高度).
  2. 一种将独立指数锚定在图表底部的方法,同时仍允许指标的刻度自动缩放.

这段代码也使用了 Michel 的 scale.none 想法,但它在顶部添加了一个不可见的绘图,可以让您确定垂直空间中列的最大高度,而无需缩放列的值自己,因此您仍然可以获得正确的读数.使用*设置/输入",您可以:

This code also uses Michel's scale.none idea, but it adds an invisible plot on top that allows you to determine the maximum height of columns in the vertical space, without scaling the values of the columns themselves, so you still obtain correct readings. Using the *Settings/Inputs" you can:

  • 指定您希望最高列占据的垂直空间的最大百分比.
  • 指定如何确定用于缩放列的最大过去值,即,使用:
    • 历史新高,或
    • 最后 n 条柱中的最高列(n=400 是默认值).第二种方法可以更好地适应最近的图表上下文.
    • Specify the maximum percentage of the vertical space you want the highest columns to occupy.
    • Specify how the maximum past value used to scale columns is determined, i.e., using:
      • The all-time high, or
      • The highest column in the last n bars (it's the default with n=400). This second method adjusts better to the recent chart context.

      //This indicator will show volume inversely. So if you are looking at an Altcoin, it will show volume in BTC, if you are looking at for example BTC/USD it will show volume in USD and so on. Works with all altcoins and fiat pairs.
      //I find this most useful when shopping for alts to quickly get an idea of their liquidity.
      
      //title the indicator and dont use decimals. (Otherwise when viewing fiat volume you get unreadably large numbers) you can change this in the settings dialog tho if you want.
      //@version=4
      study("Vol in Base asset 20MA", "", true, format.volume, 0, scale.none)
      
      //Make the moving average user configurable
      HIM1 = "1. Historical High"
      HIM2 = "2. Highest in last..."
      showMA = input(true)
      scaleFactor = 100 / input(30, "% of vertical space used", step = 10, maxval = 100)
      hiMethod = input(HIM2, "High point method", options = [HIM1, HIM2])
      hiMethod2Len = input(400, "  2. Length", minval = 2, step = 100)
      
      //Get volume for current bar and multiply with vwap
      vInverse = volume * vwap
      
      //Plot fiat volume.
      plot(vInverse, color = color.orange, title="VolumeBTC", style=plot.style_columns, transp=0) //Originally: transp=65
      
      //Plot 20 candle moving average (changable in settings)
      plot(showMA ? sma(vInverse,20) : na, color = color.white, title="Volume MA", style=plot.style_area, transp=65)
      
      //Plot high line to scale down the columns.
      var histHi = 0.
      histHi := max(histHi, nz(vInverse, histHi))
      limit = hiMethod == HIM1 ? histHi : highest(vInverse, hiMethod2Len)
      plot(limit * scaleFactor, "Historical High", #00000000)
      

      这将给出如下内容:

      有两种方法可以将列的底部带到图表底部,但没有一种方法是理想的:

      There are 2 ways to bring the base of the columns to the bottom of the chart, but none is ideal:

      1. 使用图表的设置/外观/底部边距将图表的底部边距设置为 0%,但随后图表栏会继续与列重叠.
      2. 通过向上/向下拖动其比例(红色箭头)来稍微压缩独立游戏的比例.然后抓住图表上的列(绿色箭头)并将它们拉下来,但这会冻结独立游戏的比例,因此当您更改符号和音量增加/减少时,它不会调整大小.
      1. Set bottom margin of chart to 0% using the chart's Settings/Appearance/Bottom margin, but then chart bars continue to overlap columns.
      2. Compress the indie's scale a bit by dragging its scale up/down (red arrow). Then grab the columns on the chart (green arrow) and bring them down, but this freezes the indie's scale then, so it won't resize when you change symbols and the volume increases/decreases.

      将指示器与垂直空间底部对齐的能力已被 TV 认定为一项潜在的改进,但目前还没有预计到达时间.

      The ability to align indicators with the bottom of the vertical space has been identified by TV as a potential improvement—but with no ETA yet.

      这篇关于Tradingview Pine 脚本 - 如何使自定义交易量指标表现得像内置交易量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆