Calculate height of arrow buffer symbol in pixels

 

Hello 

Assume an arrow (draw type) buffer in an indicator.

The arrow is drawn by placing the center of the character at the specified time at the price in the buffer.

The PLOT_ARROW_SHIFT value that shifts arrows up or down in a plot is specified in pixels while the size of the arrow in the arrow buffer is specified as width (1,2,3) etc which 

does not seem to be a font size.

Is it possible to calculate the size of the characters given the width of the arrow code so that the shift applied can move the arrow to have its top on the buffer price or its bottom.

Thank you

Image for reference 

In the image : the enumerated arrows have their center at the line of the buffer , 
need to find their pixel size as the PLOT_ARROW_SHIFT is specified in pixels and not the width units used to 
determine the size of a character.

Thanks.

 
Lorentzos Roussos:

Hello 

Assume an arrow (draw type) buffer in an indicator.

The arrow is drawn by placing the center of the character at the specified time at the price in the buffer.

The PLOT_ARROW_SHIFT value that shifts arrows up or down in a plot is specified in pixels while the size of the arrow in the arrow buffer is specified as width (1,2,3) etc which 

does not seem to be a font size.

Is it possible to calculate the size of the characters given the width of the arrow code so that the shift applied can move the arrow to have its top on the buffer price or its bottom.

Thank you

Image for reference 

In the image : the enumerated arrows have their center at the line of the buffer , 
need to find their pixel size as the PLOT_ARROW_SHIFT is specified in pixels and not the width units used to 
determine the size of a character.

Thanks.

I'm thinking that ObjectGetInteger() used with OBJPROP_WIDTH holds the answer... or half of it anyway.

ObjectGetInteger - Object Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5

Object Properties - Objects Constants - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5

Documentation on MQL5: Object Functions / ObjectGetInteger
Documentation on MQL5: Object Functions / ObjectGetInteger
  • www.mql5.com
The function returns the value of the corresponding object property. The object property must be of the datetime, int, color, ...
 
@Ryan L Johnson #: I'm thinking that ObjectGetInteger() used with OBJPROP_WIDTH holds the answer... or half of it anyway.

This is not about Graphical Objects. It is about an indicator plot of the "arrow" type, not a Graphical Object. Please don't confuse the two.

 
Fernando Carreiro #:

This is not about Graphical Objects. It is about an indicator plot of the "arrow" type, not a Graphical Object. Please don't confuse the two.

Yeah exactly.

And we cant query the font size either from what i gather 

 

I have a feeling you're asking because of the fact that the arrow shift on one timeframe tends to be moot when toggling to another timeframe. You could try a dynamic offset for PLOT_ARROW_SHIFT instead of a static number. I did this in a few codes, for example have a look:

Code Base

Custom Bid Ask lines

Conor Mcnamara, 2024.08.11 01:31

A customized bid and ask line which is labelled and clear to help visualize the bid and ask prices

in this code the "Ask" text is always made to be above the line regardless of the timeframe because it scales the range from chart price max to chart price min

Regarding the question, I don't think drawing type sizes and neither font sizes can be translated to help with offsets 

Post edited by moderator. Instead of links to CodeBase and Articles, consider using the "pocket" feature instead.

 
Conor Mcnamara #:

I have a feeling you're asking because of the fact that the arrow shift on one timeframe tends to be moot when toggling to another timeframe. You could try a dynamic offset for PLOT_ARROW_SHIFT instead of a static number. I did this in a few codes, for example have a look:

in this code the "Ask" text is always made to be above the line regardless of the timeframe because it scales the range from chart price max to chart price min

Regarding the question, I don't think drawing type sizes and neither font sizes can be translated to help with offsets 

Post edited by moderator. Instead of links to CodeBase and Articles, consider using the "pocket" feature instead.

So the 8 size font is 0.036 of the y axis in size ?

In indicator arrow buffers we don't specify a font size but a "width"

I'll try the 3.6% assuming 8 is the default size.

(so the offset tested will be (((MaxPrice-MinPrice)*0.036)*width_of_arrow_buffer)/2.0 ) division by 2 because the arrows are centered
 

It works for width 1 but not when you scale up.

#property indicator_chart_window
#define factor 0.036
input int arrow_width=1;
double ANCHOR_OFFSET_PRICE=0.0;
void calculate_offset(int width){
ResetLastError();
int errors=0;
double max=(double)ChartGetDouble(0,CHART_PRICE_MAX,0);errors+=GetLastError();ResetLastError();
double min=(double)ChartGetDouble(0,CHART_FIXED_MIN,0);errors+=GetLastError();ResetLastError();
if(errors==0){
ANCHOR_OFFSET_PRICE=NormalizeDouble((((max-min)*factor)*((double)width))/2.0,_Digits);
}}
double test_buffer[];
int OnInit()
  {
  calculate_offset(arrow_width);
  SetIndexBuffer(0,test_buffer,INDICATOR_DATA);
   PlotIndexSetInteger(0,PLOT_DRAW_TYPE,DRAW_ARROW);
   PlotIndexSetInteger(0,PLOT_ARROW,140);
   PlotIndexSetInteger(0,PLOT_LINE_COLOR,clrYellow);
   PlotIndexSetInteger(0,PLOT_LINE_WIDTH,arrow_width);
   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);
  return(INIT_SUCCEEDED);
  }

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[])
  {
  if(ANCHOR_OFFSET_PRICE==0.0){calculate_offset(arrow_width);}
  for(int i=prev_calculated;i<rates_total;i++){
     test_buffer[i]=high[i]+ANCHOR_OFFSET_PRICE;
     }
  return(rates_total);
  }
 
Lorentzos Roussos #:

So the 8 size font is 0.036 of the y axis in size ?

In indicator arrow buffers we don't specify a font size but a "width"

I'll try the 3.6% assuming 8 is the default size.

(so the offset tested will be (((MaxPrice-MinPrice)*0.036)*width_of_arrow_buffer)/2.0 ) division by 2 because the arrows are centered

the 3.6% was actually just chosen that time through trial and error, because it basically looked good, so you anything under 5% for the factor seems to work for very small offsets I found

but instead of using the result for arrow width, I meant that you can use it for the arrow shift in this kind of way:

   PlotIndexSetInteger(0, PLOT_ARROW, 236); 
   PlotIndexSetInteger(0, PLOT_ARROW_SHIFT,  -(10 + dynamic_offset));  // shift with dynamic offset over the candle highs
     
   PlotIndexSetInteger(1, PLOT_ARROW, 238); 
   PlotIndexSetInteger(1, PLOT_ARROW_SHIFT, (10 + dynamic_offset));  //shift with dynamic offset under the candle lows  
my point is to disregard the arrow width property entirely and focus on trial and error for what simply looks right for the arrow shift