Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
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?
Thank you.
Can you help answer these questions from other members on NexusFi?
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?
Cheers.
p.s. seem to remember there was something else about global variables on futures.io (formerly BMT) too but that might be TradeStation
Thanks RF....here is what I'm thinking..something like this (attachment)...but I need to access globally, in all objects, the array that was instantiated in this indicator, in the Initialize.
I would love to not have to have code to init the array...but it appears this is the only way it can be done in C#
not sure how to insert code...this is the attachment
==================================================================
#region Using declarations
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Gui.Chart;
#endregion
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;
};
}
namespace NinjaTrader.Indicator
{
public class AATest : Indicator
{
#region Variables
public static Instrument_Parameters[] G;
#endregion
#region Initialize
protected override void Initialize()
{
Print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>> BEGIN COMMON INITIALIZE >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
Overlay = false;
G = new Instrument_Parameters[12];
for (int i = 0; i<=11; i++)
{
G[i].ix = i;
G[i].Instrument = "";
switch (i)
{
case 0:
G[i].Instrument = "CL";
break;
case 1:
G[i].Instrument = "GC";
break;
case 2:
G[i].Instrument = "NG";
break;
case 3:
G[i].Instrument = "TF";
break;
case 4:
G[i].Instrument = "6S";
break;
case 5:
G[i].Instrument = "6A";
break;
case 6:
G[i].Instrument = "6E";
break;
case 7:
G[i].Instrument = "NQ";
break;
}
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.
For code inserts you just use the word CODE and then /CODE in square boxes as you would for QUOTE - just try making a Quote Reply of my post and look inside to see for a test.
Yes, that is right....I don't want to do any I-O or function calls to access the data, just simply a variable reference.
this is because there will be multiple objects accessing this data, and on each tic of data...so it needs to be as simple, fast, and direct as possible.....
I think I tried having G in global...will try again...but I believe it would not compile...
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....