create a rectangle

 
Hi all,


I ask for your help with the following


I need to create a rectangle that sticking to one side of the window operations, so I thought of "OBJ_RECTANGLE_LABEL" but this does not leave me the option to put prices that define the height of the rectangle, since the documentation says

Note

Anchor point coordinates are set in pixels. It is possible to recctangle label's anchoring corner from ENUM_BASE_CORNER enumeration. Rectangle label's border type can be selected from ENUM_BORDER_TYPE enumeration.

The object is used to create and design the custom graphical interface.


so for give height or width, should be based on pixels, with XDISTANCE and XDISTANCE

but I need something that allows me to create a box attached to the right side, but to let me the option to select the price for its height (width, should also be in pixels)


how can I achieve??


this is the code that I have BAD


Thanks


void CreateRectangle(const long  chart_ID=0,              
   const string           name="RectLabel")
  {
   
   
   
   
   ObjectCreate(chart_ID,name,OBJ_RECTANGLE_LABEL, 0, 0, 0); 
   
   
     
 //--- establecemos las dimensiones de la etiqueta
    ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,100));
    ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,100));
  
    ObjectSetDouble(chart_ID,name,OBJPROP_PRICE1,1,iHigh(NULL,0,0));
  ObjectSetDouble(chart_ID,name,OBJPROP_PRICE2,2,iLow(NULL,0,0));
    

  
   
} 
 
MQ-L5:
Hi all,


I ask for your help with the following


I need to create a rectangle that sticking to one side of the window operations, so I thought of "OBJ_RECTANGLE_LABEL" but this does not leave me the option to put prices that define the height of the rectangle, since the documentation says

so for give height or width, should be based on pixels, with XDISTANCE and XDISTANCE

See https://www.mql5.com/en/docs/chart_operations/charttimepricetoxy

Documentation on MQL5: Chart Operations / ChartTimePriceToXY
Documentation on MQL5: Chart Operations / ChartTimePriceToXY
  • www.mql5.com
Chart Operations / ChartTimePriceToXY - Documentation on MQL5
 

angevoyageur


Friend thanks for replying,

I tried to use it, but do not understand how

can you help me?
In addition, being 2 Price values​​, I use the function twice or use "Price1 and Price2"

thanks

 
MQ-L5:

angevoyageur


Friend thanks for replying,

I tried to use it, but do not understand how

can you help me?
In addition, being 2 Price values​​, I use the function twice or use "Price1 and Price2"

thanks

Try to use the standard library for rectangles.

See example below (try to run this example on EURUSD chart);

#property copyright "Your name here"
#property link      "http://www.mql5.com"
#property version   "1.00"
//---
#include <ChartObjects\ChartObjectsShapes.mqh>
//---
CChartObjectRectangle Rect;
//---
input datetime start_date     = D'2014.02.28 15:00:00';
input datetime end_date       = D'2014.02.28 04:00:00';
input double   start_price    = 1.37800;
input double   end_price      = 1.37300;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   EventSetTimer(1);
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   EventKillTimer();
  }
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
//---
   Rect.Create(0,"Rectangle 1",0,start_date,start_price,end_date,end_price);
   Rect.Color(clrYellow);
   Rect.Fill(true);
   ChartRedraw();
  }
//+------------------------------------------------------------------+

 

 
Friend I tried testing the ChartXYToTimePrice and ChartTimePriceToXY functions, to test and implement it, but it does not work me

I tested this in EURGBP


void CreateRectangle(const long  chart_ID=0,
   const string  name="RectLabel" )
  {

   

ObjectCreate(chart_ID,name,OBJ_LABEL,0,0,0);
   int a=70;
   int b=70;
   int c=0;
   int d=100;
   int e=0;
   int f=0;
   datetime timea=iTime(NULL,0,6);
   datetime timeb=iTime(NULL,0,12);
   datetime timec=0;
   double pricea=0.8260;
   double priceb=0.8230;
   double pricec=0;
   
   
    
    
    if (ChartXYToTimePrice(chart_ID,a,b,c,timec,pricec))
    {
    
    pricec=0.8230;
    
    ObjectSetDouble(chart_ID,name,OBJPROP_PRICE1,1,pricec);
    Print( pricec);
    }
}
   


but does not work, can you help me


 
MQ-L5:
Friend I tried testing the ChartXYToTimePrice and ChartTimePriceToXY functions, to test and implement it, but it does not work me

I tested this in EURGBP



but does not work, can you help me


Copy and paste the code I wrote and run it on EURUSD. Tell me the results later.
 
Malacarne:
Copy and paste the code I wrote and run it on EURUSD. Tell me the results later.

Malacarne thanks,  this code only put a box or rectangle, but i need that this box is "glued" to right of chart window, including if i move the scroll

i need that have a price, and is "glued" in the right or left!!!

 
MQ-L5:
Malacarne thanks,  this code only put a box or rectangle, but i need that this box is "glued" to right of chart window, including if move the scroll

Ok, then try this:

void SetRectangle(string name, int sub_window, int xx, int yy, int width, int height, color bg_color, color border_clr, int border_width)
  {
   ObjectCreate(0,name,OBJ_RECTANGLE_LABEL,sub_window,0,0);
   ObjectSetInteger(0,name,OBJPROP_XDISTANCE,xx);
   ObjectSetInteger(0,name,OBJPROP_YDISTANCE,yy);
   ObjectSetInteger(0,name,OBJPROP_XSIZE,width);
   ObjectSetInteger(0,name,OBJPROP_YSIZE,height);
   ObjectSetInteger(0,name,OBJPROP_COLOR,border_clr);
   ObjectSetInteger(0,name,OBJPROP_BGCOLOR,bg_color);
   ObjectSetInteger(0,name,OBJPROP_BORDER_TYPE,BORDER_FLAT);
   ObjectSetInteger(0,name,OBJPROP_WIDTH,border_width);
   ObjectSetInteger(0,name,OBJPROP_CORNER,CORNER_RIGHT_UPPER);
   ObjectSetInteger(0,name,OBJPROP_STYLE,STYLE_SOLID);
   ObjectSetInteger(0,name,OBJPROP_BACK,false);
   ObjectSetInteger(0,name,OBJPROP_SELECTABLE,0);
   ObjectSetInteger(0,name,OBJPROP_SELECTED,0);
   ObjectSetInteger(0,name,OBJPROP_HIDDEN,false);
   ObjectSetInteger(0,name,OBJPROP_ZORDER,0);
  }

You can replace the highlighted part of the code with

CORNER_LEFT_LOWER,
CORNER_LEFT_UPPER, 
CORNER_RIGHT_LOWER or 
CORNER_RIGHT_UPPER
 
Malacarne:

Ok, then try this:

You can replace the highlighted part of the code with

'SetRectangle' - wrong parameters have lode_runner.mq4 histoprice 53 January


Dude, I had edited my previous message

Dude, at this time, your code throws an error, but I think your code did not answer my question, because my need is a rectangle with fixed price but stuck to the right or left, the Rectangle label may be attached to the right or left, but instead of price, has cordenadas XY and I need to price

 
MQ-L5:

'SetRectangle' - wrong parameters have lode_runner.mq4 histoprice 53 January


Dude, I had edited my previous message

Dude, at this time, your code throws an error, but I think your code did not answer my question, because my need is a rectangle with fixed price but stuck to the right or left, the Rectangle label may be attached to the right or left, but instead of price, has cordenadas XY and I need to price

Are you trying to run the code in MQL4 (lode_runner.mq4?? 

 
Malacarne:

Are you trying to run the code in MQL4 (lode_runner.mq4?? 

????, really i dont know why??

now say this: 'SetRectangle' - wrong parameters count    histoprice lode_runner.mq4    53    1,

Reason: