Login Page - Create Account

Support Board


Date/Time: Wed, 12 Mar 2025 11:47:59 +0000



Vector losing it's value ACSIL (need persistent vector)

View Count: 270

[2024-12-24 11:08:29]
Balazs - Posts: 13
Hi Everybody,

I need serious help from ACSIL gurus as I cant figure out how to make a vector persistent. I want create a vector that holds the values (lines) of imbalances that are still not crossed, so I can calculate with them later and access them quicker rather than doing a for loop in sc.GetStudyLineUntilFutureIntersectionByIndex.

So I created the vector (std::vector(....), the code does the calculations correctly, the vectors stores the values of the lines I want stored.

BUT then on the next cycle(Bar) (i have autoloop set to true). the vector is empty(?) and refills them with the values found in on that Bar (if any). I know this because I have the size of the vector printed on every bar (see picture). it is not a consecutive number ( size of vector for bar n adding to the value of bar n-1), but a size only true for that bar. every bar show 1 instead of 1 ... 2.... 3 (adding the number of found lines of that bar to the vector).

So long story short. How can I make the vector persistent so the new found values of the current bar are added to the vector of the previous bar?
Date Time Of Last Edit: 2024-12-24 11:21:25
imageScreenshot 2024-12-24 120705.png / V - Attached On 2024-12-24 11:07:57 UTC - Size: 88.35 KB - 43 views
[2024-12-24 11:27:13]
User431178 - Posts: 613
Useful page of ACSIL concepts / hints: ACSIL Programming Concepts
In particular: ACSIL Programming Concepts: Allocating Memory for Classes


Failing that: https://www.sierrachart.com/index.php?page=doc/SierraChartStudyAndSystemProgrammers.php
Date Time Of Last Edit: 2024-12-24 11:27:46
[2024-12-24 12:31:36]
Balazs - Posts: 13
Thanks for the fast reply. Just to give some context: I have read every letter of the documentation. I think I grasp the core of STL_vectors, classes, ect. I have implemented the examples from the sierra website including some code they refer to in their ASC_source folder. and again, the code works fine it does what it needs to, to the extent of creating the vector, setting everything to NULL, initiating a persistentpointer, etc. It just loses the values wehn a new bar comes to the chart.

I could refer to a previous index [sc.Index-1] and reuse the vector at that index, however, I don't know if that is possible at all. The codes I tried give an error.

see code bellow. I cant seem to get past this issue. So if you have any concrete code tips, I would be more than gratefull.



//initiating the vector

std::vector<double>* InbLines;

  if(sc.LastCallToFunction)
  {
    if(InbLines != NULL)
    {
      delete InbLines;
      sc.SetPersistentPointer(1, NULL);
    }

    return;
  }

if (InbLines == NULL)
  {
    InbLines = new std::vector<double>;

    if(InbLines != NULL)
      sc.SetPersistentPointer(1, InbLines);
    else
    {
      sc.AddMessageToLog("Memory allocation error.", 1);
      return;
    }
  }



// doing some calculations, bla bla..



// lines 1 to 5 found in previous section adding them to the vector

if ( LineONE != 0)
  {
  InbLines->push_back(LineONE);
    
  CURRENT_keys++;  
  }
  
  
    if ( LineTWO != 0)
    {
      InbLines->push_back(LineTWO);
    
    
    CURRENT_keys++;
    }
  
      if ( LineTHREE != 0)
      {
        InbLines->push_back(LineTHREE);
  
  
      CURRENT_keys++;
      }
  
        if ( LineFOUR != 0)
        {
          InbLines->push_back(LineFOUR);
        CURRENT_keys++;
        }
  
  
          if ( LineFIVE != 0)
          {
            InbLines->push_back(LineFIVE);
  
          CURRENT_keys++;
          }
  }

// counting the number of elements and showing it at the bottom each bar via a Subgraph. This way I can count the amount of doubles inside the vector at a specific bar

NumbT[sc.Index] = InbLines->size();
  NumbOnLow[sc.Index] = NumbT[sc.Index];


Date Time Of Last Edit: 2024-12-24 12:45:25
[2024-12-24 13:16:44]
User431178 - Posts: 613
I have implemented the examples from the sierra website

Check it again, your code is missing an important part of the linked example.
In your code, you are always starting with an unintialized vector pointer (undefined behaviour as it may or may not be null etc).
You need to actually get the persistent pointer to use it after you first initialize.

This is wrong:
std::vector<double>* InbLines;

Instead it should be:
std::vector<double>* InbLines = static_cast<std::vector<double>*>(sc.GetPersistentPointer(1));


In the example, this is the equivalent line:
ClassA * p_ClassA = (ClassA *)sc.GetPersistentPointer(1);

[2024-12-24 13:22:36]
Balazs - Posts: 13
Oh My goodness.. This programming game is amazing but sometimes a real life killer. I tried the code you just gave me 30 times and simply missed a logical step and thus mistyped it.. Thanks my man. You made my Hollidays!! again, thanks so much!

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

Login

Login Page - Create Account