Support Board
Date/Time: Tue, 26 Nov 2024 00:42:51 +0000
Post From: Access data using GDIFunction DrawToChart()
[2024-01-21 16:56:44] |
User895355 - Posts: 55 |
Wow, thanks for your help! I've made those changes and it's not crashing now at all. Please see the changes I've made: --- brevity if (sc.LastCallToFunction || sc.IsFullRecalculation) { if (tpoMap != NULL) { /* sc.FreeMemory(tpoMap); */ delete tpoMap; sc.SetPersistentPointer(sc.Input[0].GetInt(), NULL); tpoMap = NULL; sc.p_GDIFunction = nullptr; } return; } // I put this here if (currentBar < newYorkStart || currentBar > newYorkEnd) return; if (tpoMap == NULL) { tpoMap = new std::map<float, std::vector<char>, std::greater<float>>; if (tpoMap != NULL) sc.SetPersistentPointer(sc.Input[0].GetInt(), tpoMap); else return; } ----- brevity ...and here is my DrawToChart() code: void DrawToChart(HWND WindowHandle, HDC DeviceContext, SCStudyInterfaceRef sc) { if (sc.GetPersistentPointer(sc.Input[0].GetInt()) == NULL) return; std::map<float, std::vector<char>, std::greater<float>> *tpoMap = (std::map<float, std::vector<char>, std::greater<float>> *)sc.GetPersistentPointer(sc.Input[0].GetInt()); std::map<float, std::vector<char>>::iterator it; SCString val; // yellow brush n_ACSIL::s_GraphicsBrush GraphicsBrush; GraphicsBrush.m_BrushType = n_ACSIL::s_GraphicsBrush::BRUSH_TYPE_SOLID; GraphicsBrush.m_BrushColor.SetRGB(25, 25, 25); sc.Graphics.SetBrush(GraphicsBrush); // pen n_ACSIL::s_GraphicsPen GraphicsPenForRectangle; GraphicsPenForRectangle.m_PenColor.SetColorValue(COLOR_BLUE); GraphicsPenForRectangle.m_PenStyle = n_ACSIL::s_GraphicsPen::e_PenStyle::PEN_STYLE_SOLID; GraphicsPenForRectangle.m_Width = 1; sc.Graphics.SetPen(GraphicsPenForRectangle); // draw rectangle at top right of chart sc.Graphics.DrawRectangle(sc.StudyRegionRightCoordinate - 200, sc.StudyRegionTopCoordinate + 5, sc.StudyRegionRightCoordinate, sc.StudyRegionBottomCoordinate); // hollow rectangle sc.Graphics.ResetBrush(); // marker sc.Graphics.SetTextAlign(TA_NOUPDATECP); n_ACSIL::s_GraphicsFont GraphicsFont; GraphicsFont.m_Height = 6; GraphicsFont.m_Weight = FW_NORMAL; sc.Graphics.SetTextFont(GraphicsFont); n_ACSIL::s_GraphicsColor GraphicsColor; n_ACSIL::s_GraphicsColor BgColor; GraphicsColor.SetRGB(255, 255, 255); BgColor.SetRGB(25, 25, 25); sc.Graphics.SetTextColor(GraphicsColor); sc.Graphics.SetBackgroundColor(BgColor); /* sc.Graphics.DrawTextAt(val + "<", sc.StudyRegionRightCoordinate - 200, (sc.RegionValueToYPixelCoordinate(sc.Close[sc.Index], sc.GraphRegion) - 10)); */ SCString debug; int count = 8; /* for (const auto &pair : *tpoMap) */ for (it = tpoMap->begin(); it != tpoMap->end(); it++) { const std::vector<char> &charVector = it->second; std::string chars; for (char c : charVector) { chars += c; } SCString pointer = "<"; if (sc.Close[sc.Index] == it->first) val.Format("%.2f %s %s", it->first, chars.c_str(), pointer.GetChars()); else val.Format("%.2f %s", it->first, chars.c_str()); sc.Graphics.DrawTextAt(val, sc.StudyRegionRightCoordinate - 200, (sc.StudyRegionTopCoordinate + 5) + count); count += 8; } /* n_ACSIL::s_GraphicsPen MarkerPen; MarkerPen.m_PenColor.SetColorValue(COLOR_WHITE); MarkerPen.m_PenStyle = n_ACSIL::s_GraphicsPen::e_PenStyle::PEN_STYLE_SOLID; MarkerPen.m_Width = 2; sc.Graphics.SetPen(MarkerPen); sc.Graphics.MoveTo(sc.StudyRegionRightCoordinate - 150, sc.RegionValueToYPixelCoordinate(sc.Close[sc.Index], sc.GraphRegion)); sc.Graphics.LineTo(sc.StudyRegionRightCoordinate - 200, sc.RegionValueToYPixelCoordinate(sc.Close[sc.Index], sc.GraphRegion)); */ return; } |