Login Page - Create Account

Support Board


Date/Time: Tue, 26 Nov 2024 00:31:29 +0000



Post From: Access data using GDIFunction DrawToChart()

[2024-01-19 20:16:52]
User895355 - Posts: 55
Yes, been through that file. I have what I want working as far as the layout, a rectangle along the right side of the chart. I got the data working with the example you showed me using a double Array. I was able to display the dummy data. However, *I think* I need to use a map and I believe the allocation of memory is what is busting my script.
This is the meat of my script after sc.SetDefaults:

// Section 2 - Do data processing here
std::map<float, char> *tpoMap = (std::map<float, char> *)sc.GetPersistentPointer(1);
if (sc.LastCallToFunction)
{
if (tpoMap != NULL)
{
sc.FreeMemory(tpoMap);
sc.SetPersistentPointer(1, NULL);
}
return;
}
if (tpoMap == NULL)
{
// allocate memory
tpoMap = (std::map<float, char> *)sc.AllocateMemory(1024 * sizeof(std::map<float, char>));

if (tpoMap != NULL)
{
it = tpoMap->find(sc.Close[sc.Index]);
if (it != tpoMap->end())
{
tpoMap->erase(it);
msg.Format("Index exists...%.2f", sc.Close[sc.Index]);
sc.AddMessageToLog(msg, 1);
return;
}
else
{
tpoMap->insert({sc.Close[sc.Index], 'A'});
sc.SetPersistentPointer(1, tpoMap);
}
}
}
sc.p_GDIFunction = DrawToChart;

Then in DrawToChart() I try and pull in the data like so:

std::map<float, char> *tpoMap = (std::map<float, char> *)sc.GetPersistentPointer(1);
std::map<float, char>::iterator it;

With a loop like so:

for (auto it = tpoMap->begin(); it != tpoMap->end(); it++)
{
val.Format("Val: %.2f %c", it->first, it->second);
sc.AddMessageToLog(val, 1);

sc.Graphics.DrawTextAt(val + "<", sc.StudyRegionRightCoordinate - 200, (sc.StudyRegionTopCoordinate + 5) * 20);
}

I'm sure this is not correct, but I'm not sure how to correct it.
Date Time Of Last Edit: 2024-01-19 20:17:30