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

Not able to pass double to method

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

    Not able to pass double to method

    Hello, I am sorry as this is probably an extremely easy and dumb question but I have been pulling my hair out for 2 days. I am trying to calculate a value with OBV() and pass it to another study but the study takes an int.

    Here is the code:

    double obv = OBV()[0];
    double obvEma = EMA(obv, 12);

    I have tried quite a bit to get the value of obv into the first parameter of EMA but I just cant seem to get it.

    What confuses me even more is that I have done it in another section of my code:
    ISeries<double> mom0 = Momentum(Close, Momentum_length);
    ISeries<double> mom1 = Momentum(mom0, 1);

    I am getting errors ranging from ​CS1502, CS0029 and others.

    ​Thanks for your help!

    #2
    Originally posted by TargetFilledTrading View Post
    Hello, I am sorry as this is probably an extremely easy and dumb question but I have been pulling my hair out for 2 days. I am trying to calculate a value with OBV() and pass it to another study but the study takes an int.

    Here is the code:

    double obv = OBV()[0];
    double obvEma = EMA(obv, 12);

    I have tried quite a bit to get the value of obv into the first parameter of EMA but I just cant seem to get it.

    What confuses me even more is that I have done it in another section of my code:
    ISeries<double> mom0 = Momentum(Close, Momentum_length);
    ISeries<double> mom1 = Momentum(mom0, 1);

    I am getting errors ranging from ​CS1502, CS0029 and others.

    ISeries<double> obv = OBV();
    ISeries<double> obvEma = EMA(obv, 12);

    or

    OBV obv = OBV();
    EMA obvEma = EMA(obv, 12);
    ​​

    Comment


      #3
      Originally posted by bltdavid View Post

      ISeries<double> obv = OBV();
      ISeries<double> obvEma = EMA(obv, 12);

      or

      OBV obv = OBV();
      EMA obvEma = EMA(obv, 12);
      ​​
      Thank you for the help! The first one works and compiles however I am not able to use a future operand on the variable for comparison.

      I ended up figuring out an alternative that allows the convert to int to work.

      Code:
      int obv = Convert.ToInt32(OBV()[0]);
      double obvEma = EMA(obv)[0];

      Comment


        #4
        No, you can't do EMA of an int that is not a series. You should do it like bltdavid suggested above. The first argument to EMA() has to be a series - it cannot be just a single scalar value.
        Bruce DeVault
        QuantKey Trading Vendor Services
        NinjaTrader Ecosystem Vendor - QuantKey

        Comment


          #5
          Originally posted by bltdavid View Post
          ISeries<double> obv = OBV();
          ISeries<double> obvEma = EMA(obv, 12);

          or

          OBV obv = OBV();
          EMA obvEma = EMA(obv, 12);
          After obv and obvEma are defined, per above, you can then
          use '[n]' indexing to access individual values on a 'BarsAgo' basis,

          Print("obv[0]="+obv[0]);
          Print("obvEma[0]="+obvEma[0]);


          -=o=-

          You said,
          "I am not able to use a future operand on the variable for comparison"

          ​Are you referring to the ability to add an indexer? That is, when you
          append the '[0]' suffix, like for an array?

          Otherwise, sorry, no idea what that means ...

          Comment


            #6
            Originally posted by QuantKey_Bruce View Post
            No, you can't do EMA of an int that is not a series. You should do it like bltdavid suggested above. The first argument to EMA() has to be a series - it cannot be just a single scalar value.
            Interesting, it compiled and worked? I thought EMA could take an int arg or a series double? both would work from what I interpreted from the documentation? Thanks for the extra help!

            Comment


              #7
              What it's doing when you send it an int argument is treating it as the length, and doing an EMA of the default input which is Close.

              You indicated above that you were trying to do an EMA of OBV, so that would not be what you appeared to be wanting.

              Yes, it compiles, but it is not going to give you what you appeared to be trying to get.
              Bruce DeVault
              QuantKey Trading Vendor Services
              NinjaTrader Ecosystem Vendor - QuantKey

              Comment


                #8
                Originally posted by bltdavid View Post

                After obv and obvEma are defined, per above, you can then
                use '[n]' indexing to access individual values on a 'BarsAgo' basis,

                Print("obv[0]="+obv[0]);
                Print("obvEma[0]="+obvEma[0]);


                -=o=-

                You said,
                "I am not able to use a future operand on the variable for comparison"

                ​Are you referring to the ability to add an indexer? That is, when you
                append the '[0]' suffix, like for an array?

                Otherwise, sorry, no idea what that means ...

                Thank you again bltdavid! Sorry I should have been more clear. Later in my logic for trade entries, I am comparing values of the variables saying something like:
                IF obv > obvEma then foo

                But when I used your way that logic failed for some reason.

                Comment


                  #9
                  Originally posted by QuantKey_Bruce View Post
                  What it's doing when you send it an int argument is treating it as the length, and doing an EMA of the default input which is Close.

                  You indicated above that you were trying to do an EMA of OBV, so that would not be what you appeared to be wanting.

                  Yes, it compiles, but it is not going to give you what you appeared to be trying to get.
                  Oooooohhh, I understand now. Thank you for explaining it so clearly, I appreciate that!

                  Comment


                    #10
                    Hello TargetFilledTrading,

                    Thanks for your post.

                    bltdavid and QuantKey_Bruce are correct. The first argument for EMA() must be a Series and cannot be an int value as seen in the EMA() help guide syntax.

                    EMA(ISeries<double> input, int period)

                    EMA(): https://ninjatrader.com/support/help...onential_e.htm

                    After defining obv and EMA, you could access values by supplying a BarsAgo index value. Using a BarsAgo index of [0] means you would be accessing the current bar's value. Using a BarsAgo index of [1] means you would be accessing the previous bar's value, and so on.
                    Brandon H.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by ChartTourist, Today, 08:22 AM
                    0 responses
                    3 views
                    0 likes
                    Last Post ChartTourist  
                    Started by LiamTwine, Today, 08:10 AM
                    0 responses
                    2 views
                    0 likes
                    Last Post LiamTwine  
                    Started by Balage0922, Today, 07:38 AM
                    0 responses
                    5 views
                    0 likes
                    Last Post Balage0922  
                    Started by JoMoon2024, Today, 06:56 AM
                    0 responses
                    6 views
                    0 likes
                    Last Post JoMoon2024  
                    Started by Haiasi, 04-25-2024, 06:53 PM
                    2 responses
                    19 views
                    0 likes
                    Last Post Massinisa  
                    Working...
                    X