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

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 frslvr, 04-11-2024, 07:26 AM
            8 responses
            111 views
            1 like
            Last Post NinjaTrader_BrandonH  
            Started by stafe, 04-15-2024, 08:34 PM
            10 responses
            44 views
            0 likes
            Last Post stafe
            by stafe
             
            Started by rocketman7, Today, 09:41 AM
            3 responses
            8 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by traderqz, Today, 09:44 AM
            2 responses
            5 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by rocketman7, Today, 02:12 AM
            7 responses
            31 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Working...
            X