[英]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.我能够弄清楚high
和low
是当前的高价和低价,并且括号内的值可以访问以前的高/低值。 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.