Auto fib based on previous week/month


0
0

I’ve been searching around a bit for code to auto fib the previous week/month. So on Monday it would auto fib the week prior.

I have found some of your doe that shows how to pull the begining of the week (AggregationPeriod.WEEK;) but cant figure how to input the end of the month.

Any advie or suggestions?

Thanks

Marked as spam
Posted by (Questions: 5, Answers: 16)
Asked on July 15, 2019 10:08 am
20 views
0
Private answer

I provided user inputs here for three Fibonacci levels. You can also adjust the time frame (default is set to WEEK). You can change that to whatever time frame is available in the user input. Screenshot below shows what is looks like on a 1 hour chart set to weekly Fibonacci levels. This does not include labels for the lines and it does not automatically switch directions based on trend direction.

Here is your code:

input fibOne = 38.2;
input fibTwo = 50.0;
input fibThree = 61.8;
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.CYAN);
fibLevelOne.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
plot fibLevelTwo = periodLow + ((periodHigh - periodLow) * (fibTwo * 0.01));
fibLevelTwo.SetDefaultColor(Color.YELLOW);
fibLevelTwo.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
plot fibLevelThree = periodLow + ((periodHigh - periodLow) * (fibThree * 0.01));
fibLevelThree.SetDefaultColor(Color.MAGENTA);
fibLevelThree.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

Attachments:
Marked as spam
Posted by (Questions: 36, Answers: 1978)
Answered on July 15, 2019 3:54 pm
Thank you so much. You are awesome
( at July 15, 2019 4:17 pm)
is it easy to add the function of changing directions with the trend?
( at July 15, 2019 8:41 pm)
No, not easy at all. The code would need to track intraday data and determine which order the high and low occurred. It would also need to take into account the direction of price during the following week/month.
( at July 16, 2019 8:57 am)
Ok thanks, maybe I worded it wrong. I was thinking if the week closed green it would draw fib from top to bottom and vice versa if it closed red. Make sense? Not worried about reading trend etc. just looking at the weekly candle and determining if green or red.
( at July 16, 2019 2:29 pm)
That seems like a pretty simple way to determine the direction of the fibonacci. However it's still quite a chore to build the if statements that will switch everything around. I can certainly do this. It's not too difficult for me. The real issue is that I have a bunch of paying clients and I need to focus my time and efforts on serving them. If I spent all my time building out exceptional tools in the Q&A forum my paying clients would suffer. I need to be fair to everyone. (and more importantly, make sure the bills get paid). As it is now, you can see that the levels are still valid regardless which direction the fib is oriented. 38.2 and 61.8 are mirrors of each other, spanning the 50.0 line. If we flip this around the lines would end up in the exact same levels given these default values.
( at July 16, 2019 5:11 pm)
Oh no problem. I totally understand. Thanks for your help.
( at July 16, 2019 9:28 pm)