You're reading...
EA development, MQL4, MQL5, Uncategorized

Getting Fibonacci prices from the percentage level

Getting a price at a Fibonnaci percentage level is a straightforward mathematical calculation.

We just need to define 3 things:
1. Price at 100%
2. Price at 0%
3. Percentage to return Price at

This is a script illustrating all the calculation needed:

#property strict
#property show_inputs

input double inp_price_100  = 0.0;  //Price at 100%
input double inp_price_0    = 0.0;  //Price at 0%
input double inp_percentage = 61.8; //Percentage to return Price at

void OnStart(){

   double priceDifference = MathAbs(inp_price_0 - inp_price_100) * inp_percentage/100; //get the price difference between the required percentage level and 0%
   
   Print((inp_price_100 > inp_price_0) ? NormalizeDouble(inp_price_0 + priceDifference, Digits) : NormalizeDouble(inp_price_0 - priceDifference, Digits));

}

You just need these 2 lines to to obtain your required price for further action within an EA.

Discussion

One thought on “Getting Fibonacci prices from the percentage level

  1. Jacob Notte's avatar

    Amazing! Thank you so much πŸ™‚

    Posted by Jacob Notte | 2021-05-29, 9:01 AM

Leave a comment

Archives

Visitors

Flag Counter