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

Moving averages not plotting correctly when crossed

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

    Moving averages not plotting correctly when crossed

    I have a question, as I have seen this repeatedly... perhaps I am doing something wrong. I have coded a very simple MA crossover, where I want to show 2 plots on the screen... a long MA, and a short MA that changes color whenever it crosses the longer one.

    I initialize 3 plots like this:

    Add(new Plot(Color.FromKnownColor(KnownColor.Yellow), PlotStyle.Line, "LongMA"));
    Add(new Plot(Color.FromKnownColor(KnownColor.Lime), PlotStyle.Line, "ShortMAUp"));
    Add(new Plot(Color.FromKnownColor(KnownColor.Red), PlotStyle.Line, "ShortMADown"));


    Then I have the following code in OnBarUpdate():

    if (EMA(shortMAPeriod)[0] >= EMA(longMAPeriod)[0])
    ShortMAUp.Set(EMA(shortMAPeriod)[0]);
    else
    ShortMADown.Set(EMA(shortMAPeriod)[0]);

    Whenever I plot this, it works fine except that for a few pixels right around the crossover point, nothing is plotted (i.e. I just get blank space).

    This also happens on osciallator plots where I am checking the slope and wanting to plot a different color depending on whether it is going up/down... whenever the slope changes to be near zero, the same effect occurs where nothing is plotted.

    Am I missing something or is this a bug?

    #2
    Not sure what you are referring to exactly. Could you please post a screenshot? Thanks.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Josh View Post
      Not sure what you are referring to exactly. Could you please post a screenshot? Thanks.
      Sure, here it is... I have circled the problem areas....
      Attached Files

      Comment


        #4
        Another example...
        Attached Files

        Comment


          #5
          JS999,

          Please see this reference sample for how to connect the different plots together. http://www.ninjatrader-support2.com/...ead.php?t=3227
          Josh P.NinjaTrader Customer Service

          Comment


            #6
            Originally posted by NinjaTrader_Josh View Post
            JS999,

            Please see this reference sample for how to connect the different plots together. http://www.ninjatrader-support2.com/...ead.php?t=3227
            Which reference sample? Did you forget to paste something? Never mind... I see it now.

            Comment


              #7
              That sort of worked, but not completely... I added a line to connect the averages as follows:

              ShortMAUp.Set(1,EMA(shortMAPeriod)[1]);
              ShortMAUp.Set(EMA(shortMAPeriod)[0]);

              and

              ShortMADown.Set(1,EMA(shortMAPeriod)[1]);
              ShortMADown.Set(EMA(shortMAPeriod)[0]);

              Yet while it doesn't show the empty space, now sometimes it plots the wrong color just on the other side of the long MA. I have attached an example. Any ideas?
              Attached Files

              Comment


                #8
                Not sure what you mean. The screenshot looks to be continuous to me. When using multi-colored plots it is possible to have it colored on the other end because it needs to connect the data points. Sometimes the color change criteria didn't happen on one of the points exactly and that can lead to coloring of that may appear to be off since it needs to color the whole segment.
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_Josh View Post
                  Not sure what you mean. The screenshot looks to be continuous to me. When using multi-colored plots it is possible to have it colored on the other end because it needs to connect the data points. Sometimes the color change criteria didn't happen on one of the points exactly and that can lead to coloring of that may appear to be off since it needs to color the whole segment.
                  Alright... but you can see how that could be a bit annoying... is this something that could be changed in version 7 so that the colors exactly match up visually with the crossover point? Just a suggestion... thanks for the help...

                  Comment


                    #10
                    Thank you for the suggestion. It is on our list of future considerations.
                    Josh P.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by DavidHP, Today, 07:56 AM
                    1 response
                    5 views
                    0 likes
                    Last Post NinjaTrader_Erick  
                    Started by kujista, Today, 06:23 AM
                    3 responses
                    9 views
                    0 likes
                    Last Post kujista
                    by kujista
                     
                    Started by Mindset, Yesterday, 02:04 AM
                    2 responses
                    18 views
                    0 likes
                    Last Post NinjaTrader_RyanS  
                    Started by f.saeidi, Today, 08:03 AM
                    1 response
                    5 views
                    0 likes
                    Last Post NinjaTrader_Jesse  
                    Started by samish18, 04-17-2024, 08:57 AM
                    15 responses
                    54 views
                    0 likes
                    Last Post NinjaTrader_BrandonH  
                    Working...
                    X