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 funk10101, Today, 12:02 AM
        1 response
        10 views
        0 likes
        Last Post NinjaTrader_LuisH  
        Started by GLFX005, Today, 03:23 AM
        1 response
        6 views
        0 likes
        Last Post NinjaTrader_Erick  
        Started by nandhumca, Yesterday, 03:41 PM
        1 response
        13 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by The_Sec, Yesterday, 03:37 PM
        1 response
        11 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by vecnopus, Today, 06:15 AM
        0 responses
        1 view
        0 likes
        Last Post vecnopus  
        Working...
        X