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

Falling() 1 bar out

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

    Falling() 1 bar out

    Hi,

    I'm programming a custom MACD with the Avg plotted as a colored line and the MACD plotted as colored histogram.

    I use identical code for the color-coding of each plot, but the histogram seems to be one bar out. Take a look at the attached screenshot which compares my indicator with another successfully coded one, my Falling lines colors for the histogram seems to change a bar too late. The Rising() line seems to be OK though.

    Here's my code:

    protected override void OnBarUpdate()
    {
    Macdline.Set(MACD(Fast, Slow, Smooth).Value[0]);

    if (CurrentBar < 1)
    return;

    if (Rising(MACD(Fast, Slow, Smooth).Avg))
    {
    RisingPlot.Set(1, MACD(Fast, Slow, Smooth).Avg[1]); RisingPlot.Set(MACD(Fast, Slow, Smooth).Avg[0]);
    }

    else if (Falling(MACD(Fast, Slow, Smooth).Avg))
    {
    FallingPlot.Set(1, MACD(Fast, Slow, Smooth).Avg[1]);
    FallingPlot.Set(MACD(Fast, Slow, Smooth).Avg[0]);
    }

    // Plot yellow if the %D is neutral
    else
    {
    NeutralPlot.Set(1, MACD(Fast, Slow, Smooth).Avg[1]);
    NeutralPlot.Set(MACD(Fast, Slow, Smooth).Avg[0]);
    }

    if (Rising(MACD(Fast, Slow, Smooth).Value))
    {
    RisingMacd.Set(1, MACD(Fast, Slow, Smooth).Value[1]);
    RisingMacd.Set(MACD(Fast, Slow, Smooth).Value[0]);
    }

    else if (Falling(MACD(Fast, Slow, Smooth).Value))
    {
    FallingMacd.Set(1, MACD(Fast, Slow, Smooth).Value[1]);
    FallingMacd.Set(MACD(Fast, Slow, Smooth).Value[0]);
    }

    else
    {
    NeutralMacd.Set(1, MACD(Fast, Slow, Smooth).Value[1]);
    NeutralMacd.Set(MACD(Fast, Slow, Smooth).Value[0]);
    }
    }
    Just two sets of identical color-coded plots, but wheras the if (Rising(MACD(Fast, Slow, Smooth).Avg)) plot looks good, the if (Rising(MACD(Fast, Slow, Smooth).Value)) which plots the MACD line as a histogram isn't doing so well.

    Thanks for your help,
    Jeremy
    Attached Files

    #2
    Jeremymgp,

    This is just what I have been looking for. If you get this worked out I hope you will consider sharing this.

    Comment


      #3
      Sure Art, if support knows the answer it'll get posted here so just subscribe or check back on the thread. My previously attached image shows another histogram which works fine, so there must be a way.

      Comment


        #4
        I'm not sure how your screenshot is suppose to translate with your code. ".Value" is not the histogram plot of the MACD; ".Diff" is.

        This is what your code looks like when they are all line plots and it is accurate.
        Attached Files
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Hi Josh,

          Thanks for your response, I'm not plotting Diff, only using it as a DataSeries to calculate values.
          I'm plotting the MACD and the Avg lines with the MACD plotted as a red/green histogram, Avg as blue/magenta line.

          Take a look at the screenshot attached with this message, it compares the Falling plot as both a line and a bar. There's no change in the code, I just changed the Plotstyle from line to bar in the Indicators window.

          As you can see there are places such as at 18:58 where the Falling line is longer than the bar at the same time.

          Unusual also are places like 17:46 and 18:22, where both a Rising green histogram plot & a Falling red line plot exist coincidentally, implying some overlap.

          Thanks for your help,
          Jeremy
          Attached Files

          Comment


            #6
            This happens because of what is required to connect the lines into one continuous line. The conditions are evaluated at each point, but how do you decide what color line you want to use to connect the two points together with? Hence the overlapping colors.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              MACD colored line and colored histogram

              Hi Jeremymgp

              Has this indicator been finished, and would you mind sharing it?

              Thanks in advance for your help.

              HJS

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by usazencort, Today, 01:16 AM
              0 responses
              1 view
              0 likes
              Last Post usazencort  
              Started by kaywai, 09-01-2023, 08:44 PM
              5 responses
              603 views
              0 likes
              Last Post NinjaTrader_Jason  
              Started by xiinteractive, 04-09-2024, 08:08 AM
              6 responses
              22 views
              0 likes
              Last Post xiinteractive  
              Started by Pattontje, Yesterday, 02:10 PM
              2 responses
              21 views
              0 likes
              Last Post Pattontje  
              Started by flybuzz, 04-21-2024, 04:07 PM
              17 responses
              230 views
              0 likes
              Last Post TradingLoss  
              Working...
              X