过滤掉以下内容以仅在Pine脚本中包含在计算中
因此,这就是我要做的事情: 我想编写一个脚本,该脚本专门使用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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您确实可以使用数组来实现目标。
仅当当前蜡烛是您要查找的蜡烛时才添加数组元素 - upCandle,使用输入,您可以控制数组中的元素数量并使用
数组获取其平均值。 avg() 内置。
我还为
plot()
函数引入了 upCandleCount 计数器,仅在找到 9 个 upCandle 后才开始在图表上绘制。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.