I can fetch closing price data just fine, but I can't seem to get it to work when I try to fetch closing price data in a sub-routine function.
var series = ctx.getDataSeries();
Object input = getSettings().getInput(Inputs.INPUT); //close data
Double v1 = series.getDouble(index, input); //this works fine
I call the function:
Double thrust1 = iWTT_CSI_processor(1, index, ctx);
Can I pass the v1 values of closing price data to the below fundtion? If so, how do I call that data in the function to retrieve it?
public static double iWTT_CSI_processor(int CycleCount, int index, DataContext ctx)
{
int cycs = 50;
for (int i = 0; i <= cycs - 1; i++)
{
var series = ctx.getDataSeries();
Double past_data_val = series.getDouble(index - 49 + i, "close"); //I need the closing price data from (49 + 1) days ago
//do other steps here
//I don't seem to get any data for the past_data_val variable.
}
Can someone please help me?
2nd question: in order to test the above, I could use a random number for past_data_val - if I could generate a random number. Can this be done?
Thank you.
UPDATE: I managed to find success, for a couple of reasons.
1) I found a very old forum message which talked about the Study Log (View - Display - Study Log) and how you can use it to trace values of variables, like this:
debug ("Value past_data_val_1 = " + past_data_val_1 + " Value swing = " + swing + " Value i = " + i + " Value index = " + index);
2) Somehow I found an important piece of information which I was not aware of. The modified code which now works is this:
Object key=getSettings().getInput(input, Enums.BarInput.CLOSE); //this is what I was missing
DataSeries series1 = ctx.getDataSeries();
past_data_val_1 = series1.getDouble(index - 49 + i, key, -128.0); //the "key" statement is also what I was missing
So, after hours and hours of hacking around, I finally got to the finish line.
var series = ctx.getDataSeries();
Object input = getSettings().getInput(Inputs.INPUT); //close data
Double v1 = series.getDouble(index, input); //this works fine
I call the function:
Double thrust1 = iWTT_CSI_processor(1, index, ctx);
Can I pass the v1 values of closing price data to the below fundtion? If so, how do I call that data in the function to retrieve it?
public static double iWTT_CSI_processor(int CycleCount, int index, DataContext ctx)
{
int cycs = 50;
for (int i = 0; i <= cycs - 1; i++)
{
var series = ctx.getDataSeries();
Double past_data_val = series.getDouble(index - 49 + i, "close"); //I need the closing price data from (49 + 1) days ago
//do other steps here
//I don't seem to get any data for the past_data_val variable.
}
Can someone please help me?
2nd question: in order to test the above, I could use a random number for past_data_val - if I could generate a random number. Can this be done?
Thank you.
UPDATE: I managed to find success, for a couple of reasons.
1) I found a very old forum message which talked about the Study Log (View - Display - Study Log) and how you can use it to trace values of variables, like this:
debug ("Value past_data_val_1 = " + past_data_val_1 + " Value swing = " + swing + " Value i = " + i + " Value index = " + index);
2) Somehow I found an important piece of information which I was not aware of. The modified code which now works is this:
Object key=getSettings().getInput(input, Enums.BarInput.CLOSE); //this is what I was missing
DataSeries series1 = ctx.getDataSeries();
past_data_val_1 = series1.getDouble(index - 49 + i, key, -128.0); //the "key" statement is also what I was missing
So, after hours and hours of hacking around, I finally got to the finish line.
Last edited: