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

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 sidlercom80, 10-28-2023, 08:49 AM
              168 responses
              2,262 views
              0 likes
              Last Post sidlercom80  
              Started by Barry Milan, Yesterday, 10:35 PM
              3 responses
              10 views
              0 likes
              Last Post NinjaTrader_Manfred  
              Started by WeyldFalcon, 12-10-2020, 06:48 PM
              14 responses
              1,429 views
              0 likes
              Last Post Handclap0241  
              Started by DJ888, 04-16-2024, 06:09 PM
              2 responses
              9 views
              0 likes
              Last Post DJ888
              by DJ888
               
              Started by jeronymite, 04-12-2024, 04:26 PM
              3 responses
              41 views
              0 likes
              Last Post jeronymite  
              Working...
              X