简体   繁体   English

松字 function

[英]Pine-Script function

I need some help to create a function as below, I want to get the sum of red volume in a defined period and the sum of green volume in this same period, to do the difference between both.我需要一些帮助来创建如下所示的 function,我想获得定义时期内的红色成交量总和和同一时期内绿色成交量的总和,以求两者之间的差异。

sumvolup(lenght) => 
    sumvolup = float(0)
    volwhengreen = valuewhen(close-open>=0, volume, 1)
    sumvolup := sum(volwhengreen, lenght)
    sumvolup
    
sumvoldown(lenght) => 
    sumvoldown = float(0)
    volwhenred = valuewhen(open-close>=0, volume, 1)
    sumvoldown := sum(volwhenred, lenght)
    sumvoldown

My issue is shown in the image below: when I try to check if my function works fine with a plotted char on my indicator, using sumvolup(1)>sumvoldown(1) , II get plotted of the red bar volume.我的问题如下图所示:当我尝试使用sumvolup(1)>sumvoldown(1)检查我的 function 是否与指标上的绘制字符一起正常工作时,我会绘制红色条形体积。

截图问题

It's best to include a compilable code snippet when asking questions, including the plotting code, if you are having problems with it.如果您遇到问题,最好在提问时包含一个可编译的代码片段,包括绘图代码。

This may help you get on your way:这可能会帮助您上路:

//@version=4
study("")
i_length = input(20)

// This is the equivalent of your snippet, in shorter form.
volUp = close >= open ? volume : 0
volDn = close <= open ? volume : 0
sumvolup   = sum(volUp, i_length)
sumvoldown = sum(volDn, i_length)

// This plots the information.
volIsUp = sumvolup > sumvoldown
plot(sumvolup, "sumvolup", color.green)
plot(sumvoldown, "sumvoldown", color.red)
plotchar(volIsUp[1], "volIsUp[1]", "▲", location.top, size = size.tiny)

Note that in here, where the conditions are equivalent to yours, you are counting volume twice when close == open :请注意,在这里,条件与您的条件相同,您在close == open时计算了两次交易量:

volUp = close >= open ? volume : 0
volDn = close <= open ? volume : 0

在此处输入图像描述

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

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