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 Hwop38, 05-04-2026, 07:02 PM
                0 responses
                160 views
                0 likes
                Last Post Hwop38
                by Hwop38
                 
                Started by CaptainJack, 04-24-2026, 11:07 PM
                0 responses
                307 views
                0 likes
                Last Post CaptainJack  
                Started by Mindset, 04-21-2026, 06:46 AM
                0 responses
                245 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by M4ndoo, 04-20-2026, 05:21 PM
                0 responses
                348 views
                0 likes
                Last Post M4ndoo
                by M4ndoo
                 
                Started by M4ndoo, 04-19-2026, 05:54 PM
                0 responses
                178 views
                0 likes
                Last Post M4ndoo
                by M4ndoo
                 
                Working...
                X