#### ConnorsRSI indicator development

Posted By vitaly 8 Months Ago

## ConnorsRSI indicator development

 Message Posted Tuesday March 28 2017 Hello there.Attempting to program ConnorsRSI indicator I've been stuck for a while trying to figure out RE differences in behavior when initializing indicator in code and drag-and-dropping it onto the chart. ConnorsRSI consists of three components. RSI calculation on price and streak duration works fine (especially if you copy and paste the code provided by RE team). The last component defines percentage of times within last N bars when close-to-close change was lower than the last close-to-close change in a series. In code it looks simpler than it sounds:protected override double CalcNewValue(int index)  {   // at least two price points are needed to calculate the difference   if (inputs[0].Count < 2)   {    returns.Add(double.NaN);    return double.NaN;   }   double change = Math.Log(inputs[0].LookBack(index) / inputs[0].LookBack(index + 1));   returns.Add(change);   // if not enough bars   if (inputs[0].Count < periods + 1)   {           return double.NaN;   }   double lastDayReturn = returns[returns.Count - 1];   // take the last N items of a collection (N is represented by periods)   List lastNreturns = returns.Skip(Math.Max(0, returns.Count - periods)).ToList();   // total number of occurances during last N bars when close-to-close price change was lower   // than the last day's close-to-close return    int numOfReturnsLessThanLast = lastNreturns.Count(x => x < lastDayReturn);   // percent of such closes within last N bars   double ratio = 100.0 * (double)numOfReturnsLessThanLast / (double)periods;   return ratio;  }Initializing this component in code (plugin from dll library) as a standalone indicator works fine.However, when trying to put it on a chart by drag-and-drop, the following message appears:A sample data for \$SPX index is attached. It has 100 records. Since the error message is pointing at RightEdge.Common.RList.LookBack, I assume that this line of code is the source of trouble:double change = Math.Log(inputs[0].LookBack(index) / inputs[0].LookBack(index + 1));When initialized in code, stepping through the debugger shows that index parameter passed to CalcNewValue method is always 0. This seems not to be the case when drag-and-dropping, and index has different values, which results in error on inputs[0].LookBack(100).I would appreciate If anyone could enlighten me on this topic. A link to my Dropbox: Files List of files:1. \$SPX sample data2. .cs file with code3. compiled dll with the indicator4. a .rep file with in code initializationBest regards,Vitaly Posted Monday April 03 2017 Doesn't look like there is much activity on the forum. I didn't figure out the exception RE is throwing for drag-and-drop scenario, but it since it more common creating it in code I proceeded with programming it anyway. Now it can be added to the project as an existing item (class) and instantiated like any other indicator (using constructor with 4 parameters). Since I'm neither an expert in programming nor in statistics, it would be great if someone could take a look for possible bugs/misconceptions in my implementation. The file is attached.Regards,Vitaly Attachments ConnorsRSI.cs (70 views, 12.00 KB)