Login Page - Create Account

Support Board


Date/Time: Mon, 21 Apr 2025 13:08:40 +0000



[Programming Help] - Can sc.VolumeAtPriceMultiplier be used with multiple study instances?

View Count: 123

[2025-04-14 16:50:50]
User2069 - Posts: 24
I'm trying to write a study that works kind of like a Preset Loader for my chart settings. I want to use multiple instances of the study for all the different configurations and bar periods that i use and i'm assigning each one to an ACS button. This is where i keep running into an issue with sc.VolumeAtPriceMultiplier. Only the value from the last instance of the study that was added gets updated in the chart, even though it is showing in the log like it is reading and assigning the right value from the one i actually click on. I've tried all sorts of checks and even forcing the chart to recalculate right after assigning the input into sc.VolumeAtPriceMultiplier and nothing seems to be working. Is this possible at all?
[2025-04-18 01:22:39]
drinkcodejava - Posts: 28
Not totally clear on what you are trying to do or how you are doing it.

Your custom study sets sc.VolumeAtPriceMultiplier based on a ACS control bar button on/off state?
And the value you are trying to set for sc.VolumeAtPriceMultiplier is study input?

Can you post some code?

If you are setting sc.VolumeAtPriceMultiplier in each study instance, and you have multiple study instances running on one chart, then you need to have some way of only having one instance set the value you want and prevent the other instances from changing it. Sounds like the value you want is being assigned correctly, but it might be getting changed after that.
[2025-04-18 07:46:15]
Sierra_Chart Engineering - Posts: 19285
Not sure what the problem is using sc.VolumeAtPriceMultiplier.

However, flag to reload the chart:
ACSIL Interface Members - Variables and Arrays: sc.FlagToReloadChartData

This should not be necessary but maybe that is the problem that the chart is not getting reloaded. It has to be reloaded after changing that variable. But it will happen automatically.
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, use the Teton service:
Sierra Chart Teton Futures Order Routing
[2025-04-18 14:48:35]
User2069 - Posts: 24
I apologize, i guess i should have provided more info.

Yes, I'm checking which ACS button is pressed using sc.MenuEventID and then assigning all the values, including sc.VolumeAtPriceMultiplier, when ACS Button On Event is true.
I'm getting the values from study input and assigning them to variables.

The issue with sc.VolumeAtPriceMultiplier is happening when adding more than one instance of the study to the chart. Only the value from the last instance of the study that was added actually gets updated,
even though it is showing the correct values in the log.
I think the problem is that sc.VolumeAtPriceMultiplier is getting changed as @drinkcodejava mentioned after the chart finishes reloading , but i'm not sure how or why.

The chart was always reloading automatically like it should, i tried forcing it to recalculate more so as troubleshooting to see if it would help, but it didn't unfortunately.
I also just gave FlagToReloadChartData a try but it was the same.

Here is the main function of the code:

if (sc.MenuEventID == SelectedIndex)
    {
      MessageText.AppendFormat("Got button event id %i, ", sc.MenuEventID);

      if (sc.PointerEventType == SC_ACS_BUTTON_ON)
      {
        MessageText.Append("ACS Button On Event, ");        

        switch(SelectedPeriod)
        {
        case 0:  
          NewBarPeriod.IntradayChartBarPeriodType = IBPT_DAYS_MINS_SECS;
          break;
        case 1:
          NewBarPeriod.IntradayChartBarPeriodType = IBPT_VOLUME_PER_BAR;
          break;
        case 2:
          NewBarPeriod.IntradayChartBarPeriodType = IBPT_NUM_TRADES_PER_BAR;
          break;
        case 3:
          NewBarPeriod.IntradayChartBarPeriodType = IBPT_RANGE_IN_TICKS_STANDARD;  
        }
            
        if(NewBarPeriod.IntradayChartBarPeriodType == IBPT_DAYS_MINS_SECS)
          NewBarPeriod.IntradayChartBarPeriodParameter1 = ChartPeriod * 60;
        else if (NewBarPeriod.IntradayChartBarPeriodType == IBPT_RANGE_IN_TICKS_STANDARD)
          NewBarPeriod.IntradayChartBarPeriodParameter1 = ChartPeriod * 4;
        else
        //sc.GetBarPeriodParameters(NewBarPeriod);                      
        NewBarPeriod.IntradayChartBarPeriodParameter1 = ChartPeriod;
        
            
        //Set the bar period parameters. This will go into effect after the study function returns.
        sc.SetBarPeriodParameters(NewBarPeriod);
        
        
        sc.BaseGraphScaleConstRange = ScaleRange;
        sc.ConstantRangeScaleModeTicksFromCenterOrEdge = TFC;
        sc.BaseGraphScaleIncrement = ScaleIncrement;
        sc.BaseGraphHorizontalGridLineIncrement = GridLineIncrement;
        sc.VolumeAtPriceMultiplier = VolumeAtPriceMultiplier;
        
        // Force the chart to recalculate
        //sc.RecalculateChart(sc.ChartNumber);
        sc.FlagToReloadChartData = 1;
        
        MessageText.AppendFormat("VolumeAtPriceMultiplier %i, StudyID %i, ", sc.VolumeAtPriceMultiplier, StudyGraphInstanceID);
        sc.AddMessageToLog(MessageText, 1);
                

        // reset button 1 to off
        if (sc.MenuEventID == SelectedIndex)
          sc.SetCustomStudyControlBarButtonEnable(SelectedIndex, 0);
      }
      else if (sc.PointerEventType == SC_ACS_BUTTON_OFF)
        MessageText.Append("ACS Button Off Event, ");

      sc.SetCustomStudyControlBarButtonEnable(sc.PriorSelectedCustomStudyControlBarButtonNumber, 0);

    }

[2025-04-18 17:18:55]
drinkcodejava - Posts: 28
And what is your message log output?

You are using a different ACS button ID for each instance, correct? Either as a study input or hardcoded? If they are all monitoring the same sc.MenuEventID, then they are all going to set the value on a calculation, and you will just end up with the value set by the last instance in the study list.
[2025-04-18 18:25:37]
User2069 - Posts: 24
Yes, i'm assigning each instance it's own ACS Button and the corresponding ID through the study input.
I've also been checking sc.MenuEventID in the log, as well as the StudyID to make sure it wasn't only applying the values from the last one.

Here's the log output after testing with 3 instances of the study:

2025-04-18 14:09:01.734 | Chart: MNQM5.CME [CV][M] 5 Min #2 | Study: Set Chart | Got button event id 1, ACS Button On Event, VolumeAtPriceMultiplier 2, StudyID 19,
2025-04-18 14:09:01.734 | Chart: MNQM5.CME [CV][M] 5 Min #2 | Study: Set Chart | Got button event id 1, ACS Button On Event, VolumeAtPriceMultiplier 2, StudyID 19,
2025-04-18 14:09:01.762 | MNQM5.CME [CV][M] 12.00 Range #2 | Reloading chart.
2025-04-18 14:09:02.060 | MNQM5.CME [CV][M] 12.00 Range #2 | StartDateTimeForLoadingOrderFills: 2024-04-10 00:00:00
2025-04-18 14:09:02.076 | MNQM5.CME [CV][M] 12.00 Range #2 | Chart data loading complete.
2025-04-18 14:09:14.489 | Chart: MNQM5.CME [CV][M] 12.00 Range #2 | Study: Set Chart | Got button event id 2, ACS Button On Event, VolumeAtPriceMultiplier 4, StudyID 20,
2025-04-18 14:09:14.489 | Chart: MNQM5.CME [CV][M] 12.00 Range #2 | Study: Set Chart | Got button event id 2, ACS Button On Event, VolumeAtPriceMultiplier 4, StudyID 20,
2025-04-18 14:09:14.510 | MNQM5.CME [CV][M] 24.00 Range #2 | Reloading chart.
2025-04-18 14:09:14.808 | MNQM5.CME [CV][M] 24.00 Range #2 | StartDateTimeForLoadingOrderFills: 2024-04-10 00:00:00
2025-04-18 14:09:14.821 | MNQM5.CME [CV][M] 24.00 Range #2 | Chart data loading complete.
2025-04-18 14:09:17.146 | Chart: MNQM5.CME [CV][M] 24.00 Range #2 | Study: Set Chart | Got button event id 3, ACS Button On Event, VolumeAtPriceMultiplier 8, StudyID 21,
2025-04-18 14:09:17.146 | Chart: MNQM5.CME [CV][M] 24.00 Range #2 | Study: Set Chart | Got button event id 3, ACS Button On Event, VolumeAtPriceMultiplier 8, StudyID 21,
2025-04-18 14:09:17.193 | MNQM5.CME [CV][M] 5 Min #2 | Reloading chart.
2025-04-18 14:09:17.439 | MNQM5.CME [CV][M] 5 Min #2 | StartDateTimeForLoadingOrderFills: 2024-04-10 00:00:00
2025-04-18 14:09:17.450 | MNQM5.CME [CV][M] 5 Min #2 | Chart data loading complete.

Here you can see that VolumeAtPriceMultiplier is displaying the correct values for each one, but it actually remained at 8 the entire time, which was the value set on the last instance of the study.
Date Time Of Last Edit: 2025-04-18 18:37:17

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

Login

Login Page - Create Account