Login Page - Create Account

Support Board


Date/Time: Fri, 29 Nov 2024 05:51:10 +0000



[Programming Help] - Help with rectangle drawing tool

View Count: 307

[2023-03-04 15:42:38]
User538264 - Posts: 26
Hi, I am trying to add a rectangle to opening range of each day.
Below is the code I have written. The problem here is that it keeps adding more drawings over the previous one each time the study is called which makes it overloaded.
If I use ADD_OR_ADJUST method, then only the last drawing is added to the chart and not the historical ones.
How do I make it so that the drawings are not added on every call to study?
Thanks.



SCSFExport scsf_aza_DR_range(SCStudyInterfaceRef sc)
{
  int inputs = 0;

  SCInputRef i_startTime = sc.Input[inputs++];
  SCInputRef i_endTime = sc.Input[inputs++];

  if (sc.SetDefaults)
  {

    sc.GraphName = "aza_DR_Range";
    sc.GraphRegion = 0; //Main chart region
    sc.AutoLoop = 1;


    i_startTime.Name = "Session Start Time";
    i_startTime.SetTime(HMS_TIME(14, 30, 0));

    i_endTime.Name = "Session End Time";
    i_endTime.SetTime(HMS_TIME(15, 30, 0));


    return;
  }


  SCDateTime dt_StartTime, dt_EndTime;
  dt_StartTime.SetDateTime(sc.BaseDateTimeIn[sc.Index].GetDate(), i_startTime.GetTime());
  dt_EndTime.SetDateTime(sc.BaseDateTimeIn[sc.Index].GetDate(), i_endTime.GetTime());

  float orOpen;
  float orHigh;
  float orLow;
  float orClose;

  float NextOpen;

  sc.GetOHLCOfTimePeriod(dt_StartTime, dt_EndTime, orOpen, orHigh, orLow, orClose, NextOpen);


  SCString msg;
  msg.Format("drws = %d", sc.GetACSDrawingsCount(sc.ChartNumber, 1));
  sc.AddMessageToLog(msg, 1);


  s_UseTool Tool1;
  int& r_LineNumber = sc.GetPersistentInt(4);

  Tool1.Clear();

  //if (r_LineNumber != 0)
  //  Tool1.LineNumber = r_LineNumber;

  //Tool1.LineNumber = r_LineNumber > 5 ? 1 : r_LineNumber;

  //sc.DeleteACSChartDrawing(sc.ChartNumber, TOOL_DELETE_ALL, r_LineNumber);

  Tool1.ChartNumber = sc.ChartNumber;
  Tool1.DrawingType = DRAWING_RECTANGLEHIGHLIGHT;
  Tool1.DisplayHorizontalLineValue = 1;

  Tool1.BeginValue = orHigh;
  Tool1.EndValue = orLow;
  Tool1.BeginDateTime = dt_StartTime;
  Tool1.EndDateTime = dt_EndTime;
  Tool1.Color = RGB(211, 211, 211);
  Tool1.SecondaryColor = RGB(211, 211, 211);
  Tool1.TransparencyLevel = 80;
  Tool1.NoVerticalOutline = 1;
  Tool1.LineWidth = 1;
  Tool1.AddMethod = UTAM_ADD_ONLY_IF_NEW;


  sc.UseTool(Tool1);

  //r_LineNumber = Tool1.LineNumber;
  //r_LineNumber++;

  
  //if (sc.GetACSDrawingsCount(sc.ChartNumber, 1) > 5)
  //{
  //  sc.DeleteACSChartDrawing(sc.ChartNumber, TOOL_DELETE_CHARTDRAWING, r_LineNumber + 5);
  //}




}


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

Login

Login Page - Create Account