• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Explanation of different results please

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Explanation of different results please

    I opened up an old indicator I had previously programmed to make some changes. This was one of the first I had done in NinjaScript, and at the time I had a habit of doing all my calculations, storing the result into a double, and then using Set to store the double into a DataSeries.

    Like this for example....

    Code:
    phaseTemp = atanRadians*(180/Math.PI);
                    Phase.Set(phaseTemp);
    Later, I came to believe that this step was redundant, and have since been skipping the store in double first step, like this...

    Code:
    Value.Set(((Math.Min(CurrentBar + 1, Period) - 1 ) * Value[1] + trueRange) / Math.Min(CurrentBar + 1, Period));
    The above is from the default ATR code...

    So today, I had was working on my old indicator where I did my calculations outside the Set method, stored the result in a double, and then stored the double into the DataSeries with the Set method.... here's the code section...

    Code:
    if (Math.Abs(InPhase[0] + InPhase[1]) > 0)
                {
                    
                    tangent = Math.Abs((Quadrature[0]+Quadrature[1])/(InPhase[0]+InPhase[1]));
                    atanRadians = Math.Atan(tangent);
                    phaseTemp = atanRadians*(180/Math.PI);
                    Phase.Set(phaseTemp);
                }
    This version of the code plotted like this....




    Which I am really happy with, because it exactly matches the chart Published in Ehlers' article below:



    But thinking that it was a redundant step to first store the calculation result in a double, I refactored the code to this....

    if (Math.Abs(InPhase[0] + InPhase[1]) > 0)
    {

    tangent = Math.Abs((Quadrature[0]+Quadrature[1])/(InPhase[0]+InPhase[1]));
    atanRadians = Math.Atan(tangent);

    Phase.Set(atanRadians*(180/Math.PI));
    }

    To my shock this code plots very differently... the result is way off...



    The max reading is much higher than before... especially in a percentage basis, as this indicator can only range between 6 and 50.... At Max reading on this chart, its a difference of 15.83 points...

    Moving the atanRadians*(180/Math.PI) line inside the Set parens is the only change needed to make such a drastic change.

    So now I am wondering why?

    I know an easy answer would be, so don't do it like that then.... but I want to know why its doing it, because we often see calculations done inside the Set method line....
    Last edited by Crassius; 03-21-2013, 09:25 AM.

    #2
    Hello Crassius,

    I have ran a few tests and I am not getting different values so far. Is it possible that the data has changed, can you remove the indicator create two different charts and add the indicator on each one with the different methods of plotting?
    JCNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_JC View Post
      Hello Crassius,

      I have ran a few tests and I am not getting different values so far. Is it possible that the data has changed, can you remove the indicator create two different charts and add the indicator on each one with the different methods of plotting?

      Here it is on MSFT loaded 1/3/2011 to 3/15/2013 on two different charts....

      I have attached my indicator... Look around line 100... Its easy to comment out a line or two and get both results...

      You should have the MSFT data... I got it from Kinetick EOD... I suggest you load the entire date range... to match what I have done on my end...
      Attached Files
      Last edited by Crassius; 03-21-2013, 08:05 PM.

      Comment


        #4
        Originally posted by Crassius View Post
        Here it is on MSFT loaded 1/3/2011 to 3/15/2013 on two different charts....

        I have attached my indicator... Look around line 100... Its easy to comment out a line or two and get both results...

        You should have the MSFT data... I got it from Kinetick EOD... I suggest you load the entire date range... to match what I have done on my end...
        While your results do look like a substantial difference, let us first check that we are not seeing a rounding error on small values.

        How about you change to this, so that we can see the full values in the Output Window:
        Code:
        if (Math.Abs(InPhase[0] + InPhase[1]) > 0)
        {
        tangent = Math.Abs((Quadrature[0]+Quadrature[1])/(InPhase[0]+InPhase[1]));
        atanRadians = Math.Atan(tangent);
        phaseTemp = atanRadians*(180/Math.PI);
        Print(" phaseTemp: " + phaseTemp);
        Phase.Set(atanRadians*(180/Math.PI));
        Print("DataSeries value: " + Phase[0]);
        }

        Comment


          #5
          Originally posted by koganam View Post
          While your results do look like a substantial difference, let us first check that we are not seeing a rounding error on small values.

          How about you change to this, so that we can see the full values in the Output Window:

          I am such an idiot !

          Playing around with that for few minutes, and likely because I stepped away from debugging for a few hours, led me to the realization that one way I could be getting the results I was experiencing would be if I used phaseTemp later in the code...

          and I did... of course... a few lines later I have....

          Code:
          //Resolve ArcTangent Ambiquity
                      if (InPhase[0] < 0 && Quadrature[0] > 0)
                      {
                          Phase.Set(180 - phaseTemp);
                      }
          Thanks for the help... sorry....

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by memonolog, Today, 02:39 AM
          1 response
          17 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by memonolog, Today, 07:07 AM
          0 responses
          4 views
          0 likes
          Last Post memonolog  
          Started by juanram, Today, 06:01 AM
          1 response
          9 views
          0 likes
          Last Post NinjaTrader_PaulH  
          Started by dastaan, Today, 06:29 AM
          0 responses
          6 views
          0 likes
          Last Post dastaan
          by dastaan
           
          Started by random9570, Yesterday, 09:01 PM
          2 responses
          19 views
          0 likes
          Last Post Emma1
          by Emma1
           
          Working...
          X