Login Page - Create Account

Support Board


Date/Time: Fri, 19 Apr 2024 09:01:11 +0000



StudyRegionRightCoordinate Problem when

View Count: 851

[2019-05-01 17:22:30]
BlakJak - Posts: 108
I am using GDI and need to get the coordinates of my screen to setup the compatible bitmap for drawing.

I use these lines to get the coorindates:

RECT rc;
rc.left = sc.StudyRegionLeftCoordinate;
rc.right = sc.StudyRegionRightCoordinate;
rc.top = sc.StudyRegionTopCoordinate;
rc.bottom = sc.StudyRegionBottomCoordinate;

Then I use the following for drawing where itr->barIndex() is the index of the bar at which I am going to draw an object.

int x = sc.BarIndexToXPixelCoordinate(itr->barIndex());



The resulting "x" is correct and draws the objects in the correct place on the chart, however it seems that my compatible bitmap is not correct when I attach the trade window to the left side of my chart. My drawings disappear near to the right hand side of my chart at exactly the width of the Trade Window. This means that when I create a compatible bitmap using the StudyRegion coordinates it is not giving me the correct screen coordinates to make my bitmap.

If I remove the Trade Window then the study draws perfectly all the way to the right hand side of the chart.

Could this be a bug in the way the sc.StudyRegionRightCoordinate returns the value when the Trade Window is attached on the left? Or do I need to convert the Study Region coordinates to pixel coordinates somehow? If the later, can you explain to me how to do it?
[2019-05-01 17:44:30]
BlakJak - Posts: 108
I have found a workaround to using sc.StudyRegionXXXXCoordinate to get my code to work. Instead I use GetClientRect() to fill "rc". Here is the full code:

  // Set up the memory device context we will draw to so we can apply transparency. Copy the current image so there is no strange
  // issue with the blending.
  HDC hMemDC = CreateCompatibleDC(DeviceContext);
  RECT rc;
  GetClientRect(WindowHandle, &rc);
  //rc.left = sc.StudyRegionLeftCoordinate;
  //rc.right = sc.StudyRegionRightCoordinate;
  //rc.top = sc.StudyRegionTopCoordinate;
  //rc.bottom = sc.StudyRegionBottomCoordinate;

  HBITMAP hBitMap = CreateCompatibleBitmap(DeviceContext, rc.right - rc.left, rc.bottom - rc.top);
  SelectObject(hMemDC, hBitMap);
  BitBlt(hMemDC, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, DeviceContext, rc.left, rc.top, SRCCOPY);

However, I would still like to understand why my original idea to use the StudyRegion coordinates does not work when there is a Trade Window attached on the left of the chart.
[2019-05-06 13:24:34]
BlakJak - Posts: 108
Any feedback?
[2019-05-16 05:10:47]
BlakJak - Posts: 108
Any feedback?
[2019-05-17 15:04:28]
Sierra Chart Engineering - Posts: 104368
We really need to test this to understand it. We will try to get to that today.
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
[2019-06-03 03:34:25]
Sierra Chart Engineering - Posts: 104368
We have verified that when the void DrawToChart(HWND WindowHandle, HDC DeviceContext, SCStudyInterfaceRef sc ) function is called that the following coordinates are correct with and without the Trade Window attached:

sc.StudyRegionLeftCoordinate;
sc.StudyRegionRightCoordinate;
sc.StudyRegionTopCoordinate;
sc.StudyRegionBottomCoordinate;

We cannot provide programming help and we do not know where you are making a mistake.
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
Date Time Of Last Edit: 2019-06-03 03:34:52
[2019-06-03 06:30:09]
BlakJak - Posts: 108
To clarify your test, did you attach the Trade Window on the LEFT SIDE of the chart?

Also, regarding the coordinate returned by sc.StudyRegionLeftCoordinate, is 0 the left side of the CHART or the left side of the TRADE WINDOW when the Trade Window is attached on the left?
[2019-06-03 10:42:46]
User907968 - Posts: 802
Hi BlakJak,

I think that these functions (sc.StudyRegion######## & sc.BarIndexToXPixelCoordinate) return values based on the chart window co-ordinate system.

If your Device Context / Bitmap is not copied to the origin of the Chart Window (as would be the case when you have a trade window attached to the left of the chart), then you need to translate the Chart Window co-ordinates accordingly.

for example -

for the item drawn to the Device Context
int x = sc.BarIndexToXPixelCoordinate(itr->barIndex()) - sc.StudyRegionLeftCoordinate;

Hopefully this helps.
[2019-06-03 18:33:13]
BlakJak - Posts: 108
Thanks but it is not at all intuitive when the documentation states:

"This value is given in the coordinate system of the client window and is in pixels."

In the case the Trade Window is inside the same client window as the chart then the functions sc.StudyRegionLeftCoordinate and sc.StudyRegionRightCoordinate should take care of it, so I still feel they are not working as intended since anyone dealing with Windows GDIFunctions will be referring to Window coordinates or Screen coordinates.

Is there some way to find the width of the Trade Window?
[2019-06-03 19:28:32]
User907968 - Posts: 802
When a trade window is attached to the chart, sc.StudyRegionLeftCoordinate returns a pixel value for the position of the right hand edge of the trade window, so this is effectively the width of the Trade Window.
[2019-06-04 09:47:51]
BlakJak - Posts: 108
Hi User907968,

Doesn't your last statement contradict your first post?

BTW - the sc.StudyRegionLeftCoordinate does return the correct value for the left edge of the chart with respect to the client window that the chart+trade window are in. It is the sc.StudyRegionRightCoordinate that is incorrect when the trade window is attached on the left.

I have a suspicious feeling that sc.StudyRegionRightCoordinate is actually returning the width of the chart rather than the actual pixel coordinate of the right hand edge. This would mean the to get the right hand edge you need to add sc.StudyRegionLeftCoordinate and sc.StudyRegionRightCoordinate together.

I have tried this out in my code and I can confirm that this fixes the issue.

i.e. using this code fixes the problem when the Trade Window is on the left which in my view confirms a bug in the sc.StudyRegionRightCoordinate value.

// Set up the memory device context we will draw to so we can apply transparency. Copy the current image so there is no strange

// issue with the blending.

HDC hMemDC = CreateCompatibleDC(DeviceContext);
RECT rc;
//GetClientRect(WindowHandle, &rc);
rc.left = sc.StudyRegionLeftCoordinate;
rc.right = sc.StudyRegionLeftCoordinate + sc.StudyRegionRightCoordinate;
rc.top = sc.StudyRegionTopCoordinate;
rc.bottom = sc.StudyRegionBottomCoordinate;

HBITMAP hBitMap = CreateCompatibleBitmap(DeviceContext, rc.right - rc.left, rc.bottom - rc.top);
SelectObject(hMemDC, hBitMap);
BitBlt(hMemDC, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, DeviceContext, rc.left, rc.top, SRCCOPY);

[2019-06-04 10:49:45]
Sierra Chart Engineering - Posts: 104368
sc.StudyRegionRightCoordinate will remain the same when the Trade Window is attached or not to the left side because the right side coordinate does not change.

regarding the coordinate returned by sc.StudyRegionLeftCoordinate, is 0 the left side of the CHART or the left side of the TRADE WINDOW when the Trade Window is attached on the left?
That would be the left side of the chart when the Trade Window is not attached. Or there is no left side scale.
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
Date Time Of Last Edit: 2019-06-04 11:00:52
[2019-06-04 10:59:43]
User907968 - Posts: 802
There is no contradiction, sc.StudyRegion####Coordinate returns a pixel value based on the chart window co-ordinate system.
The origin/datum (0,0) of the chart window is the top left corner.

The main point of my original post was to make sure not to mix co-ordinate systems.

If you have a solution and are happy with it then I need not say any more.
[2019-06-04 11:10:13]
BlakJak - Posts: 108
Perhaps I am misunderstanding you then. If you are saying that sc.StudyRegionLeftCoordinate returns 0 since it is always the left most pixel of the chart, then how is it possible that it can also give me the right hand edge of the trade window which would not be 0 when the Trade Window is on the left?
[2019-06-04 13:58:51]
Sierra Chart Engineering - Posts: 104368
It is only going to return zero when the Trade Window is not attached on the left. Otherwise, it will be set to the chart window client coordinate of one pixel after the right edge of the Trade Window, if it is on the left.
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
Date Time Of Last Edit: 2019-06-04 13:59:07
[2019-06-04 14:07:16]
BlakJak - Posts: 108
OK - hat was my understanding all along.

As mentioned in original post, the problem is not with the LEFT coordinate but with the RIGHT coordinate.

Adding LEFT+RIGHT gives me the actual right hand edge of the chart for the BitMap which leads me to believe that RIGHT is actually wrongly set to CHART WIDTH.
[2019-06-04 17:58:04]
Sierra Chart Engineering - Posts: 104368
The right coordinate is going to be the chart width minus the width required for the right side price scale. But that is not wrong.

There simply couldn't be anything wrong with these variables because they are extensively used within Sierra Chart itself and they are completely correct at the time the chart is being drawn and your drawing function is called.
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
Date Time Of Last Edit: 2019-06-04 17:58:52
[2019-06-04 19:47:40]
BlakJak - Posts: 108
If the right coordinate is the chart width as you say, then that explains why I get the wrong info when the Trade Window is attached on the left. The width value would make my BitMap too small and this can explain why I have the truncating feature on my study.

To post a message in this thread, you need to log in with your Sierra Chart account:

Login

Login Page - Create Account