简体   繁体   English

如何在 Pine Script 中编辑 Williams 分形指标以显示 3 柱形分形?

[英]How can I edit the Williams Fractal indicator in Pine Script to display a 3-bar fractal?

The Williams Fractal paints a fractal by finding the low/high of 5 bars, lagging by 2 bars.威廉姆斯分形通过找到 5 根柱线的低/高线绘制分形,滞后 2 根柱线。

I would like to set up an indicator that finds the low/high of 3 bars.我想设置一个指标来查找 3 个柱的低/高。

I've examined TradingView's built-in Williams Fractal, which shows the following code:我检查了 TradingView 的内置 Williams Fractal,它显示了以下代码:

//@version=4
study("Williams Fractal", shorttitle="Fractal", format=format.price, precision=0, overlay=true)
// Define "n" as the number of periods and keep a minimum value of 2 for error handling.
n = input(title="Periods", defval=2, minval=2, type=input.integer)

My first question is about defval : why is the default value 2?我的第一个问题是关于defval :为什么默认值是 2? Does this refer to the lag?这是指滞后吗? Also, I thought setting an input allows the user to manipulate this number on TradingView for indicator preferences (like setting the lookback period for an MA), but I don't see this input on the built-in Williams Fractal.此外,我认为设置一个input允许用户在 TradingView 上操纵这个数字以获得指标偏好(例如设置 MA 的回顾期),但我在内置的 Williams Fractal 上没有看到这个输入。

Then we get to these parameters:然后我们得到这些参数:

upFractal = (                                                                                                          (high[n+2]  < high[n]) and (high[n+1]  < high[n]) and (high[n-1] < high[n]) and (high[n-2] < high[n]))
         or (                                                                               (high[n+3]  < high[n]) and (high[n+2]  < high[n]) and (high[n+1] == high[n]) and (high[n-1] < high[n]) and (high[n-2] < high[n]))
         or (                                                    (high[n+4]  < high[n]) and (high[n+3]  < high[n]) and (high[n+2] == high[n]) and (high[n+1] <= high[n]) and (high[n-1] < high[n]) and (high[n-2] < high[n]))
         or (                          (high[n+5] < high[n]) and (high[n+4]  < high[n]) and (high[n+3] == high[n]) and (high[n+2] == high[n]) and (high[n+1] <= high[n]) and (high[n-1] < high[n]) and (high[n-2] < high[n]))
         or ((high[n+6] < high[n]) and (high[n+5] < high[n]) and (high[n+4] == high[n]) and (high[n+3] <= high[n]) and (high[n+2] == high[n]) and (high[n+1] <= high[n]) and (high[n-1] < high[n]) and (high[n-2] < high[n]))

dnFractal = (                                                                                                  (low[n+2]  > low[n]) and (low[n+1]  > low[n]) and (low[n-1] > low[n]) and (low[n-2] > low[n]))
         or (                                                                         (low[n+3]  > low[n]) and (low[n+2]  > low[n]) and (low[n+1] == low[n]) and (low[n-1] > low[n]) and (low[n-2] > low[n]))
         or (                                                (low[n+4]  > low[n]) and (low[n+3]  > low[n]) and (low[n+2] == low[n]) and (low[n+1] >= low[n]) and (low[n-1] > low[n]) and (low[n-2] > low[n]))
         or (                        (low[n+5] > low[n]) and (low[n+4]  > low[n]) and (low[n+3] == low[n]) and (low[n+2] == low[n]) and (low[n+1] >= low[n]) and (low[n-1] > low[n]) and (low[n-2] > low[n]))
         or ((low[n+6] > low[n]) and (low[n+5] > low[n]) and (low[n+4] == low[n]) and (low[n+3] >= low[n]) and (low[n+2] == low[n]) and (low[n+1] >= low[n]) and (low[n-1] > low[n]) and (low[n-2] > low[n]))

I was able to figure out that high and low are the current high and low prices, and that the the bracketed value gives access to previous high/low values.我能够弄清楚highlow是当前的高价和低价,并且括号内的值可以访问以前的高/低值。 But does high[n+3] (to use one example) mean the high price 3 candles forward, and high[n-1] mean the high 1 candle back?但是high[n+3] (举一个例子)是否意味着 3 根蜡烛的高价, high[n-1]意味着 1 根蜡烛的高价回来?

I'm having a hard time following the logic of the code, regardless.无论如何,我很难遵循代码的逻辑。 I get upFractal is the variable that will be painted on the screen, but let me try to put the following line into words:我得到了upFractal是将在屏幕上绘制的变量,但让我尝试将以下行变成文字:

upFractal = (                                                                                                          (high[n+2]  < high[n]) and (high[n+1]  < high[n]) and (high[n-1] < high[n]) and (high[n-2] < high[n]))

This is what I think it means:这就是我认为的意思:

"Paint an upFractal if the high of the bar two bars ahead is less than the current high of the current bar and the high of the bar one bar ahead is less than the high of the current bar and the high of the bar one bar behind is less than the high of the current bar and the high of the bar two bars behind is less than the high of the current bar." “如果前面两根柱线的高点小于当前柱线的当前高点,并且前面一柱线的高点小于当前柱线的高点和后面一柱线柱线的高点,则绘制一个upFractal小于当前柱线的高点,后面两柱线的高点小于当前柱线的高点。”

Am I getting this right?我做对了吗? Can I simply follow this logic for a 3 bar pattern?对于 3 条形图案,我可以简单地遵循此逻辑吗?

Thank you.谢谢你。

When using the history referencing [] operator on time series in Pine, the behavior is the opposite of your understanding;在 Pine 中对时间序列使用历史引用[]运算符时,行为与您的理解相反; greater indices are further away in the past and zero (or the variable name without the operator) references the current bar.更大的索引在过去更远,零(或没有运算符的变量名称)引用当前柱。

Try to change defval and minval from 2 to 3 .尝试将 defval 和 minval 从 2 更改为 3 。 Maybe it is your answer.也许这就是你的答案。

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

相关问题 pine 脚本如何将分形指标从 v2 转换为 v4 - pine script how to convert Fractal indicator from v2 to v4 NEOWave Wave Chart - 我可以在特定价格柱上启动 Pine Script 指标吗? - NEoWave Wave Chart - Can I start a Pine Script indicator at a specific price bar? 我如何从分形点绘制线,这将延伸到价格穿过它的点 - How can I draw Lines from Fractal Points, that would extend to the point where price crosses through it Tradingview Pine 脚本 - 如何使自定义交易量指标表现得像内置交易量 - Tradingview Pine script - how can I make custom volume indicator behave like a built-in Vol 在Pine-script中,如何根据自定义指标中当前柱的条件将前一个柱的值分配给当前柱? - In Pine-script, how to assign the value of the previous bar to the current bar based on a condition of the current bar in a custom indicator? 如何查看内置指标的 Pine 脚本 - 例如江恩框? - How can I view Pine Script for built-in indicator - like Gann Box? 如何从 pine 脚本中引用其他指标? - How to reference an other indicator from pine script? 松树脚本中的指示器功能指示器 - Indicator on indicator feature in pine script 如何将 plot 指标置于另一个 [Pine 脚本] 之上 - How to plot an indicator on top of another [Pine Script] 如何显示带开/关键的指示器(Pine 脚本) - How to show an Indicator with key On/Off (Pine Script)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM