-1

how do I calculate the fibo levels from yesterday/previous day.

This is how far I am currently:

 int shift   = iBarShift( NULL, PERIOD_D1, Time[0] ) + 1;   // yesterday
 HiPrice     = iHigh(     NULL, PERIOD_D1, shift);
 LoPrice     = iLow (     NULL, PERIOD_D1, shift);
 StartTime   = iTime(     NULL, PERIOD_D1, shift);

 if ( TimeDayOfWeek( StartTime ) == 0    /* Sunday */ )
 {                                       // Add fridays high and low
      HiPrice = MathMax( HiPrice, iHigh( NULL, PERIOD_D1, shift + 1 ) );
      LoPrice = MathMin( LoPrice, iLow(  NULL, PERIOD_D1, shift + 1 ) );
 }
 Range = HiPrice - LoPrice;

I think now I should have all values necessary for calculating it.

I am not sure on how I now can calculate the different levels now:
23.6 38.2 50.0 61.8 76.4 and -23.6 -38.2 -50.0 -61.8 -76.4 -100

user3666197
  • 1
  • 6
  • 50
  • 92
Salexes
  • 187
  • 1
  • 2
  • 20

2 Answers2

2

All necessary Fibo-levels can be added manually as an array - this is the easiest way as far as I know. Then simply loop over such array and
+values are ( high + array[i] / 100 * range ),
values below the fibo - ( low - array[i] / 100 * range ),
where
array[] = { 23.6, 38.2, .. } ( only positive values are enough )

user3666197
  • 1
  • 6
  • 50
  • 92
Daniel Kniaz
  • 4,603
  • 2
  • 14
  • 20
2

Fibonacci Levels need a direction, so in your above code you will either want to swap to using open and close values of the previous bar or impose a direction onto the high and low. This will let you know which way to draw the extensions and retraces.

Here is a function I have written previously for this question. This function assumes price1 is at an earlier timepoint than price2 then calculates the direction and levels, returning a FibLevel structure.

struct FibLevel {
    double retrace38;
    double retrace50;
    double retrace61;
    double extension61;
    double extension100;
    double extension138;
    double extension161;
};

void FibLevel(double price1, double price2,FibLevel &fiblevel)
{
    double range = MathAbs(price1-price2);
    fiblevel.retrace38   =(price1<price2)?price2-range*0.382:price1+range*0.382;
    fiblevel.retrace50   =(price1<price2)?price2-range*0.500:price1+range*0.500;
    fiblevel.retrace61   =(price1<price2)?price2-range*0.618:price1+range*0.618;
    fiblevel.extension61 =(price1<price2)?price2+range*0.618:price1-range*0.618;
    fiblevel.extension100=(price1<price2)?price2+range      :price1-range;
    fiblevel.extension138=(price1<price2)?price2+range*1.382:price1-range*1.382;
    fiblevel.extension161=(price1<price2)?price2+range*1.618:price1-range*1.618;   
}
rgunning
  • 568
  • 2
  • 16