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

Summation

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

    Summation

    Hi,

    please, I need to a sum of values only if they are positive.
    For example : X = a+b+c were a, b,c are positive. If negaive no.

    Have someone idea about formula in NT7,

    Thanks in advance.
    Last edited by sniper; 10-24-2016, 11:16 AM.

    #2
    Hello Sniper,

    Thank you for your note.

    What you could do is add an if statement which checks to see if a, b, and c are positive and if so, set the value of x equal to a+b+c.

    Under initialize(),

    X = 0;

    Under OnBarUpdate you would add,

    if (CurrentBar < 1) return;

    if(a>0 && b>0 && c>0)
    {
    X = a+b+c;
    }

    Please let us know if you need further assistance.
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      I badly explained myself... in market action a, b and c can be +1 or -1 , i don't know which one is posive or negative.
      I can compile a little script like this :
      x=0
      if a>0
      then x=x+1
      if b>0
      then x=x+1
      etc.. etc...
      but it looks a dirty code. Is there a single command to do this ?
      Best regard .

      Comment


        #4
        Hello Sniper,

        If you only want to have 1 added to x if either a, b, or c had a positive value you could do,

        If(a>0 || b>0 || c>0)
        {
        X+=1;
        }

        However if you wanted to add 1 to x each time either a, b or c was positive than you would want to keep them as independent if statements as in your previous message.

        Please let us know if you need further assistance.
        Alan P.NinjaTrader Customer Service

        Comment


          #5
          The second one.
          Ok thanks a lot.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by inanazsocial, Today, 01:15 AM
          1 response
          5 views
          0 likes
          Last Post NinjaTrader_Jason  
          Started by rocketman7, Today, 02:12 AM
          0 responses
          10 views
          0 likes
          Last Post rocketman7  
          Started by dustydbayer, Today, 01:59 AM
          0 responses
          1 view
          0 likes
          Last Post dustydbayer  
          Started by trilliantrader, 04-18-2024, 08:16 AM
          5 responses
          23 views
          0 likes
          Last Post trilliantrader  
          Started by Davidtowleii, Today, 12:15 AM
          0 responses
          3 views
          0 likes
          Last Post Davidtowleii  
          Working...
          X