NeoTicker Indicator JukeBox
Posted: Wed Jun 27, 2007 5:17 pm
NeoTicker Indicator JukeBox
Hello, friends,
many of you have been asking me about what's the easiest way to write an IDL indicator in NeoTicker that retains its values - and generally its entire environment - between bars/ticks and individual instances of the same indicator.
The above task is fairly easy if you're not planning to have multiple instances of the same indicator applied to the same or different hosts (time charts, quote windows etc.). You simply use a class-level object.
The snag in the class-level objects, though, is that a NeoTicker IDL indicator is a class that is instantiated only once regardless of the actual number of individual instances of the same indicator applied to your function windows. All indicator instances then share the same class-level environment.
An obvious solution to this trouble is to set up a unique environment for every individual indicator instance. Every individual indicator instance is then granted access only to its own environment: its individual set of class-level objects.
I have been using this approach all the time, but I have never published it. Now I've written a standardized object for dealing with this issue and everyone can easily deploy this solution into his or her own IDL indicator code with minimal effort.
I'm calling this solution a NeoTicker Indicator JukeBox. When the indicator is first called, its class is being instantiated with an empty jukebox of songs (class level objects specific to an individual indicator instance). Then a new song is added to the jukebox for every individual indicator instance. Every song has got its unique ID, so the individual indicators know which song is theirs in the jukebox A song holds a unique environment for every unique instance of the same indicator.
How to add JukeBox to your project:
Simple and elegant isn't it? Way more versatile then NeoTicker's builtin heaps.
Attached you will find the KreslikLib.Neo.JukeBox.DLL, example and the source code.
Michal
Hello, friends,
many of you have been asking me about what's the easiest way to write an IDL indicator in NeoTicker that retains its values - and generally its entire environment - between bars/ticks and individual instances of the same indicator.
The above task is fairly easy if you're not planning to have multiple instances of the same indicator applied to the same or different hosts (time charts, quote windows etc.). You simply use a class-level object.
The snag in the class-level objects, though, is that a NeoTicker IDL indicator is a class that is instantiated only once regardless of the actual number of individual instances of the same indicator applied to your function windows. All indicator instances then share the same class-level environment.
An obvious solution to this trouble is to set up a unique environment for every individual indicator instance. Every individual indicator instance is then granted access only to its own environment: its individual set of class-level objects.
I have been using this approach all the time, but I have never published it. Now I've written a standardized object for dealing with this issue and everyone can easily deploy this solution into his or her own IDL indicator code with minimal effort.
I'm calling this solution a NeoTicker Indicator JukeBox. When the indicator is first called, its class is being instantiated with an empty jukebox of songs (class level objects specific to an individual indicator instance). Then a new song is added to the jukebox for every individual indicator instance. Every song has got its unique ID, so the individual indicators know which song is theirs in the jukebox A song holds a unique environment for every unique instance of the same indicator.
How to add JukeBox to your project:
- you add a reference to the KreslikLib.Neo.JukeBox.DLL to your IDL project and then modify the code of your IDL indicator entry point class as follows:
Code: Select all
public class EntryPointClass : IDLIndicator
{
NTIndicatorJukeBox<MyIndicatorClass> JukeBox;
public EntryPointClass()
{
JukeBox = new NTIndicatorJukeBox<MyIndicatorClass>();
}
public double IDLCallEx(NTIndicatorObjects N)
{
return JukeBox.IDLCallSong(N);
}
}
MyIndicatorClass in the above code is your original IDL indicator class that must inherit a Song class, as it's the song that your individual indicator instance will be accessing in the jukebox . Also, your original IDL indicator class no longer inherits the IIDLindicator interface. - otherwise, your original indicator's code stays the same, except:
- instead of having IDLCallEx() method as an entry point to your indicator, there's an IDLCall() method. I renamed that in order to prevent confusion as this IDLCall() method in your indicator is no longer called by NeoTicker directly
- instead of having accessor public for the IDLCall() method, there's an additional override accessor. I wanted to make sure this method is overriden by the programmer, so I used an abstract member in a parent class
- an example of an implementation in a simple IDL indicator:
Code: Select all
public class MyIndicatorClass : Song
{
double HighestHigh = 0;
double CurrentHigh;
public override double IDLCall(NTIndicatorObjects N)
{
CurrentHigh = N.LinkSeries().get_Items(1).get_High(0);
HighestHigh = CurrentHigh > HighestHigh ? CurrentHigh : HighestHigh;
return HighestHigh;
}
}
Code: Select all
using Interop.NeoTicker;
using System.Collections;
using System.Reflection;
using System;
namespace KreslikLib.Neo.JukeBox
{
public class NTIndicatorJukeBox<T> where T : Song
{
private ArrayList Songs;
private int SongIndex;
private int UniqueID;
public NTIndicatorJukeBox()
{
Songs = new ArrayList();
}
public double IDLCallSong(NTIndicatorObjects N)
{
UniqueID = N.ItSelf().UniqueId;
SongIndex = GetSongIndexByID(UniqueID);
if (SongIndex < 0)
{
Type songType = typeof(T);
T newSong = (T)songType.InvokeMember(songType.Name,
BindingFlags.CreateInstance | BindingFlags.Instance | BindingFlags.Public,
null, null, null);
SongIndex = Songs.Add(newSong);
((Song)Songs[SongIndex]).UniqueID = UniqueID;
}
return ((Song)Songs[SongIndex]).IDLCall(N);
}
private int GetSongIndexByID(int ID)
{
for (int i = 0; i < Songs.Count; i++)
{
if (Songs[i] != null && ((Song)Songs[i]).UniqueID == ID)
{
return i;
}
}
return -1;
}
}
public abstract class Song
{
private int uniqueID;
public int UniqueID
{
get { return uniqueID; }
set { uniqueID = value; }
}
public abstract double IDLCall(NTIndicatorObjects N);
}
}
Simple and elegant isn't it? Way more versatile then NeoTicker's builtin heaps.
Attached you will find the KreslikLib.Neo.JukeBox.DLL, example and the source code.
Michal