Hi, I have been trying to create a simple indicator that takes the amount of time in a period before the latest low and a high and charts it. Basically it is ((period - bars since high/low)/period)*100. I am having trouble getting it to plot, it just shows up as flat line at 0. I also tried to print the values but I get nothing.
I've included the code below but I also have a question about DataSeries. Do I need to create a DataSeries for the indicator values to be stored in? and if not what types of indicators do you use it for? And lastly I am determining which bar out of the period contains the high or low through a for loop. Is there a better method to finding those bar index's? Cheers and thanks in advance.
// Wizard generated variables
private int numPeriod = 1; // Default setting for NumPeriod
// User defined variables (add any user defined variables below)
private double outputHigh;
private double outputLow;
private int highIndex;
private int lowIndex;
private double highest;
private double lowest;
protected override void OnBarUpdate()
{
// Use this method for calculating your indicator values. Assign a value to each
// plot below by replacing 'Close[0]' with your own formula.
if (CurrentBar<numPeriod)
{
return;
}
else
{
// first needs to find how many bars since high and low and store them in their respective variables.
//Could do a for loop to determine index position of high and low
//Assumes current bar has high/low
highest=CurrentDayOHL().CurrentHigh[0];
lowest=CurrentDayOHL().CurrentLow[0];
for (int i=1; i<numPeriod; i++)
{
if (Bars.GetDayBar(i).High > highest)
{
highest=Bars.GetDayBar(i).High;
highIndex=i;
}
if (Bars.GetDayBar(i).Low<lowest)
{
lowest=Bars.GetDayBar(i).Low;
lowIndex=i;
}
}
//store in respective output variables
outputHigh=((numPeriod-highIndex)/numPeriod)*100;
outputLow=((numPeriod-lowIndex)/numPeriod)*100;