PDA

View Full Version : Shared class


SteveB
12-19-2008, 05:10 PM
I'm sure there is a simple solution...(VB.NET guy)...

I want to create a class I can call from all other strategies.

namespace NinjaTrader.Strategy
{
partial class Strategy
{
}
public class clsAccount
{
public void Check_OpenOrders()
{

}
}
}

In my Strategy I have:

clsAccount Acct = new clsAccount();

Acct.Check_OpenOrders;

NT is flagging the semi-colon at the end of Acct.Check_OpenOrders;

The error I'm getting is:
Class member declaration expected.
Invalid token ";" in class, struct, or interface member declaration.

It makes no difference if my class is within the "partial class Strategy" brackets or not...

Thanks!

mrlogik
12-19-2008, 06:29 PM
just after a quick look.

dont you need a () at the end since Check_OpenOrders() is a function?

SteveB
12-19-2008, 06:49 PM
Sorry, I did try that before...the error message with "()" is:

Invalid token "(" in class, struct, or interface member declaration.

Ralph
12-20-2008, 01:42 AM
I do count 7 curly braces in total, 1 seems to be missing.

Regards
Ralph

SteveB
12-20-2008, 08:37 AM
I appreciate everyone's help; it's not a bracket thing...just conveying my simple problem...

I can't believe something this simple is so difficult.

VB.Net guy

mrlogik
12-20-2008, 08:46 AM
I made a GlobalVariables Indicator and posted it on this forum a few months ago. Since, I have also made a GlobalStrategy Strategy for use of global variables within strategies.

Take a look at the attached.

I have in here Set / Get methods for support / resistance values, but this can easily be changed for what you want.

You can reference this (http://www.ninjatrader-support2.com/vb/showthread.php?t=10140&highlight=global) for aid, as well as this (http://www.ninjatrader-support2.com/vb/showthread.php?t=10140&highlight=global).

good luck.

Ralph
12-20-2008, 09:20 AM
Hi Steve,

it is not a simple problem, because your code works, with the syntax as proposed by mrlogik.

It doesn't matter if one defines the clsAccount-class inside the the Strategy-class or just in the NinjaTrader.Strategy-namespace.
It is possible to call Acct.Check_OpenOrders() in Initialize() for example.

... but it doesn't work to apply Acct.Check_OpenOrders() outside a class-method and that raises the same error message you mentioned.
Is that your problem?

Regards
Ralph

SteveB
12-20-2008, 04:35 PM
Thank You Ralph!

Yes I was putzing just to get an example up and running and had the code outside a class.

Inside works like a charm.