Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Calculating difference between 2 EMA's

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

    Calculating difference between 2 EMA's

    I am writing a strategy that includes checking the distance between 2 EMA's. I am only having one problem: being able to make the actual calculation. Every time I try anything I get an error related to incorrect field type.

    All I need to be able to do is set a numeric variable to the value of an EMA.

    Conceptually I need to be able to do the following:

    EMASlow = EMA(34)

    I have searched for hours for a solution for what I know is a simple problem but I had no luck. I'm an old VB programmer and finding all the details for C# is problematic.

    If anyone can provide me the one or two script lines I would need, I would appreciate it.

    #2
    Originally posted by gcaldridge View Post
    I am writing a strategy that includes checking the distance between 2 EMA's. I am only having one problem: being able to make the actual calculation. Every time I try anything I get an error related to incorrect field type.

    All I need to be able to do is set a numeric variable to the value of an EMA.

    Conceptually I need to be able to do the following:

    EMASlow = EMA(34)

    I have searched for hours for a solution for what I know is a simple problem but I had no luck. I'm an old VB programmer and finding all the details for C# is problematic.

    If anyone can provide me the one or two script lines I would need, I would appreciate it.
    What is the exact error message?

    Comment


      #3
      Hello gcaldridge,
      Please open the output window (Tools>Output Window) and see if there is any error messages. If so can you please let me know.

      Also please make sure you have enough bars to calculate on historical bars. Please refer to this post to know more
      JoydeepNinjaTrader Customer Service

      Comment


        #4
        Originally posted by gcaldridge View Post
        I am writing a strategy that includes checking the distance between 2 EMA's. I am only having one problem: being able to make the actual calculation. Every time I try anything I get an error related to incorrect field type.

        All I need to be able to do is set a numeric variable to the value of an EMA.

        Conceptually I need to be able to do the following:

        EMASlow = EMA(34)

        I have searched for hours for a solution for what I know is a simple problem but I had no luck. I'm an old VB programmer and finding all the details for C# is problematic.

        If anyone can provide me the one or two script lines I would need, I would appreciate it.
        This is the code I have:

        variable9 = EMA(14) [0];
        variable8 = EMA(34) [0];

        and it compiles clean.

        When I add the following line:

        variable7=variable9-variable8

        I get the following error:

        the name variable7 does not exist in the current context

        Thanks

        Geoff

        Comment


          #5
          Hello gcaldridge,
          To assist you further can you please send a toy NinjaScript code* replicating the behavior to support[AT]ninjatrader[DOT]com

          Please append Attn:Joydeep in the subject line of the email and give a reference of this thread in the body of the email.

          I look forward to assisting you further.

          *The "toy" just means something that is a stripped down version that isn't necessarily the whole logic. It makes things easier to rout out.
          JoydeepNinjaTrader Customer Service

          Comment


            #6
            Originally posted by gcaldridge View Post
            This is the code I have:

            variable9 = EMA(14) [0];
            variable8 = EMA(34) [0];

            and it compiles clean.

            When I add the following line:

            variable7=variable9-variable8

            I get the following error:

            the name variable7 does not exist in the current context

            Thanks

            Geoff
            Where have you declared variable7?

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            578 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            334 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            101 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            553 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            551 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X