ObjectGetDouble

The function returns the value of the corresponding object property. The object property must be of the double type. There are 2 variants of the function.

1. Immediately returns the property value.

double  ObjectGetDouble(
   long                            chart_id,          // chart identifier
   string                          name,              // object name
   ENUM_OBJECT_PROPERTY_DOUBLE     prop_id,           // property identifier
   int                             prop_modifier=0    // property modifier, if required
   );

2. Returns true or false, depending on the success of the function. If successful, the property value is placed to a receiving variable passed by reference by the last parameter.

bool  ObjectGetDouble(
   long                            chart_id,          // chart identifier
   string                          name,              // object name
   ENUM_OBJECT_PROPERTY_DOUBLE     prop_id,           // property identifier
   int                             prop_modifier,     // property modifier
   double&                         double_var         // here we accept the property value
   );

Parameters

chart_id

[in]  Chart identifier. 0 means the current chart.

name

[in]  Name of the object.

prop_id

[in]  ID of the object property. The value can be one of the values of the ENUM_OBJECT_PROPERTY_DOUBLE enumeration.

prop_modifier

[in]  Modifier of the specified property. For the first variant, the default modifier value is equal to 0. Most properties do not require a modifier.  It denotes the number of the level in Fibonacci tools and in the graphical object Andrew's pitchfork. The numeration of levels starts from zero.

double_var

[out]  Variable of the double type that received the value of the requested property.

Return Value

Value of the double type for the first calling variant.

For the second variant the function returns true, if this property is maintained and the value has been placed into the double_var variable, otherwise returns false. To read more about the error call GetLastError().

Note

The function uses a synchronous call, which means that the function waits for the execution of all commands that have been enqueued for this chart prior to its call, that is why this function can be time consuming. This feature should be taken into account when working with a large number of objects on a chart.

Example:

#property copyright "Copyright 2025, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
 
#define   OBJ_NAME   "TestObjectGetDouble"   // Object name
#define   WND        0                       // Chart subwindow
#define   EXT        " (%$)"                 // Format string for displaying price values at levels
 
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//--- current chart ID, the chart symbol, and symbol Digits
   long   chart_idChartID();
   string symbol  = ChartSymbol(chart_id);
   int    digits  = (int)SymbolInfoInteger(symbolSYMBOL_DIGITS);
   
//--- construct the Fibonacci Levels graphical object at the maximum and minimum prices of the visible chart
   if(!CreateFibo(chart_id))
      return;
      
//--- number of object levels
   int total=(int)ObjectGetInteger(chart_idOBJ_NAMEOBJPROP_LEVELS);
   double value =0;
   double price0=0;
   double price1=0;
   
//--- anchor point prices
   price0=ObjectGetDouble(chart_idOBJ_NAMEOBJPROP_PRICE0);
   price1=ObjectGetDouble(chart_idOBJ_NAMEOBJPROP_PRICE1);
   
//--- in a loop by the number of object levels
   for(int i=0i<totali++)
     {
      //--- get the value set for the current level
      ResetLastError();
      if(!ObjectGetDouble(chart_idOBJ_NAMEOBJPROP_LEVELVALUEivalue))
        {
         Print("ObjectGetDouble() failed. Error "GetLastError());
         return;
        }
      
      //--- get the maximum and minimum prices of the object binding and the distance between them in the price value
      double max=fmax(price0price1);
      double min=fmin(price0price1);
      double range=max-min;
      
      //--- calculate the price value for the current level of the object
      double level_price=min+range*value;
      
      //--- set the color for the level so that it is visible on both dark and light backgrounds of the chart
      ObjectSetInteger(chart_idOBJ_NAMEOBJPROP_LEVELCOLORiclrRed);
      
      //--- set a format string for the level so that its price value is displayed along with the level value
      string level_text=ObjectGetString(chart_idOBJ_NAMEOBJPROP_LEVELTEXTi);
      if(StringFind(level_textEXT)<0)
        {
         level_text+=EXT;
         ObjectSetString(chart_idOBJ_NAMEOBJPROP_LEVELTEXTilevel_text);
        }
      
      //--- output the level number and its data - the level value and its price - in the journal
      PrintFormat("Fibo level [%d] value: %.3f,  price: %.*f"ivaluedigitslevel_price);
     }
   /*
   result:
   Fibo level [0value0.000,  price0.61989
   Fibo level [1value0.236,  price0.62533
   Fibo level [2value0.382,  price0.62869
   Fibo level [3value0.500,  price0.63140
   Fibo level [4value0.618,  price0.63412
   Fibo level [5value1.000,  price0.64292
   Fibo level [6value1.618,  price0.65715
   Fibo level [7value2.618,  price0.68018
   Fibo level [8value4.236,  price0.71745
   */
  }
//+------------------------------------------------------------------+
//| Create the Fibo levels graphical object on the specified chart |
//+------------------------------------------------------------------+
bool CreateFibo(const long chart_id)
  {
//--- draw Fibo levels from the highest to the lowest visible price values on the chart and get them
   double   price_high=0price_low=0;
   datetime time_high =0time_low =0;
   
   if(!GetChartExtremums(chart_idprice_highprice_lowtime_hightime_low))
      return(false);
 
//--- construct the Fibo Levels object on the found price/time coordinates
   if(!ObjectCreate(chart_idOBJ_NAMEOBJ_FIBOWNDtime_highprice_hightime_lowprice_low))
     {
      PrintFormat("%s: ObjectCreate() failed. Error %d",__FUNCTION__GetLastError());
      return(false);
     }
     
//--- all is well - update the chart and return 'true'
   ChartRedraw();
   return(true);
  }
//+------------------------------------------------------------------+
//| Return the maximum and minimum prices on the chart and their time|
//+------------------------------------------------------------------+
bool GetChartExtremums(const long chart_iddouble &price_highdouble &price_lowdatetime &time_highdatetime &time_low)
  {
//--- reset the variables
   price_high=price_low=0;
   time_high =time_low =0;
//--- chart symbol
   string symbol = ChartSymbol(chart_id);
 
//--- calculate the start of the range of copied timeseries based on the number of the first visible bar and the number of bars on the chart
   int first = (int)ChartGetInteger(chart_idCHART_FIRST_VISIBLE_BAR);
   int count = (int)ChartGetInteger(chart_idCHART_VISIBLE_BARS);
   int start = first+1-count;
   
//--- arrays where timeseries are to be copied
   double   array_high[];
   double   array_low[];
   datetime array_time[];
   int      index;
   
//--- copy three timeseries into arrays in the amount of 'count' and starting from 'start'
   ResetLastError();
   if(CopySeries(symbolPERIOD_CURRENTstartcountCOPY_RATES_TIME|COPY_RATES_HIGH|COPY_RATES_LOWarray_timearray_higharray_low)!=count)
     {
      PrintFormat("%s: CopySeries() failed. Error %d",__FUNCTION__GetLastError());
      return(false);
     }
   
//--- look for the maximum price index in the array_high array
   index=ArrayMaximum(array_high);
   if(index<0)
     {
      PrintFormat("%s: ArrayMaximum() failed. Error %d",__FUNCTION__GetLastError());
      return(false);
     }
//--- remember the highest price on the visible chart and the time value of the bar this price is located on
   price_high=array_high[index];
   time_high=array_time[index];
   
//--- look for the minimum price index in the array_low array
   index=ArrayMinimum(array_low);
   if(index<0)
     {
      PrintFormat("%s: ArrayMinimum() failed. Error %d",__FUNCTION__GetLastError());
      return(false);
     }
//--- remember the lowest price on the visible chart and the time value of the bar this price is located on
   price_low=array_low[index];
   time_low=array_time[index];
   
//--- all is fine
   return(true);
  }