I need help in constructing Fibonacci retracement using formula

 

Hello everyone, I'm trying to construct Fibonacci retracement using the formulas I learned on the internet, This is my code 

double FibonacciFunction(double High, double Low, double Level)
 { 
    datetime OpenTimeHigh = iTime(Symbol(),RSItf,iHighest(Symbol(),RSItf,MODE_CLOSE,Candles,1));
    datetime OpenTimeLow = iTime(Symbol(),RSItf,iLowest(Symbol(),RSItf,MODE_CLOSE,Candles,1));
    
//--- Trend Determination 
    int Trend = 0; //-1 DownTrend 1 Uptrend
     if (OpenTimeHigh < OpenTimeLow)
       Trend = -1;
     if (OpenTimeHigh > OpenTimeLow)
       Trend = 1;
   
    string stringtrend="";
    if (Trend==-1) stringtrend=" DownTrend ";
    if (Trend==1) stringtrend=" UpTrend ";

//---
   if (DebugMode) 
     Print("Trend ",stringtrend," HighTime ",OpenTimeHigh," LowTime ",OpenTimeLow);
//---

     double Formula = 0;
      if (Trend==-1)
       Formula = NormalizeDouble(Low + (High - Low) * (Level/100.0),Digits());   
      if (Trend==1)
       Formula = NormalizeDouble(High + (High - Low) * (Level/100.0),Digits()); 
       
     return Formula;
 }

It gives wrong retracement values when the trend is Uptrend where it gives all the values below the Lowest price including prices for the levels (23.6, 38.2,  61.8, 100.0) what might be wrong ?

Documentation on MQL5: Constants, Enumerations and Structures / Objects Constants / Object Types
Documentation on MQL5: Constants, Enumerations and Structures / Objects Constants / Object Types
  • www.mql5.com
Object Types - Objects Constants - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
   Formula = NormalizeDouble(High - (High - Low) * (Level/100.0),Digits()); 
 
lippmaje #:

Thanks