Price breakout above or below recent ‘WilliamsFractal’ pivot price


Category:
0
0

Hi Pete, if it’s not too much to ask, can you create two custom scans that i will plan to use as mobile alert on my watchlists? 

#1 if the current price  breaks out at least above 0.05% from the recent UpFractal pivot high price

#2 if the current price breaks out at least below 0.05% from the recent DownFractal pivot low price

I’ve converted WilliamsFractal pattern into a chart study already below. 

I thought about customizing this code using “within 10-20 bars ago” but i figured it would not work if pivot points are too close with each other, and using less bars ago may not detect it. Plus i get a warning for having too complex of a script. Is there a simpler way to do this? I’ve attached a picture to help me with my questions. Thanks again in advance, Pete. 

 

declare lower;

input sequenceCount = 6;

 

def maxSideLength = sequenceCount + 10;

def upRightSide = fold i1 = 1 to maxSideLength + 1 with count1 while count1 != sequenceCount and count1 != -1 do

    if GetValue(high, -i1, -maxSideLength) > high or (GetValue(high, -i1, -maxSideLength) == high and count1 == 0) then -1

    else if GetValue(high, -i1, -maxSideLength) < high then count1 + 1 else count1;

def upLeftSide = fold i2 = 1 to maxSideLength + 1 with count2 while count2 != sequenceCount and count2 != -1 do

    if GetValue(high, i2, maxSideLength) > high or (GetValue(high, i2, maxSideLength) == high and count2 >= 1) then -1

    else if GetValue(high, i2, maxSideLength) < high then count2 + 1 else count2;

 

def downRightSide = fold i3 = 1 to maxSideLength + 1 with count3 while count3 != sequenceCount and count3 != -1 do

    if GetValue(low, -i3, -maxSideLength) < low or (GetValue(low, -i3, -maxSideLength) == low and count3 == 0) then -1

    else if GetValue(high, -i3, -maxSideLength) > low then count3 + 1 else count3;

def downLeftSide = fold i4 = 1 to maxSideLength + 1 with count4 while count4 != sequenceCount and count4 != -1 do

    if GetValue(low, i4, maxSideLength) < low or (GetValue(low, i4, maxSideLength) == low and count4 >= 1) then -1

    else if GetValue(low, i4, maxSideLength) > low then count4 + 1 else count4;

 

def UpFractal = upRightSide == sequenceCount and upLeftSide == sequenceCount;

def DownFractal = downRightSide == sequenceCount and downLeftSide == sequenceCount;

 

plot scan = UpFractal;

plot scan2 = downfractal;

Attachments:
Marked as spam
Posted by (Questions: 3, Answers: 0)
Asked on November 23, 2019 11:00 am
315 views
0
Private answer

The main obstacle in using your code to generate these signals is that your plots are several bars behind the active candle at the far right hand side of the chart. Notice in your screenshot the title bar of the lower study shows "N/A" for the values? Well that means there are no values you can use to generate scans for a signal. Because the values are simply not available on the last bar of the chart.

This is a tough obstacle to overcome because the way this code is written. The original code uses fold loops and requires that you know the values of the bars that follow the fractal highs and lows. The number of future bars required to compute them is directly related to the input named "sequence count".

If you reduce the sequence count to 1 you still have a problem because the last value available is still one bar behind the final bar on the chart. Not to mention that once you reduce that setting to 1 you have introduced a large degree of noise in the fractal patterns it displays.

There may be a way to overcome this obstacle but the solution far exceeds the amount of time I permit for free solutions in the Q&A forum.

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on November 23, 2019 2:33 pm