Custom scan for price touching fibonacci level


Category:
0
0

Pete,

Just watched your new video about creating scans for specific studies but I cant quite figure out how to set mine up. The code I have will plot some fibonacci levels based on the prior weeks range. What I’m trying to do is set up a scan against my watchlist that will add to a watchlist when the price touches one of the fibonacci levels.  Ideally the scan  would occur once price touches the level, whether it crosses or just touches it and bounces (like touches fibOne). Here is the code. Thanks!

input fibOne = 11.3;

input fibTwo = 50.0;

input fibThree = 88.7;

input timeFrame = AggregationPeriod.WEEK;

plot periodHigh = high(period = timeFrame)[1];

periodHigh.SetDefaultColor(Color.GREEN);

periodHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot periodLow = low(period = timeFrame)[1];

periodLow.SetDefaultColor(Color.RED);

periodLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot fibLevelOne = periodLow + ((periodHigh – periodLow) * (fibOne * 0.01));

fibLevelOne.SetDefaultColor(Color.YELLOW);

fibLevelOne.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot fibLevelTwo = periodLow + ((periodHigh – periodLow) * (fibTwo * 0.01));

fibLevelTwo.SetDefaultColor(Color.RED);

fibLevelTwo.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot fibLevelThree = periodLow + ((periodHigh – periodLow) * (fibThree * 0.01));

fibLevelThree.SetDefaultColor(Color.YELLOW);

fibLevelThree.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

 

 

Marked as spam
Posted by (Questions: 6, Answers: 18)
Asked on August 18, 2019 8:28 pm
329 views
0
A screenshot showing one or two of these touches would have helped to answer the remaining questions. So I have this pattern in mind. (...when the price touches one of the fibonacci levels...) Previous bar's high is below fibOne, current bar's high is above fibOne, while that current bar's close is below fibOne (...or just touches it and bounces...). Is that what you mean? Because we could have several bars in a row that touch and I'm sure you don't want the scan to pick up all of those. We need more details before we can solve this.
( at August 19, 2019 7:05 am)
0
Sorry just realized you responded. I added a picture as a solution as I couldnt add it here. Here is a screenshot of the price touching one of my fib levels (circled). I just want notification of the price touches that level. I don’t care if it touches and bounces or goes straight through it without bouncing at all. I don’t care if alerts every time because I just want to run it against my watchlist anyways. Does that make sense? Thanks.
( at August 20, 2019 9:50 pm)
0
Private answer

Edit: OOPS! I completely forgot that secondary aggregation periods are not currently supported in the Study Filters of a custom scan. Sorry for the bad news. There is no solution for this, using this code. The reason is the code uses a secondary aggregation period to read the weekly high/low.

To convert any study to a scan. Simple convert every plot statement to def, then remove the lines of code used to style and color those plots.

This code is the result. I have added a single plot statement to the bottom for the scan. The scan is for any candle that "touches" fibLevelOne:

input fibOne = 11.3;
input fibTwo = 50.0;
input fibThree = 88.7;
input timeFrame = AggregationPeriod.WEEK;
def periodHigh = high(period = timeFrame)[1];
def periodLow = low(period = timeFrame)[1];
def fibLevelOne = periodLow + ((periodHigh – periodLow) * (fibOne * 0.01));
def fibLevelTwo = periodLow + ((periodHigh – periodLow) * (fibTwo * 0.01));
def fibLevelThree = periodLow + ((periodHigh – periodLow) * (fibThree * 0.01));
plot scan = high < fibLevelOne and low > fibLevelOne;

Marked as spam
Posted by (Questions: 37, Answers: 4079)
Answered on August 21, 2019 10:27 am
0
Thanks Pete, I added the code but I’m not getting anything added to the watchlists despite me watching it touch/cross the fib line. My code makes fib plots for current week based on last week numbers, but is also creating next weeks fib lines based on the current weeks pricing. Is this causing a problem? Maybe because the I need the alert when price is touching the current weeks fib, and not the future week. Make sense?
( at August 21, 2019 11:30 am)
0
I updated my answer to explain the problem.
( at August 21, 2019 12:41 pm)
0
Bummer. Thanks so much for your help.
( at August 21, 2019 12:43 pm)
0
Hi Pete, i paste the abovementioned code from Pete in thinkscript Editor and i change the agg to "day", but i am not getting anything from the scan? Is there something i have not done correctly? Thanks
( at August 30, 2019 6:52 pm)
0
Did you read the edit to my original answer? Secondary aggregations are not supported for Study Filters in a custom scan.
( at August 30, 2019 8:21 pm)
0
Oh...i did not noticed that edit. Thanks.
( at August 30, 2019 11:18 pm)
0
http://tos.mx/Fz8Ss0 Hi Pete, found this scan that automatically plots fibonacci retracements using the highest price and lowest price from the current view and timeframe. Just wondering, can this script be modified into a scanner to scan out price that touches a certain level? thanks
( at September 1, 2019 1:10 am)
0
No. The data available to the scan is not the same span of time that you can load onto a chart. Any study that uses "HighestAll" and/or "LowestAll" are not candidates for building scans.
( at September 1, 2019 8:54 am)