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

return multiple values in one method

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

    return multiple values in one method

    I would like to have a user defined method that can return multiple values. Is there a way to define it?

    The Ninja Script guide has an example on returning one calculated values. I copied it here:
    // This method performs a calculation and returns a double value
    private double Multiply(double input)
    {
    return input * 10;
    }

    What i want to do is to return 3 values: input*10, input*20, and input*30. Any way to accomplish that? Thanks.

    #2
    A method cannot return more than one value. However you can return an array of values. Unfortunately we do not have the bandwidth to assist with array creations and such. You can try searching google for resources. There are many around demonstrating how to do this.

    For instance http://www.daniweb.com/forums/thread91439.html
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      by reference

      Hi binwang2,

      in case you don't like to construct data structures for result handling you could deliver the parameters by reference. That means they are modified at the source; in this case in the calling environment.

      Regards
      Ralph
      Code:
      [FONT=Courier New][COLOR=#0000ff]private[/COLOR] [COLOR=#0000ff]void[/COLOR] Multiply([COLOR=#0000ff]ref double[/COLOR] input1, [COLOR=#0000ff]ref double[/COLOR] input2)[/FONT] 
      [FONT=Courier New]{[/FONT] 
      [FONT=Courier New]  input1 *= 10;[/FONT]
      [FONT=Courier New]  input2 *= 100;[/FONT] 
      [FONT=Courier New]}[/FONT]
       
      [FONT=Courier New]private [COLOR=blue]double[/COLOR] input1 = 1;[/FONT]
      [FONT=Courier New]private [COLOR=blue]double[/COLOR] input2 = 2;[/FONT]
      [FONT=Courier New]Multiply([COLOR=blue]ref[/COLOR] input1, [COLOR=blue]ref[/COLOR] input2);[/FONT]
      [FONT=Courier New][COLOR=mediumturquoise]// result of input1 = 10[/COLOR][/FONT]
      [COLOR=mediumturquoise][FONT=Courier New]// result of input2 = 200[/FONT]
      [/COLOR]

      Comment


        #4
        Ralph, thanks for pointing out another way.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by SantoshXX, Today, 03:09 AM
        0 responses
        13 views
        0 likes
        Last Post SantoshXX  
        Started by DanielTynera, Today, 01:14 AM
        0 responses
        2 views
        0 likes
        Last Post DanielTynera  
        Started by yertle, 04-18-2024, 08:38 AM
        9 responses
        42 views
        0 likes
        Last Post yertle
        by yertle
         
        Started by techgetgame, Yesterday, 11:42 PM
        0 responses
        14 views
        0 likes
        Last Post techgetgame  
        Started by sephichapdson, Yesterday, 11:36 PM
        0 responses
        2 views
        0 likes
        Last Post sephichapdson  
        Working...
        X