Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Syntax for method/function: 2 inputs/1 Output

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

    Syntax for method/function: 2 inputs/1 Output

    Hello. I am doing something over and over, and require the syntax for a function that will receive two inputs, and report one output.

    I am familiar with using functions of the form:
    Code:
    private void myMethod()
    {
        stuff......
    }
    Thanks!

    reference:

    #2
    Hello forrestang,

    If you are looking to output or Print() some information based on the two inputs that you pass in you may do something like:

    private void SUMValue(double var1, double var2)
    {
    Print("Sum equals: "+(var1+var2));
    }

    Otherwise, if you want to return 1 value from the two that you passed in you may do something like:

    private double SUMValueReturn(double var1, double var2)
    {
    return (var1+var2);
    }
    JCNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_JC View Post
      Hello forrestang,
      ......Otherwise, if you want to return 1 value from the two that you passed in you may do something like:

      private double SUMValueReturn(double var1, double var2)
      {
      return (var1+var2);
      }
      In your second example, where is that returned value stored? I'd like to call the function and then pass it to a variable for use later.

      Comment


        #4
        Hello forrestang,

        It is going to be returned wherever you call the function from.

        double storedValue = 0;

        protected override void OnBarUpdate()
        {
        storedValue = SUMValueReturn(1, 2);
        // storedValue is now equal to 3
        }
        JCNinjaTrader Customer Service

        Comment


          #5
          Thanks JC. That was exactly what I needed!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by argusthome, Yesterday, 10:06 AM
          0 responses
          14 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          11 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          9 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          4 views
          0 likes
          Last Post TheRealMorford  
          Started by Mindset, 02-28-2026, 06:16 AM
          0 responses
          31 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Working...
          X