Login Page - Create Account

Support Board


Date/Time: Sat, 18 May 2024 22:04:33 +0000



[Programming Help] - ACSIL - UDP request for resetting Persistent Variables re sc.SetDefaults

View Count: 1622

[2019-01-06 14:58:49]
PeterSt - Posts: 36
Hi,

Search tells me that this has been asked before but remained unanswered (at least back then) : sc.SetDefaults - resetting from within active ACSIL function

Also, I think I can reason out that no normal solution can exist to reset the Persistent Variables. Possibly logical reasons may exist for wanting this in normal circumstances, but it could be circumvented by explicit re-assignment. However, I am talking in the context of the solution in here : ACSIL - DLL cannot be opened for writing | Post: 167742 ... which is about recompiling with external editors (like Visual Studio) and my presented solution for that. Thus, the problem is general and would be in order for any random Study.

If there is a ready solution or best approach for this today, then can someone kindly let me know how to approach this ?

The problem summarized

In order to fully automated reload a changed Study, we can make calls to Sierra by means of the UDP interface. Given last link above utilizes that. Also see here : UDP Interface

What I found is that the DLL is (or all are) reloaded all right, but that the Persistent Variables are not reset. Mind you, a situation may well exist that this is even not desired, so I am kind of explicitly not asking for doing this inherently. Instead it should be done on command. Btw, please notice the relation to Global Variables, which possibly need to remain as they are. At this moment I am unsure about this because I am only just starting with ACSIL. Said "possibly" could imply that these too need to be reset with some (call back ?) means.

If not clear already, a small example of what I refer to :

if (sc.SetDefaults)
  {
    // Set the configuration and defaults
    
    sc.GraphName = "XX02 New Study";    
    sc.StudyDescription = "XX02 Insert description here.";    
    sc.AutoLoop = 1; // true
    
    // During development set this flag to 1, so the DLL can be rebuilt without restarting Sierra Chart.
    // When development is completed, set it to 0 to improve performance.
    // sc.FreeDLL = 1; // 06-01-2019,PS, Deprecated (right ?).
    
    sc.Subgraph[0].Name = "XX02 Subgraph 1 Name a";
    sc.Subgraph[0].PrimaryColor = RGB(255,200,0); // Red 06-01-2019,PS, E.g. this one will never reset.
    sc.Subgraph[0].DrawStyle = DRAWSTYLE_LINE; // Look in scconstants.h for other draw styles
    
    sc.Input[0].Name = "Input 1 Name b";
    sc.Input[0].SetInt(20); // Set the default value to 20
    sc.Input[0].SetIntLimits(1, 1000); //Optional: Limit the range of this input to 1-1000
    
    return;
  }
  

I think it will be obvious that at developing a Study, the code in the "one time settings" will need to be adjusted once in a while just the same. And when we can not imply sc.Defaults to True, we will not really be able to re-initizalize the Persistent Variables in a transparent way. Or even not at all (I would not know how to and I also tried all sc. properties and functions of the main If of this).
And of course, removing the Study from the Chart and add it again, takes too much time. ;-)

A temporary solution looks to be :

if (true) //(sc.SetDefaults) // If (true) for new compiled version. Data will never be processed.
  {
// Init Code goes here.
return;
  }

but it would be an odd two-stage process when we are working on this init code plus it can never combine with real data to be processed (because it never will (and should not) during the if true).

Thanks,
Peter
[2019-01-06 16:02:48]
PeterSt - Posts: 36
Allow me to add that this :

  bool Recompile = 0;   // Set to 1 when the SetDefaults are to be executed. Back to 0 data processing.

  if (Recompile || sc.SetDefaults)
  {
    // Set the configuration and defaults

is done in a wimp. Two actually. ;-) But fast enough once you are used to not forgetting about it.
I suppose everybody should be OK with this, and the Sierra Team might have better things to do.
[2019-01-09 02:35:00]
Sierra Chart Engineering - Posts: 104368
You need to use this function:
sc.ClearAllPersistentData()

And can call it when this is true:
ACSIL Interface Members - Variables and Arrays: sc.IsFullRecalculation
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
[2019-01-09 07:31:32]
PeterSt - Posts: 36
You need to use this function:
sc.ClearAllPersistentData()

Oh yes, I saw that and understand its working (together with the other one). But can you give me a one liner about how/when this particular function is called then ? So there needs to be some kind of trigger or again other state we can check for ...
[2019-01-09 08:25:17]
Sierra Chart Engineering - Posts: 104368
You just need to use this code near the top of the study function but below the sc.SetDefaults code block:
if (sc.IsFullRecalculation && sc.Index==0)
sc.ClearAllPersistentData();

Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
Date Time Of Last Edit: 2019-01-09 08:25:35
[2019-01-09 15:06:38]
PeterSt - Posts: 36
I'm afraid we talk passed each other;
There is no IsFullRecalculation in order and there is no Index==0 in order when the DLL reloads. There is no change anywhere. When the DLL is reloaded this is not at all the same as when the study is unloaded (removed) and reloaded (added).

Please grasp that the DLL is reloaded by external means (see OP, UDP request), that the Study remains active (which is what we want) and that no trigger exists that I know of. Also not by implication like Index being 0 (the bars are not recalculated or anything).

The suggestion to call ClearAllPersistenceData does not work either because there it no trigger to call THAT.

Btw, because of your persistence on this, I tried your suggestion in order to not look foolish - just in case. But of course it does not do a thing.

And merely :

You just need to use this code near the top of the study function but below the sc.SetDefaults code block:

I don't think so because this is all about re-applying the sc.SetDefaults code itself. Not the code under that.

  bool Recompile = 0;   // Set to 1 when the SetDefaults are to be executed. Back to 0 for data processing.

  if (Recompile || sc.SetDefaults)     // 06-01-2019,PS, Recompile.

  {
    // Set the study configuration and defaults.

    sc.GraphName = "XX04Trading Example: Using Moving Average and Target and Stop";

    BuyEntrySubgraph.Name = "XX04Buy Entry";
    BuyEntrySubgraph.DrawStyle = DRAWSTYLE_ARROW_UP;
    BuyEntrySubgraph.PrimaryColor = RGB(64, 255, 0); // SUPPOSE I WANT TO CHANGE THE COLOR OF THIS !
    BuyEntrySubgraph.LineWidth = 3;
    BuyEntrySubgraph.DrawZeros = false;

    return;
  }

... Now cause the DLL to be loaded by means of UDP request with the notice I just changed my arrow color and like to see it changed ...
Date Time Of Last Edit: 2019-01-10 08:27:44
[2019-01-09 19:09:29]
Sierra Chart Engineering - Posts: 104368
Yes you are correct about this. We did not think through this fully. We were just thinking that there is a way to clear the persistent variables and gave the standard way to do that.

The quick solution is just to select Chart >> Recalculate after allowing the loading of the DLL to cause the persistent variables to clear when using the code that we gave above.

We will give this some more thought.
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
Date Time Of Last Edit: 2019-01-09 19:09:49
[2019-01-09 19:12:41]
Sierra Chart Engineering - Posts: 104368

The suggestion to call ClearAllPersistenceData does not work either because there it no trigger to call THAT.

We think the solution is to use an actual global variable, a variable defined at the top of the CPP file which will be in the global scope and initialize it to 0 and if it is 0, then clear the persistent data and set it to 1 to indicate that step is done.

The global variable should get set back to 0 when the DLL is unloaded and reloaded we would think. But that would have to be verified.
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
[2019-01-09 23:14:49]
Sierra Chart Engineering - Posts: 104368
Now you are going to need a separate global variable for each instance of a study where you want to reset the persistent variables, maybe you could use a map and you can uniquely identify each study as explained here:
ACSIL Programming Concepts: Uniquely Identifying an Instance of a Study
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
[2019-01-10 09:08:38]
PeterSt - Posts: 36
I love it when someone else comes up with a solution I could not think of myself. This is what works very well, assumed we are not to lousy to give the chart the focus and use Ctrl-Insert :

  // bool Recompile = 0;   // Set to 1 when the SetDefaults are to be executed. Back to 0 for data processing. 10-01-2019,PS, Deactivated.

  // if (Recompile || sc.SetDefaults) // 06-01-2019,PS, Recompile.
  // if ((sc.IsFullRecalculation && sc.Index==0) || sc.SetDefaults) // 10-01-2019,PS, Like this. Ctrl-Insert after Rebuild in VS.

  // 10-01-2019,PS, The above is formally not correct because the initialization code
  // will then execute twice. See log of the situation when the If above is active :

  //Chart: Base Graph | Study: Custom DLL Study | **RECALC** DEF | 2019-01-10 05:40:46 * *****************
  //EUR.USD-CASH-IDEALPRO 2 Sec #1 | Reloading chart. | 2019-01-10 05:40:46
  //Using Bid/Ask average for last trade price for EUR.USD-CASH-IDEALPRO | 2019-01-10 05:40:46
  //Interactive Brokers | Starting real-time market data updates for: EUR.USD-CASH-IDEALPRO. ID: 1 | 2019-01-10 05:40:46
  //Interactive Brokers | Subscribing to Symbol: EUR, SecurityType: CASH, Expiration: , Exchange: IDEALPRO, Primary Exchange:
  // , Currency: USD, Multiplier: , CallPut: , Strike: , LocalSymbol: , TradingClass: | 2019-01-10 05:40:46
  //Interactive Brokers | Requesting security definition data for: EUR.USD-CASH-IDEALPRO. ID: 1 | 2019-01-10 05:40:46
  //Intraday data recording state for symbol EUR.USD-CASH-IDEALPRO is set to download 'Pending'. | 2019-01-10 05:40:46
  //Delaying start of download for EUR.USD-CASH-IDEALPRO | 2019-01-10 05:40:46
  //Interactive Brokers | Market data type is Live for EUR.USD-CASH-IDEALPRO | 2019-01-10 05:40:47
  //Chart: EUR.USD-CASH-IDEALPRO 2 Sec #1 | Study:
  // XX04Trading Example: Using Moving Average and Target and Stop | **RECALC** BAR 0 | 2019-01-10 05:40:47 *

  if (sc.IsFullRecalculation && sc.Index==0 && !sc.SetDefaults) // 10-01-2019,PS, Like this being leaner. Ctrl-Insert after Rebuild in VS.
  {
    // Set the study configuration and defaults.

    if (sc.SetDefaults)
    {
      sc.AddMessageToLog("**RECALC** DEF", 1); // This one is called first.
    }
    else
    {
      sc.AddMessageToLog("**RECALC** BAR 0", 1);   // After that, this one is called.
    }

    sc.GraphName = "XX04Trading Example: Using Moving Average and Target and Stop";

    BuyEntrySubgraph.Name = "XX04Buy Entry";
    BuyEntrySubgraph.DrawStyle = DRAWSTYLE_ARROW_UP;
    BuyEntrySubgraph.PrimaryColor = RGB(64, 255, 0);
    BuyEntrySubgraph.LineWidth = 3;
    BuyEntrySubgraph.DrawZeros = false;

    return;
  }

What the above is all about, is this not-so-intuitive situation :

if ((sc.IsFullRecalculation && sc.Index==0) || sc.SetDefaults)

So we tend to do it like this, but this will trigger the execution of the Init code twice; one time because it is just explicitly done by Sierra (the general method of working) and one time at the build-up of the Chart which a. implies IsFullRecalculation to be true and b. will run through the first bar. Leaving out either IsFullRecalculation or Index==0 does not matter (but either could be omitted).
The crux is here that both IsFullRecalculation and SetDefaults will not be true at the same time and as the log shows (this log is from the Study loading), the SetDefaults is first. In my view it is harmless when each of these is not performed (but one has to), shown by the log data. This led to my decision to only execute the Init code on the IsFullRecalculation.
It is to be noted that the "&& !sc.SetDefaults" is required, because else again the Init code executes twice.

Without the "code of proof", it looks like this :

//if ((sc.IsFullRecalculation && sc.Index==0) || sc.SetDefaults) // 10-01-2019,PS, Like this. Ctrl-Insert after Rebuild in VS.
  if (sc.IsFullRecalculation && sc.Index==0 && !sc.SetDefaults) // 10-01-2019,PS, Like this being leaner. Ctrl-Insert after Rebuild in VS.
  {
    // Set the study configuration and defaults.

    sc.AddMessageToLog("**RECALC**", 0);

    sc.GraphName = "XX04Trading Example: Using Moving Average and Target and Stop";

    BuyEntrySubgraph.Name = "XX04Buy Entry";
    BuyEntrySubgraph.DrawStyle = DRAWSTYLE_ARROW_UP;
    BuyEntrySubgraph.PrimaryColor = RGB(64, 255, 0);
    BuyEntrySubgraph.LineWidth = 3;
    BuyEntrySubgraph.DrawZeros = false;

    return;

  }

The additional neat thing of this, is that on Ctrl-Ins immediately shows what the effect is on the changes in the Init code (because it happens instantly, contrary to a compile step or even explicit Remove and Add of the Study).

Thank you very much for your help !
Peter
[2019-01-10 09:22:31]
PeterSt - Posts: 36
Watch out please : This still is not right;
When I now go to the GUI to interactively change the Subgraph settings - the same which are defined in the Init code, then "obviously" (ahum) the Chart is recalculated because of this, and the preciously set Subgraph settings are readily undone by means of the Init code which does not match that.
Hmm ... must think further ...
[2019-01-10 09:25:29]
Sierra Chart Engineering - Posts: 104368
Okay we have offered all of the help we can and we cannot possibly spend the time looking over all of this. At this point we are leaving this discussion.
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
[2019-01-10 11:04:38]
PeterSt - Posts: 36
Okay we have offered all of the help we can

You certainly did, and I wasn't asking for more. Apologies for the confusion if you thought I was asking more of you.
Thanks.
Date Time Of Last Edit: 2019-01-10 11:08:12

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

Login

Login Page - Create Account