Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Simple EMA Question

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

    Simple EMA Question

    I want to display the difference of two EMAs as an indicator. I want the first EMA to be calculated on the highs of bars and the second to be calculated from the lows of bars. I tried:

    EMADifference.Set(EMA(High,3)- EMA(Low,3));

    NT tells me this doesn't work. Can someone point out the error in my approach?

    Thanks

    #2
    You cannot subtract the EMA indicators from each other like that. You need to subtract actual EMA values.

    EMADifference.Set(EMA(High, 3)[0] - EMA(Low, 3)[0]);
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Thanks Josh,

      One more question. I want to use the EMA values from one bar back.

      EMADifference.Set(EMA(High,3)[0]- EMA(Low,3)[0]);

      gives me the value for the EMA differences of the current bar but I would like to see what they are for the previous bar.

      EMADifference.Set(EMA(High,
      3)[1]- EMA(Low,3)[1]);

      This line of code compiles but nothing is displayed. Obviously another mistake here somewhere.

      Comment


        #4
        Originally posted by ramckay View Post
        Thanks Josh,

        One more question. I want to use the EMA values from one bar back.

        EMADifference.Set(EMA(High,3)[0]- EMA(Low,3)[0]);

        gives me the value for the EMA differences of the current bar but I would like to see what they are for the previous bar.

        EMADifference.Set(EMA(High,3)[1]- EMA(Low,3)[1]);

        This line of code compiles but nothing is displayed. Obviously another mistake here somewhere.
        Include the following line in the begining of OnBarUpdate:

        if(CurrentBar == 0) return;

        Comment


          #5
          Hi roonius,

          That solved the problem. What's the basic logic for when you need to use a DataSeries to hold values and when you don't?

          Thanks,

          rod

          Comment


            #6
            Originally posted by ramckay View Post
            Hi roonius,

            That solved the problem. What's the basic logic for when you need to use a DataSeries to hold values and when you don't?

            Thanks,

            rod
            If you do some calculations on a bar basis and then need to access them later, you store the values in DataSeries. If you don't need to access those values later (after n bars) then you don't need DataSeries.

            Comment


              #7
              hey rod - if you wanted to run an EMA against EMADifference, then you would want to set that inside a DataSeries, but if you're just plotting it, you should be OK with your current method.

              EDIT: or, in other words: what roonius said

              Comment


                #8
                Thanks guys,

                Rod

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                597 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                343 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                103 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                556 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                555 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X