Login Page - Create Account

Support Board


Date/Time: Tue, 17 Mar 2026 04:57:04 +0000



Adding support for persistent pointers to s_CustomChartBarInterface

View Count: 262

[2026-01-25 08:56:19]
curious16 - Posts: 36
In a related thread (#103936) you indicated that you can add support for persistent pointers to the Custom Chart Bar interface. It would be great to have this available, that is, to have a function

void*& GetPersistentPointer(int Key); in the definition of s_CustomChartBarInterface

that provides read/write access to persistent pointers. Could you please let me know whether this will be implemented and when approximately that can be done? Thank you for your support.
[2026-01-25 18:31:40]
User719512 - Posts: 425
Until such time as s_CustomChartBarInterface supports GetPersistentPointer(), you can use GetPersistentInt64() as a workaround.
For full cleanup, use a persistent flag to detect study removal (not shown in proof of concept below).


You will want to TEST THOROUGHLY and don't just use the below blindly.
You will want to ensure you don't leak memory, clean up on study removal, etc.
Adding detailed logging with a "DEBUG" flag or #define will be valuable.


Windows uses a flat virtual address space with little-endian byte order on both x64 and ARM64, so the bit pattern of the pointer is preserved exactly during the cast and storage.
Pointers (void*) are 64-bit on both x64 and ARM64, matching the size of int64_t.


// Define a key for the persistent variable
const int POINTER_KEY = 100;

// Example struct or data to point to
struct MyCustomData {
int value;
};

// Your custom chart bar building function
SCSFExport CustomChartBarBuildingFunction(SCCustomChartBarInterfaceRef cbi) {
// Example: On first call or reload, allocate and store the pointer
// Or use a reload flag with another persistent int
if (cbi.IsFirstBarOfChart) {
MyCustomData* p_data = new MyCustomData(); // Dynamically allocate
p_data->value = 42; // Initialize

// Store pointer as int64_t
int64_t& stored_ptr = cbi.GetPersistentInt64(POINTER_KEY);
stored_ptr = reinterpret_cast<int64_t>(p_data);
}

// Retrieve and use the pointer in subsequent calls
int64_t& stored_ptr = cbi.GetPersistentInt64(POINTER_KEY);
MyCustomData* p_data = reinterpret_cast<MyCustomData*>(stored_ptr);

[2026-01-25 20:43:43]
curious16 - Posts: 36
Thank you for your proposal. This looks interesting, I'll give it a try. I'd still say it would be a good idea to have the GetPersistentPointer() function available in the interface.

Normally when using pointers in a study, I do the memory deallocation in a   
if (sc.LastCallToFunction) { }
block and check for availability of the data structure the pointer refers to (i.e. allocate memory and/or reset) in a
if(sc.IsFullRecalculation) { }
block.

I am not sure with these custom chart bar functions what is called last. Do you know whether sc.LastCallToFunction() is called after all calls to the chart bar function (the function defined with sc.fp_ACSCustomChartBarFunction)?
[2026-01-25 20:58:14]
User719512 - Posts: 425
Add logging to check that and use a persistent int for a flag for state management and to ensure no processing after LastCallToFunction(). A check for null_ptr works also.
[2026-01-25 23:59:08]
Sierra_Chart Engineering - Posts: 23226
We will try to get this done, this week:
In a related thread (#103936) you indicated that you can add support for persistent pointers to the Custom Chart Bar interface. It would be great to have this available, that is, to have a function

Yes this will be the case:
Do you know whether sc.LastCallToFunction() is called after all calls to the chart bar function (the function defined with sc.fp_ACSCustomChartBarFunction)?

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, use the Teton service:
Sierra Chart Teton Futures Order Routing
[2026-01-26 14:32:57]
curious16 - Posts: 36
I tried the proposal of User719512 and can confirm that this works well. Thank you again for proposing this workaround, and thanks also to SC Engineering for adding the persistent pointer function to s_CustomChartBarInterface.

Regarding the auto-hide feature of Custom Chart Bar studies, I asked in another thread whether that could be made optional. I understand why these studies are hidden by default, but it would be helpful if this could be overridden via ACSIL. A use case for this is to selectively color or highlight some bars with output from the Custom Chart Bar study. This can of course be done by adding an Overlay study, but it would be nicer to do this directly in the Chart Bar study.

Could you please clarify whether this can be done or whether there is a fundamental limitation that makes this impossible? As things stand now, the Custom Chart Bar study always switches back to hidden state when I try to manually unhide it in the user interface.
Date Time Of Last Edit: 2026-01-26 14:33:17
[2026-01-27 14:14:38]
curious16 - Posts: 36
Thank you for adding the persistent pointers to the Custom Chart Bar interface. I just tried this out using the latest SC version (v2870) and it works well.

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

Login

Login Page - Create Account