Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multiple EMAs with different time frames

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

    Multiple EMAs with different time frames

    Hello,
    I would like to thank those who help out on this forum.
    I'm trying to create an indicator that has multiple EMAs with different time frames. Attached is a text file of what I have got. It is pretty messy. I can get the first EMA to plot but not the second. I also can't figure out how to get the plot settings so the user can change the style and color etc...
    Any help would be greatly appreciated.
    Thank you again for your time.
    James
    I attached another stab at it. LOL
    Attached Files
    Last edited by laoshr; 09-15-2021, 08:24 PM.

    #2
    Hello James,

    Thanks for your post.

    It looks like you are assigning the same data (BarsArray[1]) to both EMAs. When you add a data series, the BarsArray count increases so the first assed data series is BarsArray[1], the 2ned added data series is BarsArray[2], and so on.

    In your 2nd file, you are checking the current bar twice and you should only need that once, but for all three data series (BarsArray[0] is the chart bars).

    Does the indicator display the plots in the user interface? If so then the user can change the color, size, and type there.

    Comment


      #3
      Hello Paul,
      Thank you for your time.
      I changed the BarsArray[2] on the second ema and yes the option to change the color and line in the user interface is there.
      It seems now a bit messier. The EMAs almost seem reversed now and the 1st EMA color seems to be connected to the 2nd EMAs time and period. LOL
      I attached what I changed.
      Any help is greatly appreciated.
      Thanks again for your time.
      James
      Attached Files

      Comment


        #4
        Hello James,

        Thanks for your reply.

        In your current bar check you are only checking for the chart bars [0] and the 1st added data series [1], you should also add a check for [2]

        When you are only using one plot you can use Value, so Value[0] would be the current bar of the plot, Value[1] would be the previous bar, Value[2] the bar before tht, etc.

        When you have multiple plots you should use Values, so the first plot would be Values[0][0] = the second plot would be Values[1][0] =, etc. etc.

        Hint: Rather than values, in the OnBarUpdate() section, use the assigned plot name as it will be far easier to read than Values and you don't have to worry about using Value or Values, so for example EMA1_Color[0] = and EMA2_Color[0] = .

        In the "properties" section, the public series EMA1_Color needs to be set to Values[0], the public series EMA2_Color needs to be set to Values[1]. The values are assigned in the order of the plots which started with 0.

        In the OnBarUpdate(), what you works but so you know you do not need to use BarsInProgress == 0 twice, you can incorporate all actions to perform when it is true just once, for example:

        if (BarsInProgress == 0)
        {
        EMA1_Color[0] = EMA[1];
        EMA2_Color[0] = EMA[2];
        }


        The braces { } are used to mark the beginning and end of a list of actions to be performed when the if statement is true. We've recently added some further information to the help guide that may be helpful, please see https://ninjatrader.com/support/help...g_concepts.htm

        ​​​​​​​

        Comment


          #5
          Hello Paul,
          Thanks again for all your help. Learn here has been challenging. Thank you for your patience.
          Here is what I got and I have an error that pops up (see screenshot). I also attached the current file code.
          Thanks yet again for everything.
          James
          Attached Files

          Comment


            #6
            Hello James,

            Thanks for your reply.

            I wrote this incorrectly, sorry about that, please try:

            if (BarsInProgress == 0)
            {
            EMA1_Color[0] = EMA1[0];
            EMA2_Color[0] = EMA2[0];
            }

            Comment


              #7
              Thank you so very much, Paul.
              That worked. I will study the changes.
              Thanks again for all your help.
              James

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              637 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              366 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              107 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              569 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              571 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X