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 10-11-2008, 12:42 PM   #1
mktrend
Senior Member
 
Join Date: Apr 2008
Posts: 123
Thanks: 0
Thanked 1 time in 1 post
Default Gloabal Variables?

Is there a way making the feed data received through NT available to third party programs, other than the txt file approach? Is there such a thing as the say Global Variables, whereby NT could read from or place to?

thanks
mktrend is offline  
Reply With Quote
Old 10-11-2008, 01:04 PM   #2
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

Best approach is to use the OnMarketData() method of an indicator and use this to drive data to your application.
NinjaTrader_Ray is offline  
Reply With Quote
Old 10-11-2008, 01:24 PM   #3
mktrend
Senior Member
 
Join Date: Apr 2008
Posts: 123
Thanks: 0
Thanked 1 time in 1 post
Default

Ray,
that's great news, any hints on how it can be done please, just a couple of lines will do...as long as I get a lead on what needs to be studied.
I'm familiar with the OnMarketData() part just need the hints on the "drive data to your application" part.

thanks

Quote:
Originally Posted by NinjaTrader_Ray View Post
Best approach is to use the OnMarketData() method of an indicator and use this to drive data to your application.
mktrend is offline  
Reply With Quote
Old 10-11-2008, 02:08 PM   #4
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

Likely you would need to provide an interface (DLL) from your application that will allow you to push the data through.
NinjaTrader_Ray is offline  
Reply With Quote
Old 10-11-2008, 02:59 PM   #5
mktrend
Senior Member
 
Join Date: Apr 2008
Posts: 123
Thanks: 0
Thanked 1 time in 1 post
Default

Yes, I was aware of that interface possibilities, although the question was about how to write directly to some form of Global variables that could have been both approached by NT and the 3rd. party app. which would also NOT be limited to just the VERY limited Methods available by the NT DLL interface.

Quote:
Originally Posted by NinjaTrader_Ray View Post
Likely you would need to provide an interface (DLL) from your application that will allow you to push the data through.
mktrend is offline  
Reply With Quote
Old 10-11-2008, 04:21 PM   #6
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

There are no global variables.
NinjaTrader_Ray is offline  
Reply With Quote
Old 10-11-2008, 08:52 PM   #7
mktrend
Senior Member
 
Join Date: Apr 2008
Posts: 123
Thanks: 0
Thanked 1 time in 1 post
Default

hmmm..., are you sure though?!

I'm thinking maybe the storage location can be a physical file, database or ASP.NET Cache, utilizing Serialization technology that enables an object to be converted into a linear stream of data that can be easily passed across process boundaries and machines, hence what is stopping us in the case of the NT?

Quote:
Originally Posted by NinjaTrader_Ray View Post
There are no global variables.
mktrend is offline  
Reply With Quote
Old 10-12-2008, 08:13 AM   #8
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

Let me approach this from a different perspective.

NinjaTrader uses C# thus the capability of the entire C# language and Microsoft .NET framework is available to you. We only provide support in the context of NinjaScript methods and properties. We do not provide support or guidance on capabilities outside that which falls into general C# programming. Anything can be done for sure.
NinjaTrader_Ray is offline  
Reply With Quote
Old 10-12-2008, 12:19 PM   #9
mktrend
Senior Member
 
Join Date: Apr 2008
Posts: 123
Thanks: 0
Thanked 1 time in 1 post
Default

Yes exactly, I understand and there indeed exists various options that I am already looking into.

Quote:
Originally Posted by NinjaTrader_Ray View Post
Let me approach this from a different perspective.

NinjaTrader uses C# thus the capability of the entire C# language and Microsoft .NET framework is available to you. We only provide support in the context of NinjaScript methods and properties. We do not provide support or guidance on capabilities outside that which falls into general C# programming. Anything can be done for sure.
mktrend is offline  
Reply With Quote
Old 10-17-2008, 04:50 PM   #10
SystemTrading
Senior Member
 
Join Date: Aug 2008
Location: Orlando, Florida
Posts: 166
Thanks: 0
Thanked 0 times in 0 posts
Default

Quote:
Originally Posted by mktrend View Post
Is there a way making the feed data received through NT available to third party programs, other than the txt file approach? Is there such a thing as the say Global Variables, whereby NT could read from or place to?

thanks
You can use Global Variable, which I believe was originally written for TS but works fine with NinjaTrader as well. It is simply a DLL that allows you to store/access values at your pleasure. You can communicate between charts etc. utilizing the program. If you don't have it, you should be able to find from google search, or I can email to you.
SystemTrading is offline  
Reply With Quote
Old 10-17-2008, 07:37 PM   #11
mktrend
Senior Member
 
Join Date: Apr 2008
Posts: 123
Thanks: 0
Thanked 1 time in 1 post
Default

You mean actually using the Global variables DLL supplied by TS?! How can that be done, it should be very interesting though.
I have found a few ways of achieving this by involving the shared memory or the WM_COPY but this is very interesting what you say and it makes lots of sense too, you would have C# read write to that DLL and have whatever else 3rd. party program do the same...hmmm, very clever.
I'll Pm you my email to please send me a sample code.
thanks

Quote:
Originally Posted by SystemTrading View Post
You can use Global Variable, which I believe was originally written for TS but works fine with NinjaTrader as well. It is simply a DLL that allows you to store/access values at your pleasure. You can communicate between charts etc. utilizing the program. If you don't have it, you should be able to find from google search, or I can email to you.
mktrend is offline  
Reply With Quote
Old 10-18-2008, 06:52 AM   #12
mrlogik
Certified NinjaScript Consultant
 
mrlogik's Avatar
 
Join Date: Sep 2006
Location: New York, USA
Posts: 774
Thanks: 1
Thanked 7 times in 5 posts
Default

mktrend,

As far as I understand it the DLL was not supplied by TS; someone made it.

In order to use it you will need to write some code in NT to interface to it, and its methods, and some code on the 3rd party side to do the same. I have actually done this with C++ and TS; the TS portion was already written for me.

mrlogik
"You look closely enough, you can find everything has a ... weak spot where it can break, sooner or later"

PureLogikTrading
mrlogik is offline  
Reply With Quote
Old 10-18-2008, 08:58 AM   #13
mktrend
Senior Member
 
Join Date: Apr 2008
Posts: 123
Thanks: 0
Thanked 1 time in 1 post
Default

mrlogik,

Yes this idea makes perfect sense, since the DLL resides in all desired processes and interfaces them through a Mapped-File, hence has nothing to do with TS and it can be used by any application.
I used to think that TS mad it since they supported it, but thanks to whomever did it.

I've read that under certain conditions it could even improve performance and retard it heavily in certain others. I wish NT would step in and comment on the potential performance effect and yes I know this subject is NOT supported.

I guess the C# load lib model should look similar to below after replacing the below with the GV prototype? I'll look into it.

[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);

I wish someone would show us how to directly write to a Mapped-File though, that must be faster and it can be used to accumulate data into it before witting it to HDD and also make the data available to all other apps.
mktrend is offline  
Reply With Quote
Old 10-18-2008, 09:19 AM   #14
mktrend
Senior Member
 
Join Date: Apr 2008
Posts: 123
Thanks: 0
Thanked 1 time in 1 post
Default

[DllImport("GlobalVariable21.dll", SetLastError = true)]
static extern "C" int __stdcall GV_GetInteger( int iLocation ) ;

well something similar to the above???
mktrend is offline  
Reply With Quote
Old 10-18-2008, 09:25 AM   #15
mrlogik
Certified NinjaScript Consultant
 
mrlogik's Avatar
 
Join Date: Sep 2006
Location: New York, USA
Posts: 774
Thanks: 1
Thanked 7 times in 5 posts
Default

In my MFC program this is part of what I had.

First, the extern prototypes
Code:
HINSTANCE hDll;
extern "C" __declspec(dllexport) int __stdcall GV_GetInteger(int location);
extern "C" __declspec(dllexport) int __stdcall GV_SetInteger(int location, int value);
Then the get / set functions

Code:
/***********************************************************************/
/*****************       GetGVInteger     ******************************/
/***********************************************************************/
int getGvInteger(int location)
{
    typedef int (__stdcall*getIntegerPtr)(int);
    getIntegerPtr func;
    func = (getIntegerPtr)GetProcAddress(hDll, "GV_GetInteger");

    int i = -1;
    if ( func )
        i = func(location);

    return i;
}


/***********************************************************************/
/*****************       SetGVInteger     ******************************/
/***********************************************************************/
int setGvInteger(int location, int value)
{
    typedef int (__stdcall*getIntegerPtr)(int, int);
    getIntegerPtr func;
    func = (getIntegerPtr)GetProcAddress(hDll, "GV_SetInteger");

    int i = -1;
    if ( func )
        i = func(location, value);

    return i;
}
On init i did this
Code:
hDll = LoadLibrary("the dlls location");
And then I was able to use those functions I described above.

This was in MFC, I haven't looked into how to use a DLL with NT yet.

I hope this is a little helpful
"You look closely enough, you can find everything has a ... weak spot where it can break, sooner or later"

PureLogikTrading
mrlogik 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
Using variables eswap0 General Programming 2 06-07-2008 05:56 PM
Global variables monpere Strategy Development 1 03-10-2008 07:06 PM
importing variables from .txt sandro Indicator Development 1 05-15-2007 06:59 AM
where should variables be declared? Folls Indicator Development 2 05-04-2007 11:12 AM
Plotting variables MAX Indicator Development 2 10-30-2006 10:19 PM


All times are GMT -6. The time now is 07:51 AM.