Plot Fibonacci levels between two inputs


Category:
0
0

Hi Pete,

I am looking for a study where there are two inputs for high and low and it plots the fibs.

Thank you in advance for your help

Shaishav

Marked as spam
Posted by (Questions: 49, Answers: 62)
Asked on July 2, 2023 7:18 pm
171 views
0
Private answer

I moved your question out of the "Frequently Asked Questions" and into the "Chart Studies" topic. I also updated the title of your question to include the full name instead of the abbreviation. Both of these changes will make it easier for the rest of our viewers to locate this solution using the search function.

You did not state which direction you wanted the Fibonacci levels to be computed so I had to pick one. I included the three most common Fibonacci levels as well as the zero and 100% levels. Once you see how the code is structured you can add any additional lines you want. I also included user inputs to adjust the multiplier for each of the three Fibonacci levels.

Screenshot below shows how this looks on the chart. The screenshot includes a comment showing where I have added a hand drawn Fibonacci retracement to validate the levels are computed correctly.

input priceHigh = 100.0;
input priceLow = 50.0;
input fibOne = 23.8;
input fibTwo = 50.0;
input fibThree = 61.8;
def range = priceHigh - priceLow;
plot fibZero = priceLow;
plot fibLevelOne = priceLow + (range * fibOne * 0.01);
plot fibLevelTwo = priceLow + (range * fibTwo * 0.01);
plot fibLevelThree = priceLow + (range * fibThree * 0.01);
plot fib100 = priceHigh;

Attachments:
Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on July 2, 2023 7:37 pm
0
Thank you Pete. I can add other levels but I will not be able to add the direction . If you can modify the code to include the direction selector that would be great. Thank you
( at July 4, 2023 3:56 am)
0
All you have to do is invert the values you apply to each input. In the example provided in my solution, you would simply use a value of 50 for the "priceHigh" input and a value of 100 for the "priceLow" input. Obviously its possible to build a solution which has many additional features and functionality. But this is what I am able/willing to build free of charge.
( at July 4, 2023 9:01 am)
0
Hello Hahn, I did not get the plot in ToS that you show here for the Fibs. The Fibs are labelled on the y-axis with the Fib values, and they overide price and are plotting below price, not above like you show in your image. Maybe the code here was updated incorrectly? Thanks.
( at December 19, 2024 6:11 pm)
0
You have to manually input the high and low price using the user inputs which are provided. The default values are a high of 100 and a low of 50. You need to update that to reflect the specific high and low you want to use.
( at December 19, 2024 6:18 pm)
0
Ah, makes sense, sorry, did not read the code carefully enough, works now anchoring to the correct Fibs, but still no Fib price labels that I can see. No worries.
( at December 19, 2024 7:53 pm)
0
Correct. The labels are not part of the indicator. "The screenshot includes a comment showing where I have added a hand drawn Fibonacci retracement to validate the levels are computed correctly."
( at December 19, 2024 7:57 pm)
0
OK, thanks. I also noted that the price high and low have to be manually changed for each new chart symbol if this indicator is saved to the same study, which can be time consuming. Wonder why the user wanted it since the default ToS Fib can be snapped to actual price with simple left mouse button click and drags, complete with both label sets (when also hovering). Thanks for your help. RJ
( at December 19, 2024 8:17 pm)