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 TheWhiteDragon, 01-21-2019, 12:44 PM
            4 responses
            541 views
            0 likes
            Last Post PaulMohn  
            Started by GLFX005, Today, 03:23 AM
            0 responses
            3 views
            0 likes
            Last Post GLFX005
            by GLFX005
             
            Started by XXtrader, Yesterday, 11:30 PM
            2 responses
            11 views
            0 likes
            Last Post XXtrader  
            Started by Waxavi, Today, 02:10 AM
            0 responses
            7 views
            0 likes
            Last Post Waxavi
            by Waxavi
             
            Started by TradeForge, Today, 02:09 AM
            0 responses
            14 views
            0 likes
            Last Post TradeForge  
            Working...
            X