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

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 ender_wiggum, Today, 09:50 AM
                1 response
                5 views
                0 likes
                Last Post NinjaTrader_Gaby  
                Started by rajendrasubedi2023, Today, 09:50 AM
                1 response
                10 views
                0 likes
                Last Post NinjaTrader_BrandonH  
                Started by geotrades1, Today, 10:02 AM
                0 responses
                4 views
                0 likes
                Last Post geotrades1  
                Started by bmartz, Today, 09:30 AM
                1 response
                8 views
                0 likes
                Last Post NinjaTrader_Erick  
                Started by geddyisodin, Today, 05:20 AM
                3 responses
                25 views
                0 likes
                Last Post NinjaTrader_Gaby  
                Working...
                X