Go Back   NinjaTrader Support Forum > NinjaTrader 7 > General Development

General Development General NinjaScript development questions.

NinjaTrader
Reply
 
Thread Tools Display Modes
Old 10-18-2008, 11:26 AM   #16
mktrend
Senior Member
 
Join Date: Apr 2008
Posts: 123
Thanks: 0
Thanked 1 time in 1 post
Default

Well yes, the TS zip comes with the source code and all in C++...but, how do we convert it to C#?
mktrend is offline  
Reply With Quote
Old 10-18-2008, 01:56 PM   #17
mktrend
Senior Member
 
Join Date: Apr 2008
Posts: 123
Thanks: 0
Thanked 1 time in 1 post
Default

This WORKS:

[DllImport("GlobalVariable.dll")]
public static extern int GV_SetInteger(int iLocation, int iVal);

[DllImport("GlobalVariable.dll")]
public static extern int GV_GetInteger( int iLocation) ;

int GV1 = GV_SetInteger(1, 33);
int GV2 = GV_GetInteger(1);
mktrend is offline  
Reply With Quote
The following user says thank you to mktrend for this post:
Old 11-16-2008, 02:09 PM   #18
GaryAlbers
Senior Member
 
Join Date: Nov 2007
Location: Arlington Heights, IL
Posts: 263
Thanks: 4
Thanked 27 times in 25 posts
Default Could you show a bit more?

mktrend,

I am trying to understand how to use the code snipet you showed.
For example, on these two lines of code:
[DllImport("GlobalVariable.dll")]
public static extern int GV_SetInteger(int iLocation, int iVal);

Is that the EXACT syntax?
Do they go before the Using Declarations?
Do they go after the brace of the 'namespace NinjaTrader.Indicator' statement?
I have tried several combinations and keep getting compiler errors.

I assume the GlobalVariables.dll should go in:
C:\Program Files\NinjaTrader 6.5\bin right?

I appreciate any direction you can provide. Perhaps a link that I can refer to?


Thanks,
Gary
GaryAlbers is offline  
Reply With Quote
Old 11-17-2008, 05:22 AM   #19
mktrend
Senior Member
 
Join Date: Apr 2008
Posts: 123
Thanks: 0
Thanked 1 time in 1 post
Default

Quote:
Originally Posted by GaryAlbers View Post
mktrend,

I am trying to understand how to use the code snipet you showed.
For example, on these two lines of code:
[DllImport("GlobalVariable.dll")]
public static extern int GV_SetInteger(int iLocation, int iVal);

Is that the EXACT syntax?
Do they go before the Using Declarations?
Do they go after the brace of the 'namespace NinjaTrader.Indicator' statement?
I have tried several combinations and keep getting compiler errors.

I assume the GlobalVariables.dll should go in:
C:\Program Files\NinjaTrader 6.5\bin right?

I appreciate any direction you can provide. Perhaps a link that I can refer to?


Thanks,
Gary
make sure dll in bin or wherever but both apps address the same path...
mktrend is offline  
Reply With Quote
Old 12-19-2008, 09:27 PM   #20
GATT1
Junior Member
 
Join Date: Nov 2008
Posts: 13
Thanks: 0
Thanked 0 times in 0 posts
Default

Can somebody please provide a download link for GlobalVariable.dll?
Please don't post the TS link, I have no access to the TS forum!

Thank you
GATT1 is offline  
Reply With Quote
Old 01-13-2009, 06:09 AM   #21
cunparis
Senior Member
 
Join Date: Feb 2008
Location: Paris
Posts: 733
Thanks: 15
Thanked 15 times in 9 posts
Default

Quote:
Originally Posted by GATT1 View Post
Can somebody please provide a download link for GlobalVariable.dll?
Please don't post the TS link, I have no access to the TS forum!

Thank you
I just found this thread working on an algorithm to have multiple strategies coordinate to best use my trading capital. You can read the details of that discussion here: http://www.ninjatrader-support2.com/...ad.php?t=12252

I found the GV file that people are looking for here and I'm attaching it to this message.

I will try it out and report back. It may take me a few days, I have a lot of work this week.

Thank you to everyone in this thread for sharing this idea and for posting the code examples. It's very helpful to me.
Attached Files
File Type: zip Gv.zip (25.5 KB, 215 views)
cunparis is offline  
Reply With Quote
Old 01-13-2009, 06:51 AM   #22
mktrend
Senior Member
 
Join Date: Apr 2008
Posts: 123
Thanks: 0
Thanked 1 time in 1 post
Default

Quote:
Originally Posted by cunparis View Post
The problem is once a strategy enters a long position, I don't want the other strategies to enter any positions. My account size won't allow it. I can't figure out how to do this.

The solution of just trading one strategy doesn't work for me because I don't get many trades so I like to trade ES & NQ so that I get more trades.
Yep, you're on the right track! Just have each strategy entering a position to set a Global Variable to 1 and after exiting it to reset it back to 0 and all strategies to check the condition of the flag first and if it's a 1 it means the account is not available...etc.

A bit more sophisticated approach would be to make a custom event as in any strategy entering and exiting a trade would inform the others about it by raising a custom event.
I had a thread on this a few days ago!

here:
http://www.ninjatrader-support2.com/...ad.php?t=13039
Last edited by mktrend; 01-13-2009 at 06:55 AM.
mktrend is offline  
Reply With Quote
Old 01-13-2009, 07:07 AM   #23
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 26,245
Thanks: 496
Thanked 1,866 times in 1,796 posts
Default

Thanks for posting this info guys!
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 01-13-2009, 12:01 PM   #24
mktrend
Senior Member
 
Join Date: Apr 2008
Posts: 123
Thanks: 0
Thanked 1 time in 1 post
Default

Quote:
Originally Posted by mktrend View Post
This WORKS:

[DllImport("GlobalVariable.dll")]
public static extern int GV_SetInteger(int iLocation, int iVal);

[DllImport("GlobalVariable.dll")]
public static extern int GV_GetInteger( int iLocation) ;

int GV1 = GV_SetInteger(1, 33);
int GV2 = GV_GetInteger(1);
Utilizing the snippet above or any of the many other functions available in the GV.dll you can send any data or even streams from one ind. strat, to others quite easily. Post if need more help. Make sure the same copy of the dll is referred to and no other copies of the same dll exist in your system files etc.
mktrend is offline  
Reply With Quote
Old 03-03-2009, 12:39 PM   #25
bridenour
Senior Member
 
Join Date: Jan 2009
Posts: 158
Thanks: 0
Thanked 0 times in 0 posts
Default

Hi,

Did using this DLL actually work out for you guys? Do you think it would be appropriate/effective for storing an "available balance" variable across multiple live executing strategies?

Thanks,
Brandon
bridenour is offline  
Reply With Quote
Old 03-04-2009, 12:20 AM   #26
cunparis
Senior Member
 
Join Date: Feb 2008
Location: Paris
Posts: 733
Thanks: 15
Thanked 15 times in 9 posts
Default

Quote:
Originally Posted by bridenour View Post
Hi,

Did using this DLL actually work out for you guys? Do you think it would be appropriate/effective for storing an "available balance" variable across multiple live executing strategies?

Thanks,
Brandon
I don't think it's necessary. A static variable seems to do the same thing.

This GV is to communicate between different applications, not to communicate inside the same application when other methods (static variable) are possible.
cunparis is offline  
Reply With Quote
Old 03-04-2009, 07:00 AM   #27
bridenour
Senior Member
 
Join Date: Jan 2009
Posts: 158
Thanks: 0
Thanked 0 times in 0 posts
Default

cunparis,

i thought you had said you tried with a static variable but were not successful? thanks for the input!

br
bridenour is offline  
Reply With Quote
Old 03-04-2009, 11:06 AM   #28
cunparis
Senior Member
 
Join Date: Feb 2008
Location: Paris
Posts: 733
Thanks: 15
Thanked 15 times in 9 posts
Default

Quote:
Originally Posted by bridenour View Post
cunparis,

i thought you had said you tried with a static variable but were not successful? thanks for the input!

br
I was not successful but it had nothing to do with the choice of static variable for GV. The reason I didn't succeed is because when you have several strategies accessing the same value there are timing issues. If you make a lock you have to synchronize the methods so that two strategies don't try to modify the lock at the same time. I eventually gave up because I determined that it's better to do my position sizing differently where I allocate a % of capital to each strategy.

It didn't take long to program but testing it took a long time. So my advice is re-examine your need for this and avoid it if possible. If you just want to communicate a msg between two strategies it's easy. but if you want to use some kind of lock where one strategy gets the lock and another strategy waits for it, then this is where it gets hard..
cunparis is offline  
Reply With Quote
Old 03-04-2009, 11:15 AM   #29
bridenour
Senior Member
 
Join Date: Jan 2009
Posts: 158
Thanks: 0
Thanked 0 times in 0 posts
Default

I just want to share an available balance among strategies. I have several distinct systems that trade reasonably infrequently, and to efficiently use my available funds I need it to be available cross strategy.

Unlike yours, mine is not all of none, so I need to recalculate and update the "available balance" each time an entry or exit occurs.

The odds of entries and exits happening simultaneously is rather low, so I think I might just give the static a shot and see how it plays out. Worst case it will try to open too many positions and likely get rejected due to margin limits.

Thanks for your feedback!
bridenour is offline  
Reply With Quote
Old 03-05-2009, 07:21 AM   #30
cunparis
Senior Member
 
Join Date: Feb 2008
Location: Paris
Posts: 733
Thanks: 15
Thanked 15 times in 9 posts
Default

Quote:
Originally Posted by bridenour View Post
I just want to share an available balance among strategies. I have several distinct systems that trade reasonably infrequently, and to efficiently use my available funds I need it to be available cross strategy.

Unlike yours, mine is not all of none, so I need to recalculate and update the "available balance" each time an entry or exit occurs.

The odds of entries and exits happening simultaneously is rather low, so I think I might just give the static a shot and see how it plays out. Worst case it will try to open too many positions and likely get rejected due to margin limits.

Thanks for your feedback!
Unless you're trading a very small account size, you will probably find with position sizing and a 2% risk that it's impossible to use all of your money. In this case you may not need to share the account balance.

If you are trading a small account size then you could re-examine the % risk you're taking.
cunparis 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 Development 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 11:19 PM


All times are GMT -6. The time now is 04:37 PM.

Futures, foreign currency and options trading contains substantial risk and is not for every investor. An investor could potentially lose all or more than the initial investment. Risk capital is money that can be lost without jeopardizing ones financial security or lifestyle. Only risk capital should be used for trading and only those with sufficient risk capital should consider trading. Past performance is not necessarily indicative of future results. View Full Risk Disclosure.

CFTC Rules 4.41 - Hypothetical or Simulated performance results have certain limitations, unlike an actual performance record, simulated results do not represent actual trading. Also, since the trades have not been executed, the results may have under-or-over compensated for the impact, if any, of certain market factors, such as lack of liquidity. Simulated trading programs in general are also subject to the fact that they are designed with the benefit of hindsight. No representation is being made that any account will or is likely to achieve profit or losses similar to those shown.

This website is hosted and operated by NinjaTrader, LLC (“NT”), a software development company which owns and supports all proprietary technology relating to and including the NinjaTrader trading platform. NT is an affiliated company to NinjaTrader Brokerage (“NTB”), which is a NFA registered introducing broker (NFA #0339976) providing brokerage services to traders of futures and foreign exchange products. This website is intended for educational and informational purposes only and should not be viewed as a solicitation or recommendation of any product, service or trading strategy. No offer or solicitation to buy or sell securities, securities derivative or futures products of any kind, or any type of trading or investment advice, recommendation or strategy, is made, given, or in any manner endorsed by any NT affiliate and the information made available on this Web site is not an offer or solicitation of any kind. Specific questions related to a brokerage account should be sent to your broker directly. The content and opinions expressed on this website are those of the authors and do not necessarily reflect the official policy or position of NT or any of its affiliates. 

Vendors along with their websites, products and services, collectively referred to as (“Vendor Content”), are independent persons or companies that are in no manner affiliated with NT or any if its affiliates. NT or any of its affiliates are not responsible for, do not approve, recommend or endorse any Vendor Content referenced on this website and it’s your sole responsibility to evaluate Vendor Content. Please be aware that any performance information provided by a vendor should be considered hypothetical and must contain the disclosures required by NFA Rule 2-29(c). If you are interested in learning more about, or investigating the quality of, any such Vendor Content you must contact the vendor, provider or seller of such Vendor Content. No person employed by, or associated with, NT or any of its affiliates is authorized to provide any information about any such Vendor Content.