Announcement

Collapse
No announcement yet.

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 CarlTrading, 03-31-2026, 09:41 PM
        1 response
        83 views
        1 like
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        45 views
        0 likes
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        65 views
        2 likes
        Last Post CaptainJack  
        Started by CarlTrading, 03-30-2026, 11:51 AM
        0 responses
        68 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 03-30-2026, 11:48 AM
        0 responses
        56 views
        0 likes
        Last Post CarlTrading  
        Working...
        X