Architecture / Public Array / Instantiate - NinjaTrader Programming | futures io social day trading
futures io futures trading


Architecture / Public Array / Instantiate
Updated: Views / Replies:812 / 8
Created: by vantojo Attachments:3

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
 

Architecture / Public Array / Instantiate

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

Architecture / Public Array / Instantiate

Hello All,

(addressed to the more advanced coders...)

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.

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
Birmingham UK
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: IG/eSignal
Favorite Futures: Dax
 
ratfink's Avatar
 
Posts: 3,339 since Dec 2012
Thanks: 11,282 given, 7,092 received



vantojo View Post
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:
 
Code
public class OracItem
{
    public int value;
    public int port;
}
	
 
public static class Orac
{
    public static Dictionary<string, OracItem> Properties = new Dictionary<string, OracItem>();
    public static int localPort = 0;		// set to publishPort by Clients stays at zero for Servers unless inbound data
    public static string  Lock = "LOCK";
}

Will tidy/improve a few things in time, e.g. Lock as object, but it's fine. I'm simple.
The two main interface indicators are simple :

To set a value:
 
Code
    public class OracSet : Indicator
    {
        #region Variables
        // Wizard generated variables
            private string property = ""; // Default setting for Property
        // User defined variables (add any user defined variables below)
        #endregion

        /// <summary>
        /// This method is used to configure the indicator and is called once before any bar data is loaded.
        /// </summary>
        protected override void Initialize()
        {
            Overlay = true;
            CalculateOnBarClose = false;
			
            if (property != "")
            {
                lock (Orac.Lock)
                {
                    OracItem  oi;
					
                    if (!Orac.Properties.ContainsKey (property))
                    {
                        Orac.Properties.Add (property, new OracItem());
                    }
					
                    oi = Orac.Properties[property];
					
                    oi.port  = Orac.localPort;
                    oi.value = 0;
                }
            }
        }

        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            if (property != "")
            {
                 lock (Orac.Lock)
                {
                    Orac.Properties[property].value = (int) Close[0];
                }
            }
        }
To Plot a value:
 
Code
    public class OracPlot : Indicator
    {
        #region Variables
        // Wizard generated variables
            private string property = ""; // Default setting for Property
        // User defined variables (add any user defined variables below)
        #endregion

        /// <summary>
        /// This method is used to configure the indicator and is called once before any bar data is loaded.
        /// </summary>
        protected override void Initialize()
        {
            Add(new Plot(Color.FromKnownColor(KnownColor.SeaGreen), PlotStyle.Line, "Plot0"));

            Overlay = false;
            CalculateOnBarClose = false;
        }

        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            if (property != "")
            {
                int  value = 0;
				
                lock (Orac.Lock)
                {
                    if (Orac.Properties.ContainsKey (property))
                    {
                        value = Orac.Properties[property].value;
                    }
                }
				
                Plot0.Set(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

Travel Well

Last edited by ratfink; November 3rd, 2013 at 10:16 AM. Reason: p.s.
Reply With Quote
The following 2 users say Thank You to ratfink for this post:
 
  #4 (permalink)
Elite Member
Neuquen, Argentina
 
Futures Experience: Intermediate
Platform: Ninja
Favorite Futures: CL, TF, 6S, NG, sometimes GC
 
Posts: 195 since Jul 2012
Thanks: 25 given, 39 received

an example

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#



AATest.cs

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

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;
}

G[i].Enable_Voice = true;

G[i].AccountName = "";
G[i].Action = "";
G[i].ExitPosition = false;
G[i].Price = 0;
G[i].ATM_Name = "";
}

Print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>> END COMMON INITIALIZE >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");


}
#endregion


#region OnBarUpdate
protected override void OnBarUpdate()
{
}
#endregion


#region Properties
#endregion
}
}

Reply With Quote
 
  #6 (permalink)
Elite Member
Birmingham UK
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: IG/eSignal
Favorite Futures: Dax
 
ratfink's Avatar
 
Posts: 3,339 since Dec 2012
Thanks: 11,282 given, 7,092 received


vantojo View Post
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#

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.

Cheers

Travel Well
Reply With Quote
 
  #7 (permalink)
Elite Member
Birmingham UK
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: IG/eSignal
Favorite Futures: Dax
 
ratfink's Avatar
 
Posts: 3,339 since Dec 2012
Thanks: 11,282 given, 7,092 received


vantojo View Post
not sure how to insert code...this is the attachment

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.

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

reply

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...

C# is not my first language...

should it be something other than Static?

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

Way COOL....it works!!

to verify:

see attachments

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....

Attached Files
Register to download File Type: cs AATest.cs (2.3 KB, 27 views)
Register to download File Type: cs AATest2.cs (908 Bytes, 22 views)
Reply With Quote
The following 4 users say Thank You to vantojo for this post:

Reply



futures io > > > > > Architecture / Public Array / Instantiate

Thread Tools Search this Thread
Search this Thread:

Advanced Search



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

Jigsaw Trading: TBA

Elite only

FuturesTrader71: TBA

Elite only

NinjaTrader: TBA

Jan 18

RandBots: TBA

Jan 23

GFF Brokers & CME Group: Futures & Bitcoin

Elite only

Adam Grimes: TBA

Elite only

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
XAverage array in EasyLanguage Big Mike EasyLanguage Programming 13 December 16th, 2015 09:17 AM
Populate an Array with Pivot Points JHall65 MultiCharts 3 August 26th, 2013 11:22 PM
Filling an array with all trades done onava EasyLanguage Programming 5 April 27th, 2012 06:10 AM
US Architecture Billings Index Flat in March Quick Summary News and Current Events 0 April 20th, 2011 07:10 AM
Two dimensional array in EasyLanguage Big Mike EasyLanguage Programming 6 August 17th, 2010 07:23 PM


All times are GMT -4. The time now is 01:41 AM.

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-12-16 in 0.14 seconds with 20 queries on phoenix via your IP 23.22.136.56