• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

MACD multi frame

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

    MACD multi frame

    Hi,
    I have the following:

    Code:
    protected override void Initialize()
            {
                Add(PeriodType.Day,1);
            }
    protected override void OnBarUpdate()
            {
                double AvgMACD       =   MACD(BarsArray[1],12,26,9).Avg[0];
                double DiffMACD       =   MACD(BarsArray[1],12,26,9).Diff[0];
                
                if ( DiffMACD > AvgMACD )
                    {
                        BackColor = Color.Aqua;
                    }
                else if ( DiffMACD < AvgMACD )
                    {
                        BackColor = Color.Yellow;
                    }
                
            }
    Why it will not plot on any minutes charts and only on daily?

    #2
    Hello 2Look4me,

    Thank you for writing in.

    You will need to ensure that both your primary series and the secondary series have at least one bar of data before processing.

    Note that OnBarUpdate() is called for both series. When the first minute bar is being processed, a daily bar does not even exist yet. So, when your daily series calls OnBarUpdate(), it's trying to access the value of MACD Avg and Diff but those values do not yet exist and you run into a run-time error.

    I would suggest adding the following line of code before your logic within OnBarUpdate().

    Code:
    if (CurrentBars[0] < 0 || CurrentBars[1] < 0)
         return;
    More information about this can be found at this forum link here (it pertains to a script without an added series, however): http://ninjatrader.com/support/forum...ead.php?t=3170

    Please, let us know if we may be of further assistance.
    Last edited by NinjaTrader_ZacharyG; 09-12-2016, 12:04 PM.
    Zachary G.NinjaTrader Customer Service

    Comment


      #3
      Thanks Zachary. After making the change, the indicator in any of the minutes time frame is not showing correctly the daily MACD. I cannot tell where the problem is in the script. What am I missing here?

      Comment


        #4
        Hello 2Look4me,

        Can you please describe what you are expecting your script to do?

        Do you want your script to color the background of the one bar at daily close?

        If this is the case, you'll want to place your logic within an if (BarsInProgress == 1) conditional.

        Once the daily bar closes, color the background.

        Code:
        if (BarsInProgress == 1)
        {
             // logic to assign AvgMACD and DiffMACD and color the background
        }
        The code will only run once the daily bar closes and calls OnBarUpdate().

        Do you want your script to color the background of all the bars previous to the daily close?

        If this is the case, you'll need to count up how many bars are on your chart, then use BackColorSeries to color all bars of that session.

        I have provided an example indicator demonstrating this.
        Attached Files
        Zachary G.NinjaTrader Customer Service

        Comment


          #5
          Zachary,
          Thanks for the prompt response and for the example indicator. I was hoping that with the script, the BackColor of the minutes time frame plot reflects the daily MACD crossovers.

          From the attached two charts, this doesn't seem to be the case.
          Attached Files

          Comment


            #6
            Nevermind, I got the issue solved.

            With Calculate On Bar Close=False; doesn't seem that the Multi Time Frame indicator containing Add(PeriodType.Day,1) performs the calculations as the Day MACD crossover occurs in real time. If that is the case, is there a way around it so the indicator will plot the results as the PeriodType.Day crossover happens in real time?

            Comment


              #7
              Never mind, got that issue solved also. Thanks!

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by kojakojids, Today, 02:04 AM
              0 responses
              1 view
              0 likes
              Last Post kojakojids  
              Started by pitifak, Today, 01:01 AM
              0 responses
              3 views
              0 likes
              Last Post pitifak
              by pitifak
               
              Started by rjafcv, Yesterday, 10:40 PM
              0 responses
              4 views
              0 likes
              Last Post rjafcv
              by rjafcv
               
              Started by JAtrades, Yesterday, 07:38 PM
              0 responses
              3 views
              0 likes
              Last Post JAtrades  
              Started by bouncetherubble, Yesterday, 07:07 PM
              0 responses
              3 views
              0 likes
              Last Post bouncetherubble  
              Working...
              X