简体   繁体   English

当 Pine Script 中的成交量条低于成交量 SMA 时如何为最低成交量蜡烛着色

[英]How to color lowest volume candle when volume bars below volume SMA in Pine Script

Im trying to code barcolor() function to mark lowest volume candle from those who below the volume(SMA,5), im tried Matrix, built_in functions eg.我正在尝试编写 barcolor() function 来标记那些低于音量(SMA,5)的人的最低音量蜡烛,我尝试了 Matrix,内置函数,例如。 ta.lowest(), arrays (actually almost near my target but something wrong due to some bars marked wrongly or ignored by code or in some instances marked correctly) and so many staff, only im able to do is color all candles that corresponds all volume bars below volume(SMA,5) thats actually simple to do, below part of code with arrays and also im attaching screenshot of the result. ta.lowest(), arrays(实际上几乎接近我的目标,但由于某些条标记错误或被代码忽略或在某些情况下标记正确而导致错误)和这么多员工,我唯一能做的就是为所有对应的蜡烛着色音量条低于音量 (SMA,5) 这实际上很简单,下面是部分代码 arrays 并且我附上了结果的屏幕截图。

//@version=5
cond = ma > vol
var float min_volume = na
length = ta.barssince(cond) 

Vol_array = array.new_float(500, 0)

for i = 0 to 499
    if cond
        min_volume := vol < vol[i] ? vol : na
        for j = 0 to length
            array.fill(Vol_array, min_volume[j])
min_array_vol = array.min(Vol_array)

//barcolor(cond ? color.rgb(216, 8, 119) : na)
barcolor(min_array_vol == vol ? color.blue : na)

在此处输入图像描述

So the result should be: lowest volume bar below the series of volumes under SMA should be accounted and marked所以结果应该是:低于 SMA 下一系列成交量的最低成交量条应该被计算和标记

Now that I understand what you are attempting to do, then this is the easiest way to determine the minimum volume in the segment where volume is less than the SMA(5) of the volume.既然我了解了您要尝试执行的操作,那么这是确定交易量小于交易量 SMA(5) 的线段中最小交易量的最简单方法。

the segment volume is now set and the bar_index (not the offset) is also now set.段交易量现在已设置,bar_index(不是偏移量)现在也已设置。 How you use that data is up to you.如何使用这些数据取决于您。

var float running_min_vol = 0.0
var int running_min_vol_idx = 0
var float min_vol_segment= 0.0
var int min_vol_segment_idx =0
sma_v = ta.sma(volume,5)

if ta.crossunder(volume,sma_v)
    min_vol := volume
    min_vol_idx: bar_index

min_vol := math.min(min_vol,volume)

if nz(ta.change(min_vol))<0
    min_vol_idx := bar_index

if ta.crossover(volume,sma_v)
    min_vol_segment:= min_vol
    min_vol_segment_idx := min_vol_idx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM