NinjaTrader Support Forum  
X

Attention!

This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com


Go Back   NinjaTrader Support Forum > NinjaScript Development Support > General Programming

General Programming General NinjaScript programming questions.

Reply
 
Thread Tools Display Modes
Old 12-06-2010, 07:11 AM   #1
fosch
Member
 
Join Date: Feb 2010
Posts: 74
Thanks: 1
Thanked 2 times in 2 posts
Default returning a value from a method/function?

I'm new to C#, but not new to programming (I have a VB background). I'm trying to get the syntax right for the following. I'm trying to create a method/function that will return a number of shares based off calculations within. I've successfully created methods/functions that just perform calculations, but do not return anything. However, I'm having trouble getting the syntax right when trying to return a value. Here's my code:

publicvoid TotalShareSize (double risk, double rval, outint totShareSize)
{
//Calculations here...
totShareSize = x;

}

Thanks.
fosch
fosch is offline  
Reply With Quote
Old 12-06-2010, 07:30 AM   #2
dave1992
Senior Member
 
Join Date: Nov 2008
Location: UK
Posts: 637
Thanks: 0
Thanked 1 time in 1 post
Default

If the value being returned is an integer, for example, just replace

publicvoid

with

public int

and then in the proc, do

return value;
dave1992 is offline  
Reply With Quote
Old 12-06-2010, 07:56 AM   #3
NinjaTrader_Brett
NinjaTrader Customer Service
 
NinjaTrader_Brett's Avatar
 
Join Date: Dec 2009
Location: Denver, CO, USA
Posts: 6,498
Thanks: 109
Thanked 291 times in 280 posts
Default

DAve,

Thanks for the assist appreciate it.

Dave is absolutely correct.

Let us know if you have follow up questions, also searching the net for c# information will greatly assist here as well.

Let me know if I can be of further assistance.
NinjaTrader_Brett is offline  
Reply With Quote
Old 12-06-2010, 10:22 AM   #4
fosch
Member
 
Join Date: Feb 2010
Posts: 74
Thanks: 1
Thanked 2 times in 2 posts
Default

Thanks fellas... dave1992, that did the trick. Much appreciated.

fosch
fosch is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
returning non plotted series murfinp Indicator Development 8 08-17-2010 08:10 AM
Functions returning 2 values kenz987 Charting 2 10-09-2009 07:36 AM
ZeroLagEMA returning 0 RandyT General Programming 3 07-15-2009 08:45 AM
Returning ticks from entry rsi77 Strategy Development 21 02-02-2009 01:53 AM
Indicator returning more than one value ryker General Programming 2 12-06-2007 02:22 AM


All times are GMT -6. The time now is 01:50 AM.