X Y distance from a bar

 

hi

is there any way to find the X & Y distance on the chart from a bar ?

 

MetaEditor - Help - MQL4 Reference - Window functions is as close as I've found & used
WindowFirstVisibleBar
WindowBarsPerChart
WindowPriceMax & ... Min

These enable you accurately work out the location of a price at a time (I use "percentage of window size" rather than true X & Y)

Remember that location of a bar will change as window is scrolled or zoomed, and (without fancy programming) you cannot recalc/redraw bits between ticks.

 

Using this type of calculations in an EA is not good from my point of view, simply because of the issues brewmanz said. Why not use iHighes/iLowes instead of PriceMax/Min and a fixed number instead of WindowFirstVisibleBar.

And what can you extract from following?: price changed +24 pixel in the las hour?

Don't get me wrong, maybe i am missing an important point.

 

the reason for that is: i'm trying to find out if the chart is shifted or not

i tried WindowFirstVisibleBar() in int init() & gives the same results

//+------------------------------------------------------------------+
//|                                                       !!TEST.mq4 |
//|                      Copyright © 2010, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2010, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

#include <WinUser32.mqh>

#import "user32.dll"
   int GetAncestor(int hWnd, int gaFlags);
   
#import

#property indicator_chart_window

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//-----
      int hndl = GetAncestor(WindowHandle(Symbol(),Period()),2); //find Termeinal handle

      PostMessageA(hndl, WM_COMMAND, 33023, 0); //press the shift chart button
      int First = WindowFirstVisibleBar();
      Alert ("First ", First);
      PostMessageA(hndl, WM_COMMAND, 33023, 0); //press the shift chart button
      int Second = WindowFirstVisibleBar();
      Alert ("Second ", Second);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+

 

If you mean with shifted, that strange zoom when you click and hold on the price left, then i maybe something like that will work:

int last=WindowBarsPerChart();
double hi=High[iHighest(Symbol(),Period(),last,MODE_HIGH,0)];
double lo=Low[iHighest(Symbol(),Period(),last,MODE_LOW,0)];
double tolerance=20*Point*Digits.Mod;
if(WindowPriceMax()>(hi+tolerance)||WindowPriceMin()<(low-tolerance)){
  //Zoom is used
}

no warranty, only written here. just an idea...

//z

Reason: