过滤掉以下内容以仅在Pine脚本中包含在计算中

发布于 2025-01-19 08:09:33 字数 669 浏览 4 评论 0原文

因此,这就是我要做的事情: 我想编写一个脚本,该脚本专门使用upcandles [Close>开放]以计算从开放到高的%变化,接近高和开放到低点,然后以这些值的(移动)平均值来确定动态盈利,落后偏差和停止损失级别。我认为这应该解决问题。

// Variables
upCandle = (close > open) and barstate.isconfirmed

MP = if upCandle
    ((high - open) / open) * 100

TD = if upCandle
    ((high - close) / close) * 100

ML = if upCandle
    ((low - open) / open) * 100

它正确获取上频的值(以便该部分有效),但是随后它在从下candles获得的空值之间进行了插值。我只想从上随附的OHLC-DATA,如果没有可用数据,则不会插入N/A-或零值。 我认为我也许可以使用数组来解决此问题,这是“如果确认上的candle,请将适当的值粘贴到相应的FIFO阵列中,如果不是这样,请不要”。然后,我可以使用指定的回顾期计算该数组的平均值(FX仅包括最后9个上磁带),然后我可以将其绘制为阵列数据的移动平均值,而原始上循环数据的直方图。 换句话说,我认为我可以通过从阵列中滤出下调来完成我想做的事情。

但是我该怎么办?有人有什么想法吗? :)

So, here's what I'm aiming to do:
I want to write a script that uses OHLC-data exclusively from UP-candles [close > open] to calculate % change from Open to High, Close to High, and Open to Low, then take a (moving) average of those values to determine dynamic take profit-, trailing deviation- and stop loss-levels. I figured that this should do the trick.

// Variables
upCandle = (close > open) and barstate.isconfirmed

MP = if upCandle
    ((high - open) / open) * 100

TD = if upCandle
    ((high - close) / close) * 100

ML = if upCandle
    ((low - open) / open) * 100

It gets the values of the Up-candles correctly (so that part works), but then it interpolates between the empty values it gets from Down-candles. I want to ONLY take the OHLC-data from Up-candles, not have N/A- or ZERO-values inserted if no data is available.
I think I might be able to solve this using arrays, something along the lines of "if the Up-candle is confirmed, stick the appropriate value into a corresponding FIFO-array, if not then don't". Then, I could calculate the average from that array with a specified lookback period (f.x. include only the last 9 Up-candles) which I could then plot as a moving average for the array-data and a histogram for the raw Up-candle data.
In other words, I think I can accomplish what I want to do by filtering out Down-candles from an array.

But how do I do that? Anyone have any ideas? :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蓝礼 2025-01-26 08:09:33

您确实可以使用数组来实现目标。
仅当当前蜡烛是您要查找的蜡烛时才添加数组元素 - upCandle,使用输入,您可以控制数组中的元素数量并使用数组获取其平均值。 avg() 内置。
我还为 plot() 函数引入了 upCandleCount 计数器,仅在找到 9 个 upCandle 后才开始在图表上绘制。

//@version=5
indicator("My script")

// Variables
upCandle = (close > open) and barstate.isconfirmed

MP = if upCandle
    ((high - open) / open) * 100

TD = if upCandle
    ((high - close) / close) * 100

ML = if upCandle
    ((low - open) / open) * 100

// Average of the given values for the latest 9 upCandles
avgPeriod = input.int(9, 'Average Period')

var float[] upCandleMPs = array.new<float>(avgPeriod)
var float[] upCandleTDs = array.new<float>(avgPeriod)
var float[] upCandleMLs = array.new<float>(avgPeriod)

var int upCandleCount = 0

if upCandle
    array.unshift(upCandleMPs, MP)
    array.unshift(upCandleTDs, TD)
    array.unshift(upCandleMLs, ML)
    upCandleCount += 1

plot(upCandleCount >= avgPeriod ? array.avg(upCandleMPs) : na)
plot(upCandleCount >= avgPeriod ? array.avg(upCandleTDs) : na)
plot(upCandleCount >= avgPeriod ? array.avg(upCandleMLs) : na)

You can indeed use the arrays to accomplish the goal.
Add an array element only if the current candle is the one you are looking for - upCandle, using the input you can control the number of elements in the array and take its average using the array.avg() built-in.
I have also introduced the upCandleCount counter for the plot() functions to start plotting on the chart only after 9 upCandles are found.

//@version=5
indicator("My script")

// Variables
upCandle = (close > open) and barstate.isconfirmed

MP = if upCandle
    ((high - open) / open) * 100

TD = if upCandle
    ((high - close) / close) * 100

ML = if upCandle
    ((low - open) / open) * 100

// Average of the given values for the latest 9 upCandles
avgPeriod = input.int(9, 'Average Period')

var float[] upCandleMPs = array.new<float>(avgPeriod)
var float[] upCandleTDs = array.new<float>(avgPeriod)
var float[] upCandleMLs = array.new<float>(avgPeriod)

var int upCandleCount = 0

if upCandle
    array.unshift(upCandleMPs, MP)
    array.unshift(upCandleTDs, TD)
    array.unshift(upCandleMLs, ML)
    upCandleCount += 1

plot(upCandleCount >= avgPeriod ? array.avg(upCandleMPs) : na)
plot(upCandleCount >= avgPeriod ? array.avg(upCandleTDs) : na)
plot(upCandleCount >= avgPeriod ? array.avg(upCandleMLs) : na)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文