Login Page - Create Account

Support Board


Date/Time: Sat, 23 Nov 2024 19:24:22 +0000



Post From: ACSIL - how to delete (ACSIL) user drawings when time frame is changed?

[2013-07-23 09:31:56]
User11748 - Posts: 14
I think I found a solution.

One of your post made me realize that persistent variables are still persistent when study is fully recalculated, whereas I thought that it was set again to 0 at the beginning of the recalculation.

So I have simply added this piece of code:
// If study is recalculated, let's delete the old marker:
if ( sc.Index == 0 ) {
sc.DeleteUserDrawnACSDrawing(sc.ChartNumber, UniqueLineNumber + sc.PersistVars->i1);
}

I have implemented this change in my bigger projects, and it seems to work. Problem solved.

Full code is below.

Thanks again for your help!

Nicolas

#include "sierrachart.h"

SCDLLName("Nicolas Test 2");

SCSFExport scsf_Nicolas_Test_2(SCStudyGraphRef sc) {

  if ( sc.SetDefaults ) {
    sc.GraphName = "Nicolas Test 2";
    sc.AutoLoop = 1;
    sc.FreeDLL = 1;
    sc.GraphRegion = 0;
    return;
  }

  int UniqueLineNumber = 74191;

  // If study is recalculated, let's delete the old marker:
  if ( sc.Index == 0 ) {
    sc.DeleteUserDrawnACSDrawing(sc.ChartNumber, UniqueLineNumber + sc.PersistVars->i1);
  }

  // If study is removed, let's delete the marker:
  if ( sc.LastCallToFunction && sc.PersistVars->i1 > 0 ) {
    sc.DeleteUserDrawnACSDrawing(sc.ChartNumber, UniqueLineNumber + sc.PersistVars->i1);
  }

  bool firstBarOfJuly_19_2003 = sc.BaseDateTimeIn[sc.Index].GetYear() == 2013
    && sc.BaseDateTimeIn[sc.Index].GetMonth() == 7
    && sc.BaseDateTimeIn[sc.Index].GetDay() == 19
    && sc.BaseDateTimeIn[sc.Index-1].GetDay() != 19;

  if ( firstBarOfJuly_19_2003 ) {
    sc.PersistVars->i1 = sc.Index - 10; // index of the bar on top of which the marker shall be drawn
    s_UseTool Tool;
    Tool.Clear();
    Tool.ChartNumber = sc.ChartNumber;
    Tool.DrawingType = DRAWING_MARKER;
    Tool.LineNumber = UniqueLineNumber + sc.PersistVars->i1;
    Tool.BeginIndex = sc.PersistVars->i1;
    Tool.BeginValue = sc.High[sc.PersistVars->i1];
    Tool.Color = RGB(0,200,200);
    Tool.AddMethod = UTAM_ADD_ALWAYS;
    Tool.MarkerType = MARKER_X;
    Tool.MarkerSize = 8;
    Tool.LineWidth = 5;
    Tool.AddAsUserDrawnDrawing = 1; // ***
    sc.UseTool(Tool);
  }
}