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

formula / syntax question .

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

    formula / syntax question .

    In this formula :
    protected override void OnBarUpdate()
    {
    if ((High[0] - Low[0]) == 0)
    {
    bop.Set(0) ;
    }
    else
    {
    bop.Set((Close[0] - Open[0]) / (High[0] - Low[0])) ;
    }

    Value.Set(SMA(bop, smooth)[0]) ;
    }


    I'd like to multiple this by volume :

    bop.Set((Close[0] - Open[0]) / (High[0] - Low[0])) ;

    But I can't get it to compile without errors .

    bop.Set((Close[0] - Open[0]) / (High[0] - Low[0])) * Volume[0] ;

    Seems straight forward ?




    #2
    T2020,

    You will need to watch the closing ). You want to put that after your additional volume math, not before.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Josh View Post
      T2020,

      You will need to watch the closing ). You want to put that after your additional volume math, not before.
      I see . And the division calculation is still carried out before the multiplication ? thx

      Comment


        #4
        Correct. You can use parenthesis to get it in the order you want.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          another quick question

          In this macd indicator :
          fastEma.Set(EMA(OBV(), Fast)[0]);

          slowEma.Set(SMA(OBV(), Slow)[0]);

          double macd = fastEma[0] - slowEma[0];
          double macdAvg = (2.0 / (1 + Smooth)) * macd + (1 - (2.0 / (1 + Smooth))) * Avg[1];

          Value.Set(macd);
          Avg.Set(macdAvg);
          Diff.Set((macd - macdAvg)*2);

          Is there a way to simplify this line :
          double macdAvg = (2.0 / (1 + Smooth)) * macd + (1 - (2.0 / (1 + Smooth))) * Avg[1];

          Something like this :
          double macdAvg = (EMA(macd, Period)[0]);

          It won't compile ,but if I had a line something like that , I could switch MA
          types easy . thx .

          Comment


            #6
            That is because "macd" is not a DataSeries. It is only a single double value. You need to pass in a DataSeries for that first parameter on the EMA for it to work.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_Josh View Post
              That is because "macd" is not a DataSeries. It is only a single double value. You need to pass in a DataSeries for that first parameter on the EMA for it to work.
              So you have to make " macd " into a dataseries ? Like the way " EMA " represents an exponential MA ? Not sure how to do that . ...

              Comment


                #8
                Please see the help guide article on DataSeries objects here: http://www.ninjatrader-support.com/H...taSeriesObject
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_Josh View Post
                  Please see the help guide article on DataSeries objects here: http://www.ninjatrader-support.com/H...taSeriesObject
                  I guess it's the DataSeries Objects your referring to ,but my programming
                  skills are limited to editing with minor substitutions and trial and error ,so
                  I wouldn't know where or how to include this . It's not something I have to
                  have ,just something that would make it easier to change MA types .
                  thx .

                  Comment


                    #10
                    T2020, you may also want to take a look at the tip that explains how to access DataSeries values and brackets [].
                    AustinNinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by gentlebenthebear, Today, 01:30 AM
                    1 response
                    8 views
                    0 likes
                    Last Post NinjaTrader_Jesse  
                    Started by Aviram Y, Today, 05:29 AM
                    1 response
                    7 views
                    0 likes
                    Last Post NinjaTrader_ChelseaB  
                    Started by cls71, Today, 04:45 AM
                    1 response
                    7 views
                    0 likes
                    Last Post NinjaTrader_ChelseaB  
                    Started by TradeForge, Today, 02:09 AM
                    1 response
                    22 views
                    0 likes
                    Last Post NinjaTrader_ChelseaB  
                    Started by elirion, Today, 01:36 AM
                    2 responses
                    14 views
                    0 likes
                    Last Post elirion
                    by elirion
                     
                    Working...
                    X