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 Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          558 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          324 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          101 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          545 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          547 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X