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

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 wzgy0920, 04-20-2024, 06:09 PM
          2 responses
          27 views
          0 likes
          Last Post wzgy0920  
          Started by wzgy0920, 02-22-2024, 01:11 AM
          5 responses
          32 views
          0 likes
          Last Post wzgy0920  
          Started by wzgy0920, 04-23-2024, 09:53 PM
          2 responses
          49 views
          0 likes
          Last Post wzgy0920  
          Started by Kensonprib, 04-28-2021, 10:11 AM
          5 responses
          193 views
          0 likes
          Last Post Hasadafa  
          Started by GussJ, 03-04-2020, 03:11 PM
          11 responses
          3,235 views
          0 likes
          Last Post xiinteractive  
          Working...
          X