Support Board
Date/Time: Wed, 30 Apr 2025 11:44:45 +0000
Post From: Can sc.VolumeAtPriceMultiplier be used with multiple study instances?
[2025-04-22 23:20:09] |
drinkcodejava - Posts: 29 |
Definitely something strange going on. I wrote up a simplified version of your study and was able to reproduce the behavior, but what's even more weird is that if you manually change VolumeAtPriceMultiplier (V@PM) manually via Chart Settings >> Chart Data >> Volume At Price to a non-study input value and then try to click a button for any instance other than the last one, the V@PM value doesn't change at all. For example, in the log output you provided, you have Study IDs 19, 20 and 21 with input values of 2, 4 and 8, respectively. For this example, assume that the studies are listed in that calculation order as well. If you enter '12' in the Chart Settings window and then click the button 1 or 2 (i.e. any instance other than the last one), even though the button event and V@PM are output to log, you will see that the value in the Chart Settings window after the chart is reloaded is still 12, not 8 (at least that's how it was when I did it). In other words, the manually entered value only gets changed when the button for the last instance is clicked. If button 1 or 2 is clicked, the value doesn't change from 12 to 2, then to 4, then to 8 as you might think. It actually doesn't change at all. I also wrote up a super simple study (Only Message Log, below) which only outputs the value of V@PM to the message log, and then added two instances into the study list; one near the top above the V@PM studies and one at the bottom. When I did this and clicked the button for the last V@PM instance, the result was the value did not get changed. It's as if even just accessing V@PM in order to write it to output prevents it from getting changed. If I move the second Only Message Log just above the last V@PM instance, the button for the last instance starts working again. I think what you might need to do is in your Preset Loader study, store the desired V@PM value to spreadsheet/file, then develop a separate custom study that reads in and sets the V@PM value, making sure that it is the last in the study list to read/write to sc.VolumeAtPriceMultiplier. SCDLLName("Only Message Log")
SCSFExport scsf_OnlyMsgLog(SCStudyInterfaceRef sc) { SCInputRef i_Input01 = sc.Input[0]; // Section 1 - Set the configuration variables and defaults if (sc.SetDefaults) { sc.GraphName = "Only Message Log"; // sc.StudyDescription = "This is a description that will be displayed on the help page for the study"; sc.AutoLoop = 1; // 1 = Automatic looping is enabled i_Input01.Name = "ID Number"; i_Input01.SetInt(1); return; } // Section 2 - Do data processing here SCString msg; int ID = i_Input01.GetInt(); if (sc.IsFullRecalculation && sc.Index==sc.ArraySize-1) { msg.Format("ID: %d. Current sc.VolumeAtPriceMultiplier value: %d", ID, sc.VolumeAtPriceMultiplier); sc.AddMessageToLog(msg,0); } } |