I have an architecture that uses Public variables to communicate between decoupled indicators and strategies, or between two indicators. This allows me more flexibility and modularity than binding say, an indicator to a strategy.
This works fine as long as long as I only want to communicate between two or more objects (indicators/strategies) that are working on the exact same Instrument.
However, I need to take it to the next step...and have this work for multiple instruments.
My goal is to create a dynamic real time pool of in-memory public data for each instrument I monitor that can be accessed by any executing object.
I want this data to be available simply through public variables, and not say, an external source, like an in-memory SQL datastore. (I don't want to issue an I-O just to get the variables, on each tick the pool needs to be immediately available.)
I have this implemented (for a single instrument) by way of a non executing indicator with a Public variables. I call it Common.
It would be so simple to put in a public array or list, with each entry in the list being a structure for a specific instrument.
However, unlike the public variables I use now, and are available to all executing objects without the Common Indicator even being executed, lists and arrays are not instantiated until run time.
This indicator is a global store, and not tied to any instrument, strategy, or indicator. It is not executed.
I don't know how to get around this issue in what I know about Ninja....any ideas?
I use a public SortedDictionary for exactly this purpose, properties are basically ascii strings with int values (could be doubles instead, I will probably switch this at some stage). Properties can be added from anywhere and referenced from anywhere across charts or workspaces. I also have a network distributed system on top of it, so I know the mechanism is reliable. I am contemplating extending it to use DataSeries in the Properties but have not done so yet as I am currently more interested in discretionary than automated trading.
As I was a massive fan of Blake's 7 it is obviously called Orac ...
Basic data constructs:
The two main interface indicators are simple :
To set a value:
To Plot a value:
Using this route it's easy to set/plot indicators across charts/workspace from any standard Ninja Data series or Indy series using the standard user interaction. But as yet I don't support historical data, that's the biggest current limitation, happy to think about the future if there is more general interest in this area or maybe that is enough idea to help?
p.s. seem to remember there was something else about global variables on futures.io (formerly BMT) too but that might be TradeStation
Last edited by ratfink; November 3rd, 2013 at 09:16 AM.
The following 2 users say Thank You to ratfink for this post:
not sure how to insert code...this is the attachment
#region Using declarations
public class Global
public struct Instrument_Parameters
public int ix;
public string Instrument;
public bool Enable_Voice;
public string AccountName;
public string Action;
public bool ExitPosition;
public double Price;
public string ATM_Name;
public class AATest : Indicator
public static Instrument_Parameters G;
protected override void Initialize()
Print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>> BEGIN COMMON INITIALIZE >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
Overlay = false;
G = new Instrument_Parameters;
for (int i = 0; i<=11; i++)
G[i].ix = i;
G[i].Instrument = "";
G[i].Instrument = "CL";
G[i].Instrument = "GC";
G[i].Instrument = "NG";
G[i].Instrument = "TF";
G[i].Instrument = "6S";
G[i].Instrument = "6A";
G[i].Instrument = "6E";
G[i].Instrument = "NQ";
You should be able to move 'G' into the Global class itself, it can then be referenced as Global.G[i].xxxxx, etc everywhere.
I guess you could also have the init code simplified into a seperate routine that just takes a string as parameter for the instrument name, as the rest of the init values appear to be common. I don't see a big deal to worry about having a dynamic rather than static init really, unless you need lots of instruments. I'm not a comprehensive C# expert so I'm sure there probably are many other ways as well that I just don't use.
For my own stuff I use a dynamic file reader/loader to read and Add instrument lists into multi-instrument indicators/strategies but unless I misunderstood I don't think that is what you are asking.
load AATest into a Market Analyzer
and AATest2 onto a chart
when the Market Analyzer initializes AATest will instantiate the global array
every time there is a new bar AATest2 will access the global array created in AATest Initialize and print (all of) one of the array elements. Will test more later to make sure AATest2 can write into the global array.
If this works it is going to allow me to do what I need to do....have a memory based array of data available across all unbound indicators and strategies, and a way for them to share state data.
Then no need to bind objects, or for I-O (even to memory based stores) OR functions or methods to get/store data from/into the array.
Thank you Ratfink for the comraderie!!! It helped....
The following 4 users say Thank You to vantojo for this post: