Login Page - Create Account

Support Board


Date/Time: Sun, 22 Dec 2024 17:45:41 +0000



[User Discussion] - Problem with drawing using sc.p_GDIFunction

View Count: 3018

[2014-04-23 14:01:09]
norvik - Posts: 22
Dear SC Support,
I have a problem with drawing using sc.p_GDIFunction. Study is calculated only when it is applied on the chart or when I
press "Recalculate" at the chart menu. After I do some interactive action with chart, moving or scrolling, I see a wrong drawing result.

Code:
// GDI.cpp : Defines the exported functions for the DLL application.
//

#include "stdafx.h"
#include <windows.h>
#include "C:\SierraChart\ACS_Source\sierrachart.h"

SCDLLName ("GDI Example")

// This file demonstrates the functionality to use the Windows graphics device interface with ACSIL to freely draw inside of the chart window

// Windows GDI documentation can be found here: http://msdn.microsoft.com/en-nz/library/windows/desktop/dd145203%28v=vs.85%29.aspx

/*==========================================================================*/
void DrawToChart(HWND hWnd, HDC hDC); //Drawing function declaration

int firstY;
int secondY;
int firstX;
int secondX ;
/*==========================================================================*/
SCSFExport scsf_DrawToChartExample(SCStudyInterfaceRef sc)
{

  if (sc.SetDefaults)
  {

    // Set the configuration and defaults

    sc.GraphName = "Draw To Chart Example";

    sc.AutoLoop = 0;

    // When specifying a GDI function below, this must be false. Otherwise, the GDI function will not be called.
    sc.FreeDLL = 0;

    sc.GraphRegion = 0;

    // This is how we specify the drawing function.
    sc.p_GDIFunction = DrawToChart;

    return;
  }


  // Do data processing
firstY = sc.RegionValueToYPixelCoordinate(sc.Close[sc.ArraySize - 1],0);
secondY = sc.RegionValueToYPixelCoordinate(sc.Close[sc.ArraySize - 100],0);
firstX = sc.BarIndexToXPixelCoordinate(sc.ArraySize - 1);
secondX = sc.BarIndexToXPixelCoordinate(sc.ArraySize - 100);


}
/*==========================================================================*/

//This is the actual drawing function. This function is specified by the "sc.p_GDIFunction" member in the main study function. This drawing function is called when Sierra Chart draws the study on the chart. This will only occur after there has been a call to the main "scsf_" study function which is defined above.

//Currently this drawing function does not have access to the ACSIL "sc." structure. We are considering how this might be possible to add in the future. Any study data that you need to access in this drawing function, should be placed into global variables by the main "scsf_" study function which can then be accessed by this function when it is called.

void DrawToChart(HWND hWnd, HDC hDC)
{
  // Создаем Pen
HPEN hPen = CreatePen (PS_SOLID, 2, RGB(255, 0, 0));

// Выбираем свой Pen в DC, запоминаем старый Pen
HPEN hOldPen = (HPEN)SelectObject (hDC, hPen);

// Перемещаем точку рисования в левый верхний угол окна
MoveToEx(hDC, firstX, firstY, NULL);
// Рисуем линию в правый нижний угол
LineTo(hDC, secondX, secondY);

// Выбираем старый Pen в DC (освобождаем свой Pen из DC)
SelectObject(hDC, hOldPen);

// Удаляем Pen
DeleteObject (hPen);

  return;
}

/*==========================================================================*/

imageAfterApplyingStudy.jpg / V - Attached On 2014-04-23 14:00:37 UTC - Size: 169.98 KB - 693 views
imageAfterResizingBarSpacing.jpg / V - Attached On 2014-04-23 14:00:46 UTC - Size: 181.66 KB - 616 views
[2014-04-23 17:29:20]
Sierra Chart Engineering - Posts: 104368
Yes, this is true:

Study is calculated only when it is applied on the chart or when I
press "Recalculate" at the chart menu

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
[2014-04-23 19:12:53]
ejtrader - Posts: 688
norvik - There are few limitations with GDI function at present. Main issue is lack of "SC" structure availability to this function ( which SC team is going to look at it at some point in the future ).

I started using this function but due to unavailability of SC structure - but ended up going with UseTool instead.

If it is a must for you to use GDI functions, you would have to depend on global variables a lot and keep populating them on every tick( to account for any changes to the SC window co-ordinates) and make a call to GDI function on every tick.

In general - It's really not convenient to use it in it's current state and you might want to use UseTool instead until SC structure is made available to GDI functions somehow(??).

Thanks


Date Time Of Last Edit: 2014-04-23 19:14:37
[2014-04-25 12:52:05]
norvik - Posts: 22
ejtrader , thank you for your feedback. sc.UseTool is a greate feacher, but at some situations i prefer to draw without any limitations.
I have software, which can plot DOM historically, it is a modyfied original code of JTools (NANEX LLC). I have to export time&sales and DOM data from SierraChart to another application in real time , debug and support several thousand strings source code program. It is really convenient to use ASCIL study and apply it directly to SC charts..

So, I hope SC Team will improve this function.
Date Time Of Last Edit: 2014-04-25 13:01:56
imageDepth.jpg / V - Attached On 2014-04-25 12:51:35 UTC - Size: 294.84 KB - 6074 views
[2014-04-25 13:05:06]
ejtrader - Posts: 688
norvik - Interesting way you are using this and agree with you about the number of possibilities if GDI function can be improved :)

Thanks.
[2014-04-28 07:08:56]
Sierra Chart Engineering - Posts: 104368
In the next release, the GDI function defined by an advanced custom study will now receive the "sc" structure.

This is the new declaration:

void DrawToChart(HWND WindowHandle, HDC DeviceContext, SCStudyInterfaceRef sc )

At every chart draw, the sc structure members related to coordinates will now be updated.

This greatly enhances the usability and hopefully should be a solution to the first issue described in this thread.
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: 2014-05-01 08:05:51
[2014-05-01 07:27:15]
norvik - Posts: 22
Wonderful !

Many thanks, SC Cupport,

Good luck!





[2014-05-01 23:44:54]
ejtrader - Posts: 688
SC Team - Thank for doing this. Would you please also provide a short example(or update the existing example) - to make use of this structure efficiently - and more importantly how this new function would account for screen size changes done by users - without "re-populating" x,y co-ordinates.

What is the value for HDC that needs to be passed while calling the function?

Thanks
Date Time Of Last Edit: 2014-05-02 00:07:51
[2014-05-02 21:47:19]
Sierra Chart Engineering - Posts: 104368

void DrawToChart(HWND WindowHandle, HDC DeviceContext, SCStudyInterfaceRef sc ) is a function that Sierra Chart calls. So Sierra Chart sets the DeviceContext.

Any of the "sc" structure member variables which would change when resizing a chart window, will change.

We do not see a need for an example beyond what is provided. You should be able to make use of this functionality and know how to use it.
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
[2014-05-02 22:55:18]
ejtrader - Posts: 688
SC Team - Current GDIExample.cpp is not compiling with the changes you have made. Would you please check?

thanks
[2014-05-02 22:56:46]
Sierra Chart Engineering - Posts: 104368
It compiles under Visual C++ for us. What is the specific compiler error that you get. Otherwise, it is hard for us to comment on this.
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
[2014-05-02 23:28:30]
ejtrader - Posts: 688
Sorry - forgot about the necessity to use VC++ for this. Was using QT/g++ for this. Would check it out in VC++.

This was the line erroring out in QT/g++.

sc.p_GDIFunction = DrawToChart;

Error:
http://screencast.com/t/TNbgh87smmq
[2014-05-02 23:32:39]
Sierra Chart Engineering - Posts: 104368
You can use Qt/g++. Change the code like this:
sc.p_GDIFunction = (void*)DrawToChart;

This should work, but maybe you need to use a reinterpret_cast
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
[2014-05-02 23:43:36]
ejtrader - Posts: 688
SC Team - Need helping hand here.

sc.p_GDIFunction = (void*)DrawToChart; // this didn't work
sc.p_GDIFunction = reinterpret_cast<void*>(DrawToChart); // This also didn't work

http://screencast.com/t/PZVlk7mlUhw -- both the cases - this is the error

Thanks
Date Time Of Last Edit: 2014-05-03 00:12:31
[2014-05-03 00:31:04]
Sierra Chart Engineering - Posts: 104368
Those compiler errors do not look like they apply to these lines. What lines are they referring to? And what is the source of those lines.

This compiles just fine on Visual C++:
sc.p_GDIFunction = reinterpret_cast<void *>( ACSGDIFunction);
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: 2014-05-03 00:31:19
[2014-05-03 00:32:31]
ejtrader - Posts: 688
Thanks SC team. As it works fine in VC++ - should be fine to manage (Though wish it could work in g++ ).

The error is specific to the above line. I tried it in "geany/g++" as well and same error. Same is the case with SC's built-in compiler.

Thanks

http://screencast.com/t/3lGIEHwq

http://screencast.com/t/1idUwzozLG
Date Time Of Last Edit: 2014-05-03 00:37:49
attachmentV1GDIExample.cpp - Attached On 2014-05-03 00:37:38 UTC - Size: 2.36 KB - 569 views
[2014-05-04 12:23:36]
ejtrader - Posts: 688
SC Team - Solved the compile issue with g++ by including gdi libraries during link time.

Happened to check the new enhancements - including SC structure and auto adjustment of co-ordinates - certainly this makes the functionality a lot better now.

Thanks
Date Time Of Last Edit: 2014-05-04 13:06:33
[2015-05-15 04:43:43]
User17836 - Posts: 12
ejtrader - which file specifically did you indlucde? I am getting the following error on VS2010:

error C2065: 'ACSGDIFunction' : undeclared identifier

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

Login

Login Page - Create Account