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

getting an indicator a tally?

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

    getting an indicator a tally?

    How would you code an indicator to tally a specific codition you built. I built a condition that has a value of +1 or -1 everytime it occurs. but I cant get it to tally the 1's. the results just goto plus or minus 1 and back to 0 when I want the numbers to tally as they go along...

    I'm very new to programming so please take that fact under consideration, but heres a copy of the code i built and could anyone suggest any ways to create codes to tally the results:

    {
    double pos = 0;
    double neg = 0;
    double sum = 0;
    if (High [0] > 600) pos = 1;
    if (Low [0] < -600) neg = -1;
    sum = (pos + neg);

    // Use this method for calculating your indicator values. Assign a value to each
    // plot below by replacing 'Close[0]' with your own formula.
    Plot0.Set(sum [0] + sum [1]);

    }

    #2
    This code will not compile.

    What you need to do is create a DataSeries object named mySum. Then do something like:

    mySum.Set(pos + neg)
    if (CurrentBar > 0) Plot0.Set(mySum[0] + mySum[1]);

    See here for a reference - http://www.ninjatrader-support.com/H...iesObject.html
    RayNinjaTrader Customer Service

    Comment


      #3
      thanks, I'll give it a try.

      Much appreciated

      Comment


        #4
        I'm getting closer but for some reason its still tending to dwell towards 0. when it doesn't register my condition the line goes back to 0. I would like it to add onto the last positive or negative result.

        Comment


          #5
          Thats because you are resetting the value of your counter at the start of every call to the OnBarUpdate() method. You want to define your variables outside of the OnBarUpdate() method. Place them inside the section titled "Variables" which is above the Initialize() method.

          Do something like:
          private double pos = 0;
          Josh P.NinjaTrader Customer Service

          Comment


            #6
            Originally posted by Josh View Post
            Thats because you are resetting the value of your counter at the start of every call to the OnBarUpdate() method. You want to define your variables outside of the OnBarUpdate() method. Place them inside the section titled "Variables" which is above the Initialize() method.

            Do something like:
            private double pos = 0;
            I hate to be a pain but after I made the changes the line went to flat 0. is there anything else I'm missing? Should I post my code to give a better idea of what I'm doing?

            I can't figure out why its not working.

            thanks again,

            Comment


              #7
              Have you followed our debug suggestions here - http://www.ninjatrader-support.com/v...ead.php?t=3418
              RayNinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Jon17, Today, 04:33 PM
              0 responses
              1 view
              0 likes
              Last Post Jon17
              by Jon17
               
              Started by Javierw.ok, Today, 04:12 PM
              0 responses
              4 views
              0 likes
              Last Post Javierw.ok  
              Started by timmbbo, Today, 08:59 AM
              2 responses
              10 views
              0 likes
              Last Post bltdavid  
              Started by alifarahani, Today, 09:40 AM
              6 responses
              40 views
              0 likes
              Last Post alifarahani  
              Started by Waxavi, Today, 02:10 AM
              1 response
              19 views
              0 likes
              Last Post NinjaTrader_LuisH  
              Working...
              X