Need to get RECTANGLE high and low prices

 

Hello,

I need to get the high and low price of RECTANGLE in my EA with below code.


            double price1 = ObjectGetDouble(chart[idx].ID,obj_name,OBJPROP_PRICE,0);
            double price2 = ObjectGetDouble(chart[idx].ID,obj_name,OBJPROP_PRICE,1);

but I receive wrong prices as below.

price1 = -1202941964 , price2 = 2122057442

what is my mistake ? how to fix it ?

 
mrnoorhani:

Hello,

I need to get the high and low price of RECTANGLE in my EA with below code.


but I receive wrong prices as below.

price1 = -1202941964 , price2 = 2122057442

what is my mistake ? how to fix it ?

Please make sure that you are applying the right values for "Chart ID" and "Object name".

 
I think you should post your code completely. Maybe people can realize where the problem is.
 
mrnoorhani #:

I am sure

The amount of code you posted is partial. By seeing that no one can help you. If you want help, post full code.

 
   string obj_name;
   int TotalObj = ObjectsTotal(NULL, 0, OBJ_RECTANGLE);
   for(int i=TotalObj-1 ; i>=0 ; i--)
      {
      obj_name=ObjectName(NULL,i,0,OBJ_RECTANGLE);   
      double price1 = ObjectGetDouble(NULL,obj_name,OBJPROP_PRICE,0);
      double price2 = ObjectGetDouble(NULL,obj_name,OBJPROP_PRICE,1);      
      printf("%s : price1 = %d , price2 = %d",obj_name,price1,price2);
      }  

the above is complete of my code for this and below is the result.


SUPPLY PERIOD_M15  3 : price1 = -1669883285 , price2 = 2122057442

SUPPLY PERIOD_H1  1 : price1 = -1669883285 , price2 = 395824186

DEMAND PERIOD_M15 2 : price1 = 1808696628 , price2 = 68719477

DEMAND PERIOD_H1 0 : price1 = 258385232 , price2 = 1964002645


 
mrnoorhani #:

the above is complete of my code for this and below is the result.


SUPPLY PERIOD_M15  3 : price1 = -1669883285 , price2 = 2122057442

SUPPLY PERIOD_H1  1 : price1 = -1669883285 , price2 = 395824186

DEMAND PERIOD_M15 2 : price1 = 1808696628 , price2 = 68719477

DEMAND PERIOD_H1 0 : price1 = 258385232 , price2 = 1964002645


Your code is running on my system with correct output.

 
Yashar Seyyedin #:

Your code is running on my system with correct output.

surprised ???? so is there any parameter must be set in terminal ? what is wrong ?

 

You are using printf in the wrong manner.

e

double

A real value in the format [-] d.dddde[sign] ddd, where d - one decimal digit, dddd - one or more decimal digits, ddd - a three-digit number that determines the size of the exponent, sign - plus or minus

use %e

Documentation on MQL5: Common Functions / PrintFormat

Post edited by moderator to reference MQL5 documentation instead of MQL4.

Documentation on MQL5: Common Functions / PrintFormat
Documentation on MQL5: Common Functions / PrintFormat
  • www.mql5.com
PrintFormat - Common Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Many thanks Yashar. resolved !!!!
 
Your topic has been moved to the section: Expert Advisors and Automated Trading
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
 
@Yashar Seyyedin #: Documentation on MQL5: Common Functions / PrintFormat

Post edited by moderator to reference MQL5 documentation instead of MQL4.


When answering posts in the MT5/MQL5 sections, please reference the MQL5 and not the MQL4 documentation.

Reason: