Download MetaTrader 5

How can I get the actual price of each Fibo level ? - page 2

To add comments, please log in or register
John McGovern
12
John McGovern  

//A function that returns the price level:

//pass in the high pric to double high

//pass in the low pric to double low

//pass in one of these fibonacci levels 0,24.6,32.8,50.0,68.2,74.6,100 to double fibonacciLevel

//it returns the price level for your entered fibonacci level

//example:

//high:1.0100

//low:1.0000

//fibonacciLevel:61.8

//returns: 1.00618


double getPriceLevel(double high, double low, double fibonacciLevel)

{

if(fibonacciLevel<0 || fibonacciLevel>100) return(-1.0); //error

fibonacciLevel = fibonacciLevel/100;

double D=high-low;

double V=D*fibonacciLevel;

double priceLevel=V+low;

return(NormalizeDouble(priceLevel,5));

}

John McGovern
12
John McGovern  

//How can I get the actual price of each Fibo level ?

//my latest version of the getPriceLevel function:

//purpose: to help find the order entry position after a retracement over Elliot waves for uptrending or downtrending markets . 

//remember: for uptrending market, a support level is needed to know what fibonacci level to place the order at using a buy limit order type.

//                   candle reversal patten or moving average crossover may be used for market order.


enum trend  // enumeration of named constants

   {

    FORUPTREND,

    FORDOWNTREND,

   };

//double getPriceLevel(double high, double low, double fibonacciLevel,double ticks)

double getPriceLevel(double high, double low, double fibonacciLevel,trend measuringuptrendretracement=FORUPTREND)

{


double D;

double V;

double priceLevel;

double rfibonacciLevel;


if(fibonacciLevel<0 || fibonacciLevel>100) return(-1.0); //error


if(measuringuptrendretracement==FORUPTREND) //0% at the top, 100% at the bottom 

{

  fibonacciLevel = fibonacciLevel/100;

  D=high-low;

  V=D*fibonacciLevel;

  priceLevel=V+low;

  return(NormalizeDouble(priceLevel,5));

}

else //DOWN, downtrend, the numbers are reversed, 0% at the top, 100% at the bottom

{

  rfibonacciLevel = 100-fibonacciLevel;

  fibonacciLevel = rfibonacciLevel/100;

  D=high-low;

  V=D*fibonacciLevel;

  priceLevel=V+low;

  return(NormalizeDouble(priceLevel,5));

}


}

Sergey Golubev
Moderator
100960
Sergey Golubev  
Stanislav Korotky
23174
Stanislav Korotky  
What about ObjectGetValueByTime function?
MOHAMMED SAFAR AL-OTAIBI
31
MOHAMMED SAFAR AL-OTAIBI  
NOT RELATED TO FIBO
nicholishen
1389
nicholishen  
//+------------------------------------------------------------------+
//|                                                GetFiboLevels.mq4 |
//|                                      Copyright 2017, nicholishen |
//|                         https://www.forexfactory.com/nicholishen |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, nicholishen"
#property link      "https://www.forexfactory.com/nicholishen"
#property version   "1.00"
#property strict
#property indicator_chart_window
#include <ChartObjects\ChartObjectsFibo.mqh>

class MyFibo : public CChartObjectFibo
{
public:
   bool Attach(string name)
   {
      return Attach(ChartID(),name,0,2);
   }
   double LevelPrice(const int level_index)
   {
      double first = Price(0); 
      double last  = Price(1);
      double range = fabs(first-last);
      double fib   = range * LevelValue(level_index);
      if(first<last)
         return NormalizeDouble(last-fib,_Digits);
      return NormalizeDouble(last+fib,_Digits);
   }
};
//+------------------------------------------------------------------+
int OnInit()
{
   ChartSetInteger(0,CHART_EVENT_OBJECT_CREATE,true);
   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
{

   MyFibo fibo;
   if( (id==CHARTEVENT_OBJECT_CREATE || id == CHARTEVENT_OBJECT_DRAG)
        &&ObjectGetInteger(0,sparam,OBJPROP_TYPE)==OBJ_FIBO
     )
   {
      if(fibo.Attach(sparam))
      {
         string comm="";
         int total=fibo.LevelsCount();
         for(int i=0;i<total;i++)
            comm+= string(fibo.LevelValue(i))+" = "+DoubleToString(fibo.LevelPrice(i),_Digits)+"\n";
         Comment(comm);  
         fibo.Detach();
      }      
   }
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
{
   return(rates_total);
}
12
To add comments, please log in or register