Click here to Skip to main content
15,894,003 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
StochRSI I have doubt does it working perfectly . My problem is .. with the same data .. portal (https://in.investing.com/charts/live-charts) stochrsi indicator .. value / graph is different than my data . My data points giving very quick over brought and very fast over sold region (with same time frame with same data ) . Please suggest .

The source code has been mentioned in - Solution 3

What I have tried:

C#
List<PriceCollectionWithId> NeedToProcessRsiAsc = NeedToProcessRsiDesc.OrderBy(o => o.AutoId).ToList();
                    PriceCollectionWithId lastVal = NeedToProcessRsiAsc.LastOrDefault();
stochRsi_last_val = 0;
                            double maxVal = NeedToProcessRsiAsc.Max(t => t.RsiValue);
                            double minVal = NeedToProcessRsiAsc.Min(t => t.RsiValue);
                            double lastRsi = lastVal.RsiValue;
                            stochRsi_last_val = ((lastRsi - minVal) / (maxVal - minVal));
                            stochRsi_last_val = Math.Round(stochRsi_last_val, 2, MidpointRounding.AwayFromZero);
Posted
Updated 29-Jul-19 6:13am
v4
Comments
Richard Deeming 16-Jul-19 13:28pm    
Reproduce the problem with a simplified set of sample data. Update your question to show that sample data, the expected output, and the actual output.

Without that information, we can't help.
biswa85 17-Jul-19 13:12pm    
Fine I try to create a sample .. Is their any nuget pack with provide financial algorithm ?

We can't help you - we don't have access to the rest of your code, the data you are testing with, or the results you expect.

So, it's going to be up to you.
Fortunately, you have a tool available to you which will help you find out what is going on: the debugger. If you don't know how to use it then a quick Google for "Visual Studio debugger" should give you the info you need.

Put a breakpoint on the first line in the function, and run your code through the debugger. Then look at your code, and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.

Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!
 
Share this answer
 
Quote:
I have doubt does it working perfectly . Please help .

Nobody but you can workout something with the piece of code in your question because you are the only one knowing the untold.

Your code do not behave the way you expect, or you don't understand why !

There is an almost universal solution: Run your code on debugger step by step, inspect variables.
The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't know what your code is supposed to do, it don't find bugs, it just help you to by showing you what is going on. When the code don't do what is expected, you are close to a bug.
To see what your code is doing: Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute.

Debugger - Wikipedia, the free encyclopedia[^]

Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
Basic Debugging with Visual Studio 2010 - YouTube[^]

Debugging C# Code in Visual Studio - YouTube[^]

The debugger is here to only show you what your code is doing and your task is to compare with what it should do.
 
Share this answer
 
Comments
biswa85 26-Jul-19 11:37am    
I have posted the code bellow .. please help if possible . Thank you .
My stochrsi code as follows .. Please help .

C#
private double CalculateStochRSI(List<PriceCollectionWithId> RSiColl, int RsiPeriod, int isHigherTimeFrame)
       {

           double stochRsi_last_val = 0;
           List<PriceCollectionWithId> RSiCollDesc = RSiColl.OrderByDescending(o => o.AutoId).ToList();
           List<PriceCollectionWithId> RSiCollDesc_HigherTimeframe = null;
           if (isHigherTimeFrame == 2)
           {
               RSiCollDesc_HigherTimeframe = RSiColl.FindAll(x => x.Rsi1 != -11).OrderByDescending(o => o.AutoId).ToList();
           }
           else
           {
               RSiCollDesc_HigherTimeframe = RSiCollDesc;
           }


           if (RSiColl.Count >= Convert.ToInt32(RsiPeriod + 5))
           {
               int MaxSlNo = RSiCollDesc_HigherTimeframe.Max(t => t.SlNo);
               List<PriceCollectionWithId> NeedToProcessRsiDesc = RSiCollDesc_HigherTimeframe.FindAll(x => x.SlNo >= (MaxSlNo - RsiPeriod) && x.SlNo <= MaxSlNo);
               List<PriceCollectionWithId> NeedToProcessRsiAsc = NeedToProcessRsiDesc.OrderBy(o => o.AutoId).ToList();
               PriceCollectionWithId lastVal = NeedToProcessRsiAsc.LastOrDefault();
               if (lastVal != null)
               {
                   if (isHigherTimeFrame == 1)
                   {
                       stochRsi_last_val = 0;
                       double maxVal = NeedToProcessRsiAsc.Max(t => t.RsiValue);
                       double minVal = NeedToProcessRsiAsc.Min(t => t.RsiValue);
                       double lastRsi = lastVal.RsiValue;
                       stochRsi_last_val = ((lastRsi - minVal) / (maxVal - minVal));
                       stochRsi_last_val = Math.Round(stochRsi_last_val, 2, MidpointRounding.AwayFromZero);
                   }
                   if (isHigherTimeFrame == 2)
                   {
                       stochRsi_last_val = 0;
                       double maxVal = NeedToProcessRsiAsc.Max(t => t.Rsi1);
                       double minVal = NeedToProcessRsiAsc.Min(t => t.Rsi1);
                       double lastRsi = lastVal.Rsi1;
                       stochRsi_last_val = ((lastRsi - minVal) / (maxVal - minVal));
                       stochRsi_last_val = Math.Round(stochRsi_last_val, 2, MidpointRounding.AwayFromZero);
                   }
               }
           }
           return stochRsi_last_val;
       }


Class Definition -
C#
public class PriceCollectionWithId
{
    public int AutoId { get; set; }
    public int SlNo { get; set; }
    public double RsiValue { get; set; }
    public double StochRsiValue { get; set; }
    public double OtherIndicatorValue { get; set; }



    public double Rsi1 { get; set; }
    public double Rsi2 { get; set; }
    public double StockRsi1 { get; set; }
    public double StockRsi2 { get; set; }
}
 
Share this answer
 
v2
Comments
Richard MacCutchan 26-Jul-19 11:40am    
1. This is not a Solution.
2. You have still not explained what your problem is.
Richard Deeming 26-Jul-19 11:44am    
If you want to update your question, click the green "Improve question" link and update your question.

DO NOT post the update as a solution. And DO NOT mark that fake solution as the answer to your question!

Your question is now showing as "solved".
Patrice T 26-Jul-19 12:14pm    
Use Improve question to update your question.
So that everyone can pay attention to this information.
biswa85 28-Jul-19 5:09am    
My problem is .. with the same data .. portal (https://in.investing.com/charts/live-charts) stochrsi indicator .. value / graph is different than my data . My data points giving very quick over brought and very fast over sold region (with same time frame with same data ) . Please suggest .

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900