Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Calculation Errors

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

    Calculation Errors

    I have noticed this many times before but just let it go but tried each time to understand why this is happening. I've had no success understanding so I am finally posting here in hopes that someone will tell me how stupid I'm being and provide a solution so I can move on.

    The situation is this. I have an EMA plotting on my chart. I can clearly see that it is rising over several bars by looking at my chart. I can look at the values of the same bars in the databox and see that price is in fact rising between those 3 bars I'm concerned with.

    I wrote an indicator that displays a graphic on the chart when certain conditions are met. On of the conditions is as follows:

    EMA(Typical,14)[1] < EMA(Typical,14)[2] &&
    Rising(EMA(Typical,14))

    So, the ema should be falling between bars 2 and 1 but rising between bars 1 and 0.

    It's that simple.

    Well the problem in this case is this. The ema on the chart and price in the databox show the EMA is clearly rising over the 3 bars but yet the code evaluates the EMA as falling between bars 2 and 1. I printed price for those bars and sure enough price shows that bar 2 to 1 is falling but again, the databox shows different prices for those bars and show price rising.

    How can this be explained so i can understand and fix this stupid problem...

    I hope I've explained this so it's understandable.

    Thanks,
    Mike

    #2
    May be putting in some Print() statements will help: http://www.ninjatrader-support.com/v...ead.php?t=3418

    Comment


      #3
      I did and they confirm exactly what I described. I just forgot to include that in my earlier post.

      Comment


        #4
        Are you sure that you have on your chart EMA and not SMA? Are you sure that the EMA is using Typical and not Close?

        If all is as expected, then the simple task would be to have your strategy at the top of OnBarUpdate() print out

        Print(Time[0].ToString() + " " + EMA(Typical, 14)[0]);

        Then correlate it to a chart with the same indicator and if you find something drastically different, let us know and provide us reference samples to check. Keep in mind, on a chart, the EMA for display purposes will be cut off based on ticksize in the y margin.
        RayNinjaTrader Customer Service

        Comment


          #5
          Thanks Ray...yes i'm sure I'm using EMA and not SMA and Typical versus Close. I checked again just to be sure. So, I started documenting the problem so I could present my case a bit better and a funny thing happened. I created a new indicator to send to you demonstrating the problem and can't reproduce the behavior. Very strange. It happens in my indicator quite frequently but haven't seen a case yet in my test indicator where that happens. Wish I could see why it's happening. Bottom line is that I just copy and pasted the code from my indicator to the new one and it works. So, I'm at a loss. I will continue the investigation and let you know what I find out if anything.

          Thanks,
          Mike

          Comment


            #6
            Holy Cow it was the Typical pricetype. I was using EMA(Typical,period) and it would still use Close. I tried changing Typical to Median and Open and those worked. Changed it back to Typical and it would only return Close. So, I created my own pricetype dataseries called myTypical and that works beautifully. I can't tell you how much grief this problem has caused me. This has been going on for months. I noticed many times when my Moving Averages would be rising or falling but would evaluate as being the opposite. Never could put my finger on the problem until just moments ago.

            Can this be caused by a corrupt database that i should just rebuild or could this be something else entirely.

            Thanks,
            Mike

            Comment


              #7
              Mike,

              Are you setting the price type when you are loading the indicator or are you hardcoding it in? I am having a hard time trying to reproduce your behavior right now. Any guidance would be appreciated. Or if you could provide me with a simple-as-possible indicator that can reproduce your scenario. Thanks.

              Please try my attached indicator. Throw it onto a chart. You will notice that Typical is fairly close to Close, but there are clear discrepancies since the lines do not completely overlap each other.
              Attached Files
              Last edited by NinjaTrader_JoshP; 05-10-2008, 04:45 AM.
              Josh P.NinjaTrader Customer Service

              Comment


                #8
                Josh,

                I use it just the way I described in an earlier post. I put the following in my code exactly as it is here...

                EMA(Typical,14)[1] < EMA(Typical,14)[2] &&
                Rising(EMA(Typical,14))

                I wish I could give you more. I've been working for several hours now in an attempt to create something you can look at that has the same problem but I can't. In fact, I put this same indicator new chart and don't have the same results. Using the chart that I noticed the problem on, I can toggle between using the standard Typical pricetype and my custom myTypical. Using the nt Typical I get erroneous results. Using myTypical I get correct results. I created a new chart and did the same thing but both myTypical and nt Typical and they both give correct results. I'm mystified. Don't know if you think it's something you want to pursue but I'd be willing to work with you on it over the phone. I don't want to post my phone number here but let me know if you want to do that. I assume you have access to my email address.

                Mike

                Comment


                  #9
                  Mike,

                  I don't have access to your email, but if you want you can email me at josh at ninjatrader. com. I can assist in this matter if you ever find a consistently reproducible scenario. In the meantime why don't we put this on the backburner and leave it as an open case till more information crops up.
                  Josh P.NinjaTrader Customer Service

                  Comment


                    #10
                    Thanks Josh.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by geotrades1, Today, 07:54 AM
                    5 responses
                    9 views
                    0 likes
                    Last Post geotrades1  
                    Started by Aviram Y, Today, 06:03 AM
                    1 response
                    7 views
                    0 likes
                    Last Post NinjaTrader_ChelseaB  
                    Started by leonardomocci, Today, 08:28 AM
                    0 responses
                    1 view
                    0 likes
                    Last Post leonardomocci  
                    Started by prisonbreaker82, 02-24-2024, 11:16 AM
                    3 responses
                    36 views
                    0 likes
                    Last Post NinjaTrader_BrandonH  
                    Started by bill2023, Today, 08:21 AM
                    0 responses
                    3 views
                    0 likes
                    Last Post bill2023  
                    Working...
                    X