Login Page - Create Account

Support Board


Date/Time: Thu, 28 Mar 2024 23:58:51 +0000



[Programming Help] - Time and Sales + draw to chart, Sierra Chart becomes unresponsive

View Count: 326

[2022-11-06 17:27:16]
onnb - Posts: 660
hi - when using the time and sales with p_GDIFfunction Sierra Chart becomes unresponsive.
We get this on version 2448 (not sure on other versions, have not tested)

See script below that reproduces it.
Add to a chart and leave it running with a live feed. As time and sales records come in the chart/SC will freeze at some point.



#include "sierrachart.h"


SCDLLName("Study Becomes Unresponsive")

static void DrawToChart(HWND hWnd, HDC hdc, SCStudyInterfaceRef sc)
{
  int& justavariable = sc.GetPersistentInt(1);
  c_SCTimeAndSalesArray TimeSales;
  sc.GetTimeAndSales(TimeSales);
  int TimeSalesSize = TimeSales.Size();
  if (TimeSales.Size() > 0)
  {
    int type = 0;
    int vol = 0;
    float price = 0;

    for (int i = TimeSales.Size() - 1; i >= 0; i--)
    {
      if (TimeSales[i].Type == SC_TS_BID)
        justavariable += TimeSales[i].Volume;
      if (TimeSales[i].Type == SC_TS_ASK)
        justavariable += TimeSales[i].Volume;
    }
  }
}

SCSFExport scsf_StudyBecomesUnresponsive(SCStudyInterfaceRef sc)
{
  if (sc.SetDefaults)
  {
    sc.GraphName = "Study Becomes Unresponsive";
    sc.StudyDescription = "";
    sc.AutoLoop = 0;
    sc.GraphRegion = 0;
    sc.p_GDIFunction = DrawToChart;
    return;
  }
}




[2022-11-06 20:24:49]
gorx1 - Posts: 8
DrawToChart sums 'all' the volume in TS record, which btw increases after every tick (until a certain limit specified in settings), and adds is to a persistent integer variable referenced by int& justavariable.

So if this function gets called on chart update interval, i.e several times a second, you're probably getting overflow of that integer variable.
[2022-11-06 20:53:05]
onnb - Posts: 660
The issue came up on bigger project, this is just sample code to demonstrate and reproduce.

It doesn't get anywhere near to overflow an int before crashing.
To be sure I set justavariable to 0 before the loop and it still freezes.

Btw, I'd expect that even if the int were to overflow with a larger value, the result of that would be wrong values as it overflows MAX_INT but I would not expect a freeze.
Date Time Of Last Edit: 2022-11-06 20:55:43
[2022-11-23 17:45:55]
onnb - Posts: 660
Ping....just checking in if you can provide thoughts on this issue

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

Login

Login Page - Create Account