C# question -- public static methods - NinjaTrader Programming | futures io social day trading
futures io futures trading


C# question -- public static methods
Updated: Views / Replies:121 / 8
Created: by vantojo Attachments:0

Welcome to futures io.

(If you already have an account, login at the top of the page)

futures io is the largest futures trading community on the planet, with over 90,000 members. At futures io, our goal has always been and always will be to create a friendly, positive, forward-thinking community where members can openly share and discuss everything the world of trading has to offer. The community is one of the friendliest you will find on any subject, with members going out of their way to help others. Some of the primary differences between futures io and other trading sites revolve around the standards of our community. Those standards include a code of conduct for our members, as well as extremely high standards that govern which partners we do business with, and which products or services we recommend to our members.

At futures io, our focus is on quality education. No hype, gimmicks, or secret sauce. The truth is: trading is hard. To succeed, you need to surround yourself with the right support system, educational content, and trading mentors Ė all of which you can find on futures io, utilizing our social trading environment.

With futures io, you can find honest trading reviews on brokers, trading rooms, indicator packages, trading strategies, and much more. Our trading review process is highly moderated to ensure that only genuine users are allowed, so you donít need to worry about fake reviews.

We are fundamentally different than most other trading sites:
  • We are here to help. Just let us know what you need.
  • We work extremely hard to keep things positive in our community.
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts.
  • We firmly believe in and encourage sharing. The holy grail is within you, we can help you find it.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.

You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

Reply
 
Thread Tools Search this Thread
 

C# question -- public static methods

  #1 (permalink)
Elite Member
Neuquen, Argentina
 
Futures Experience: Intermediate
Platform: Ninja
Favorite Futures: CL, TF, 6S, NG, sometimes GC
 
Posts: 179 since Jul 2012
Thanks: 22 given, 39 received

C# question -- public static methods

Hello,

for NT7.

I have shared routines between different indicators, even strategies.

I've created a new .cs file in the Indicator folder with it's own "namespace AAGlobal" and "public class Methods". Then inside this are the individual methods. The Ninja editor opens this "Indicator" and it compiles fine.

The methods in this class I have defined as "public static", and these can be referenced successfully (i.e. compiled) in other Indicators and Strategies when referenced with using AAGlobal and then qualifying the method in the calling statement.
"
My question is....what happens if multiple indicators and strategies execute this code at "the same time"?

Would it be better to not have the methods declared "static", and instantiate the method in the calling program?

Thanks

Reply With Quote
 
  #2 (permalink)
Quick Summary
Quick Summary Post

Quick Summary is created and edited by users like you... Add FAQ's, Links and other Relevant Information by clicking the edit button in the lower right hand corner of this message.

 
  #3 (permalink)
Elite Member
Omer עומר / Israel י
 
Futures Experience: Master
Platform: NinjaTrader, Proprietary,
Broker/Data: Ninjabrokerage/IQfeed + Synthetic datafeed
Favorite Futures: 6A, 6B, 6C, 6E, 6J, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
 
rleplae's Avatar
 
Posts: 2,321 since Sep 2013
Thanks: 1,629 given, 3,429 received
Forum Reputation: Legendary



vantojo View Post
Hello,

for NT7.

I have shared routines between different indicators, even strategies.

I've created a new .cs file in the Indicator folder with it's own "namespace AAGlobal" and "public class Methods". Then inside this are the individual methods. The Ninja editor opens this "Indicator" and it compiles fine.

The methods in this class I have defined as "public static", and these can be referenced successfully (i.e. compiled) in other Indicators and Strategies when referenced with using AAGlobal and then qualifying the method in the calling statement.
"
My question is....what happens if multiple indicators and strategies execute this code at "the same time"?

Would it be better to not have the methods declared "static", and instantiate the method in the calling program?

Thanks

Theorethically you would run into a multi-threading issue, but i thin NT7 is not that much of a multi-threading beast
you would then have to put locks around critical sections

What was the reason to make those things 'static' in the first place ?

Another pattern is to use the singleton, if you really need multiple threads to share the same thing...

Depends what nut you want to crack

Reply With Quote
 
  #4 (permalink)
Elite Member
Neuquen, Argentina
 
Futures Experience: Intermediate
Platform: Ninja
Favorite Futures: CL, TF, 6S, NG, sometimes GC
 
Posts: 179 since Jul 2012
Thanks: 22 given, 39 received

Ok


rleplae View Post
Theorethically you would run into a multi-threading issue, but i thin NT7 is not that much of a multi-threading beast
you would then have to put locks around critical sections

What was the reason to make those things 'static' in the first place ?

Another pattern is to use the singleton, if you really need multiple threads to share the same thing...

Depends what nut you want to crack

Ok, that is what I wanted to know...the potential for collision....I will remove the "static" and instantiate each use....multiple indicators or strategies may want to execute some of these common routines "at the same time", more or less.

Other methods are preferred to be static because they manage global (public) static variables and will only be called by one instance of one class when the workspaces first load.

Reply With Quote
 
  #5 (permalink)
Seth
Salt Lake City, Utah
 
Futures Experience: Beginner
Platform: Jigsaw, NinjaTrader8
Favorite Futures: ZB
 
Posts: 317 since Apr 2016
Thanks: 13 given, 263 received


vantojo View Post
Hello,

for NT7.

I have shared routines between different indicators, even strategies.

I've created a new .cs file in the Indicator folder with it's own "namespace AAGlobal" and "public class Methods". Then inside this are the individual methods. The Ninja editor opens this "Indicator" and it compiles fine.

The methods in this class I have defined as "public static", and these can be referenced successfully (i.e. compiled) in other Indicators and Strategies when referenced with using AAGlobal and then qualifying the method in the calling statement.
"
My question is....what happens if multiple indicators and strategies execute this code at "the same time"?

Would it be better to not have the methods declared "static", and instantiate the method in the calling program?

Thanks

There is nothing wrong with this. Both processes can access the same piece of code at the same time. The execution code is basically just a location in memory, and both call stacks point to the same location.

It's data where you can run into concurrency issues. For instance, if you are using the singleton pattern you can have different pieces of code modifying the same variables.

Reply With Quote
 
  #6 (permalink)
Elite Member
Omer עומר / Israel י
 
Futures Experience: Master
Platform: NinjaTrader, Proprietary,
Broker/Data: Ninjabrokerage/IQfeed + Synthetic datafeed
Favorite Futures: 6A, 6B, 6C, 6E, 6J, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
 
rleplae's Avatar
 
Posts: 2,321 since Sep 2013
Thanks: 1,629 given, 3,429 received
Forum Reputation: Legendary


TWDsje View Post
There is nothing wrong with this. Both processes can access the same piece of code at the same time. The execution code is basically just a location in memory, and both call stacks point to the same location.

It's data where you can run into concurrency issues. For instance, if you are using the singleton pattern you can have different pieces of code modifying the same variables.

If two threads access the same data (in true multi-threading), then you DO have an issue
but i think NT 7/8 does NT execute in real multi-threading

In my code outside NT i need to keep an eye on that, or you get an exception...

Reply With Quote
 
  #7 (permalink)
Elite Member
Neuquen, Argentina
 
Futures Experience: Intermediate
Platform: Ninja
Favorite Futures: CL, TF, 6S, NG, sometimes GC
 
Posts: 179 since Jul 2012
Thanks: 22 given, 39 received

............

I have a custom architecture that when NT boots and the primary workspace opens, one process (running from Market Analyzer) reads a SQL database and loads public static arrays and variables with control/configuration/news data.

Then, later multiple other processes when they are started, read this global data (arrays/variables) and load selected information they need for processing into local process variables.

Sometimes these secondary processes (indicators, strategies), write back status information into the global static arrays/variables to be shared with any process that needs it.

Having the main boot process in the Market Analyzer (against one instrument) was the only way I could figure out in NT to have a boot process load system wide, shared data. It works, but it was not really what I wanted to do.

Reply With Quote
 
  #8 (permalink)
Seth
Salt Lake City, Utah
 
Futures Experience: Beginner
Platform: Jigsaw, NinjaTrader8
Favorite Futures: ZB
 
Posts: 317 since Apr 2016
Thanks: 13 given, 263 received


rleplae View Post
If two threads access the same data (in true multi-threading), then you DO have an issue
but i think NT 7/8 does NT execute in real multi-threading

In my code outside NT i need to keep an eye on that, or you get an exception...

Yes as I said if two threads are accessing the same variables then you could have problems. This is why singletons become relevant at this point. There are many suggestions about how to write singletons to avoid these kinds of issues. Just search for C# Singletons.

Reply With Quote
 
  #9 (permalink)
Elite Member
Omer עומר / Israel י
 
Futures Experience: Master
Platform: NinjaTrader, Proprietary,
Broker/Data: Ninjabrokerage/IQfeed + Synthetic datafeed
Favorite Futures: 6A, 6B, 6C, 6E, 6J, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
 
rleplae's Avatar
 
Posts: 2,321 since Sep 2013
Thanks: 1,629 given, 3,429 received
Forum Reputation: Legendary


TWDsje View Post
Yes as I said if two threads are accessing the same variables then you could have problems. This is why singletons become relevant at this point. There are many suggestions about how to write singletons to avoid these kinds of issues. Just search for C# Singletons.

My understanding of a singleton is to have a class that instantiates to the same instance
so that two processes calling the class, are using the same data.

I used it in a trading risk module that is implemented as a DLL and shared by multiple threads

Reply With Quote

Reply



futures io > > > > > C# question -- public static methods

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)

FuturesTrader71: TBA

Elite only

Al Brooks: TBA

Elite only

Jigsaw Trading: TBA

Oct 19

RandBots: TBA

Oct 24
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
Ninja Trader and Static DOM jodistrict NinjaTrader 2 October 2nd, 2015 03:23 PM
Identify Last [right-most] Candle on Static Chart Webby NinjaTrader 1 March 11th, 2014 07:42 AM
Static V Dynamic Dom dee50 NinjaTrader 16 October 17th, 2012 12:24 AM
Dynamic and static bars indicator esam_jir NinjaTrader Programming 1 March 2nd, 2012 07:22 PM
chat archive not static doug Feedback and Announcements 2 August 12th, 2009 01:40 PM


All times are GMT -4. The time now is 11:21 PM.

Copyright © 2017 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
All information is for educational use only and is not investment advice.
There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
no new posts
Page generated 2017-09-23 in 0.09 seconds with 18 queries on phoenix via your IP 54.162.218.214