Is it possible to anchor CCanvas Bitmaps by (time, price) coordinates rather than by pixel? This is to solve color change to overlapping objects.

To add comments, please log in or register
MacDougall
17
MacDougall  

Hi, is it not possible to anchor each corner of a rectangle bitmap to a (time, price) coordinate rather than a pixel coordinate?

PROBLEM: This is for a script which creates simple volume-at-price profiles, made up of many rectangles. When there are two overapping profiles, the overlapping parts of the rectangles are displayed a different color than either of the profiles.

AIM: In an attempt to avoid this i turned to bitmaps with CCanvas. While it is possible to anchor these bitmaps to one (time, price) coordinate, i can't find how to fix those edges or corners to particular times and prices so that they retain their relevance while changing timeframe or zooming. 

If this is not possible, then i see two unnapealing possibilities:

A, mask the overlapping sections of normal rectangle objects. The set of interacting modular scripts i have developed so far are based around quickly and easily adding, selecting, changing, toggling... many objects and groups of objects, scrolling through levels of relevance, in order for the user to relatively easily manage the complexity of many objects without being overwhelmed by them. The idea of adding more objects (the color masks) just seems like a really inelegant and wasteful path i don't want to go down... though i guess that is what computers are for.....

or;

B, recalculate and redraw a bitmap every time a timeframe or zoom is changed. That would then also require this to be an indicator rather than the simpler script. 

If you know anything about this then i'd be really grateful for any ideas as i've researched and experimented about as far as i can feasibly go on my own at the moment. Thanks for any responses!

Lorentzos Roussos
28197
Lorentzos Roussos  
Market profile script ? :)

The bitmaps get anchored (on the x axis) in points in the middle of the bar , is this the issue you encounter ? Gaps ?
paul selvan
504
paul selvan  
Conversions functions   ChartXYToTimePrice()  or  ChartTimePriceToXY()  maybe helpfull for your purpose
MacDougall
17
MacDougall  
Lorentzos Roussos:
Market profile script ? :)

The bitmaps get anchored (on the x axis) in points in the middle of the bar , is this the issue you encounter ? Gaps ?

Thanks Lorentzos. Well, the issue is that the bitmaps are only anchored at one (time, price) coordinate, ie they move when changing timeframe or zooming, but they do not resize proportionally, whereas normal MQL objects do. 

Thanks too for the Market Profile link. What specifically about it are you referring to?

I think of Market Profiling methods as mostly (but not only) based on Time-At-Price (TAP) profiles rather than Volume-At-Price (VAP) profiles. Graphically the profiles can look the same, right? My Volume-At-Price scripts work really robustly, simply and modularly with MQL's normal objects, moving, combining, changing data or position, always trying to dynamically adapt the information to the relevance of current analyses without adding to info overload. I am very happy with the scripts, except for the overlapping which causes the colour problem.

This overlapping colour is the initial problem which has led to either option A (masking) or B (bitmaps), but those potential solutions each have their own challenges. The lack of (time,price) coordinates for each corner is one of the two main challenges with B. Have you ever come across a way of specifying more than one (time,price) coordinate for bitmaps in MQL?

Lorentzos Roussos
28197
Lorentzos Roussos  
MacDougall:

Thanks Lorentzos. Well, the issue is that the bitmaps are only anchored at one (time, price) coordinate, ie they move when changing timeframe or zooming, but they do not resize proportionally. 

Thanks too for the Market Profile link. What specifically about it are you referring to?

I think of Market Profiling methods as mostly (but not only) based on Time-At-Price (TAP) profiles rather than Volume-At-Price (VAP) profiles. Graphically the profiles can look the same, right? My Volume-At-Price scripts work really robustly, simply and modularly with MQL's normal objects, moving, combining, changing data or position, always trying to dynamically adapt the information to the relevance of current analyses without adding to info overload. I am very happy with the scripts, except for the overlapping which causes the colour problem.

This overlapping colour is the initial problem which has led to either option A (masking) or B (bitmaps), but those potential solutions each have their own challenges. The lack of (time,price) coordinates for each corner is one of the two main challenges with B. Have you ever come across a way of specifying more than one (time,price) coordinate for bitmaps in MQL?

In that case , as Paul said , you have to go the Indicator route and capture chart changing events in order to adjust what is being displayed.
The best approach will be to have one canvas as an "underchart" and perform all resizing operations there when user scrolls or adjusts the chart

MacDougall
17
MacDougall  
paul selvan:
Conversions functions   ChartXYToTimePrice()  or  ChartTimePriceToXY()  maybe helpfull for your purpose

Thanks Paul. Yes, that is what i am thinking about in option B with "recalculate and redraw". Is it possible to pick up an OnZoom() or OnChangeTimeFrame() event in MQL? Cos that would be needed to then recalc and redraw automatically, right?

Option A (masking) is starting to look preferable but it's going to create a whole mess of extra rectangle objects which will make some of my manual processes with objects more complex. And that's the last thing i want. I don't want to get stuck into some cascade of coding complexity to manage a whole load of informational complexity created unnecessarily.

With both options, the z-axis / z-order constraint in MQL will also need solving as it will need to know which object should be on top to know which colour is the intended one. And that also looks relatively challenging given that objects' createTime property is read-only. Maybe i will just add more metadata into the object name or description field.

Simpler solutions anyone? I've already re-examined whether these outputs are really requirements or not. Something other than masking, like an actual z-axis (not just background / foreground)?

paul selvan
504
paul selvan  

Did check methods  of class CCanvas - in   include file  "Canvas.mqh"  


May be like this example.

Let's say  canvas name is C.

void OnChartEvent(const int id,const long &lparam,const double &dparam,const string &sparam){
   
   int width=(int)ChartGetInteger(0,CHART_WIDTH_IN_PIXELS,0)/2;   
   int height=(int)ChartGetInteger(0,CHART_HEIGHT_IN_PIXELS,0)-25;
   
   C.Resize(width, height);
   C.Update();
}
MacDougall
17
MacDougall  
paul selvan:

Did check methods  of class CCanvas - in   include file  "Canvas.mqh"  


May be like this example.

Let's say  canvas name is C.

Thanks again Paul. That is very helpful for the Bitmap Indicator Solution (B). I've decided though that i really don't want resources continuously taken up by an extra indicator on many charts, which would seem to be needed for the redrawing of bitmaps with every zoom or timeframe change. 

So i'm left with the Masking Script Solution (A):

- Rather than a function which will be called everytime any script is run which changes objects on a chart (adds, deletes, changes any properties or timeframes), this will be limited initially to running manually when these unwanted colours are created on a chart (hopefully not too often). 

- On that chart, it should check all objects on each timeframe, as objects may not be on all timeframes and so overlaps may exist on some timeframes and not others.

- For each timeframe, it should identify the (price,time) coordinates of any overlap between two objects and create a new rectangle object with those coordinates (the mask).

-  The mask's colour, when overlapped with the existing ones, should result in the colour of the object with the highest z-axis value of the two overlapping objects. That z-axis parameter will have been stored in the object description (with a default derived from create time).

- The mask's z-value will be the value of the highest object below it, plus one.

- When there are more than two objects overlapping, it should work to keep iterating over the process of comparing two objects, now including mask objects. I think that will take care of the more complex polygons from more than 2 objects overlapping. I don't envisage overlaps from more than 2 or 3 or 4 objects (eg seeing the growth of VAP profiles over time by layering updated ones on top of older ones) and i won't try to code for all edge cases, partly as i am the only user.

What do you think? Does that seem feasible to you? Or are there any things which jump out at you as infeasible?

paul selvan
504
paul selvan  
Nikolai Semko
5834
Nikolai Semko  
MacDougall:

Hi, is it not possible to anchor each corner of a rectangle bitmap to a (time, price) coordinate rather than a pixel coordinate?

PROBLEM: This is for a script which creates simple volume-at-price profiles, made up of many rectangles. When there are two overapping profiles, the overlapping parts of the rectangles are displayed a different color than either of the profiles.

AIM: In an attempt to avoid this i turned to bitmaps with CCanvas. While it is possible to anchor these bitmaps to one (time, price) coordinate, i can't find how to fix those edges or corners to particular times and prices so that they retain their relevance while changing timeframe or zooming. 

If this is not possible, then i see two unnapealing possibilities:

A, mask the overlapping sections of normal rectangle objects. The set of interacting modular scripts i have developed so far are based around quickly and easily adding, selecting, changing, toggling... many objects and groups of objects, scrolling through levels of relevance, in order for the user to relatively easily manage the complexity of many objects without being overwhelmed by them. The idea of adding more objects (the color masks) just seems like a really inelegant and wasteful path i don't want to go down... though i guess that is what computers are for.....

or;

B, recalculate and redraw a bitmap every time a timeframe or zoom is changed. That would then also require this to be an indicator rather than the simpler script. 

If you know anything about this then i'd be really grateful for any ideas as i've researched and experimented about as far as i can feasibly go on my own at the moment. Thanks for any responses!

Форум по трейдингу, автоматическим торговым системам и тестированию торговых стратегий

Цветные свечи (пожелания)

Nikolai Semko, 2019.03.02 14:28

Nevertheless, I spent a couple of hours for a demonstration of replacing the indicator with banded candles so as not to be unfounded.

I even exaggerated at the expense of 30-50 lines of code. The main function ShowBars, which forms the candles on the screen only 9 lines of code:

 void ShowBars( bool change= true )
  {
   static MqlRates B[];
   uint clrBody= 0 ;
   if (change) CopyRates ( _Symbol , _Period ,( int )W.Right_bar,W.BarsInWind,B); else B[ ArraySize (B)- 1 ]=Bar0;
   Canvas.Erase(W.Color);
   for ( int i= 0 ,x=- 1 ; i<W.BarsInWind;i++,x+=W.dx_pix) 
     {
      Canvas.LineVertical(x,( int )(Canvas.Y(B[i].high)- 0.5 ),( int )(Canvas.Y(B[i].low)- 0.5 ),clrLine);
       if (B[i].close>B[i].open) clrBody=clrBull; else if (B[i].close<B[i].open) clrBody=clrBear; else clrBody=clrLine;
      Canvas.FillRectangle(x- int (W.dx_pix* 0.35 ),( int )(Canvas.Y(B[i].open)- 0.5 ),x+ int (W.dx_pix* 0.35 ),( int )(Canvas.Y(B[i].close)- 0.5 ),clrBody);
     }
   Canvas.Update();
  }

It is expensive?

Of course, this code is only demonstration, but still quite working. And "control the width, height of the window, the scale of the display of the graph , rewind, offset" performs.


I advise you to carefully study my class iCanvas. I think this will suit your needs.

MQL4-version 

To add comments, please log in or register