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

Plotting histogram

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

    Plotting histogram

    I'm trying to plot a simple histogram, the difference of two moving averages.

    Diff.Set(MA2[0] - MA3[0]);

    if (Diff[0] > Diff[1] ) {
    BullBar.Set(Diff[0]);
    }
    else if (Diff[0] < Diff[1]){
    BearBar.Set(Diff[0]);
    }

    I need some help figuring out why I'm getting these problems (see attachment):
    * Green & Red bars are plotted together
    * Declining Red Bars and Rising Green Bars are not plotted consistently
    * Once I refresh the chart, all these issues are gone until it reappears with new plots

    Thanks in advance.
    Attached Files

    #2
    Hello 2Look4me,

    Thank you for your post.

    Try setting the opposite plot to zero:
    Code:
    Diff.Set(MA2[0] - MA3[0]);
    
    if (Diff[0] > Diff[1] ) {
    BullBar.Set(Diff[0]);
    BearBar.Set(0);
    } 
    else if (Diff[0] < Diff[1]){
    BullBar.Set(0);
    BearBar.Set(Diff[0]);
    }

    Comment


      #3
      Thanks Patrick, I worked on that for hours, but it didn't cross my mind.

      Comment


        #4
        You just need a single plot and no additional DataSeries.

        Code:
        private Color upColor = Color.Lime;
        private Color downColor = Color.Red;
        Diff.Set(MA2[0] - MA3[0]);
        if(Diff[0] > Diff[1])
           PlotColors[0][0] = upColor;
        else if (Diff[0] < DIff[1])
           PlotColors[0][0] = downColor;
        else
           PlotColors[0][0] = PlotColors[0][1];

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by gentlebenthebear, Today, 01:30 AM
        0 responses
        2 views
        0 likes
        Last Post gentlebenthebear  
        Started by samish18, Yesterday, 08:31 AM
        2 responses
        9 views
        0 likes
        Last Post elirion
        by elirion
         
        Started by Mestor, 03-10-2023, 01:50 AM
        16 responses
        389 views
        0 likes
        Last Post z.franck  
        Started by rtwave, 04-12-2024, 09:30 AM
        4 responses
        31 views
        0 likes
        Last Post rtwave
        by rtwave
         
        Started by yertle, Yesterday, 08:38 AM
        7 responses
        29 views
        0 likes
        Last Post yertle
        by yertle
         
        Working...
        X