• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Best way to code indicator output when using custom class as output

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Best way to code indicator output when using custom class as output

    I have a requirement for an indicator which identifies swing points, i.e. higher highs or lower lows on a bar chart. Coding it visually is done, and I now need to expose the list of swing points so I can access them in another indicator or strategy.

    The output is a dictionary of objects of my custom class, keyed by bar number.

    If I set up my strategy to work like this:

    Code:
    public class PermaCodeSwingState : Indicator
    {
        PermaCodeSwing swingIndy;
        
        protected override void Initialize() 
        {
            Overlay = true;
            CalculateOnBarClose = true;
            Add(PermaCodeSwing(2, 2, 20, 0.00001));
            swingIndy = PermaCodeSwing(2, 2, 20, 0.00001);    
        }
        
        protected override void OnBarUpdate()
        {
            swingIndy.Update();
            if (CurrentBars[0] < BarsRequired)
            {                
                return;
            }
            
        }
    I have to include that Update() call because otherwise the indicator doesn't update. This is the relevant part of the indie code, showing just instantiation of the SwingPoint for a swing high, and putting it in the dictionary:

    Code:
    private Dictionary<int, SwingPoint> swingHighs 
        = new Dictionary<int, SwingPoint>(), swingLows = new Dictionary<int, SwingPoint>();
    public class SwingPoint
    {
        public int before, after;
        public IBar bar;
        public int barNum;
        public IBar creationBar;
        public int creationBarNum;
        public DateTime creationTime;
        public SwingPoint(int newBefore, int newAfter, int swingBarNum, IBar swingBar, 
            int cb, IBar currentIBar)
        {
            this.before = newBefore;
            this.after = newAfter;
            this.bar = swingBar;
            this.barNum = swingBarNum;
            this.creationBar = currentIBar;
            this.creationBarNum = cb;
        }
    }
    protected override void OnBarUpdate()
    {
        if (isSwingHigh) 
        {
            SwingPoint swingPoint = new SwingPoint(before, after, 
                CurrentBar - swingBar, Bars.Get(CurrentBar - swingBar), 
                CurrentBar, Bars.Get(CurrentBar));
            swingHighs.Add(CurrentBar - swingBar, swingPoint);
        }
    }
    
    public Dictionary<int, SwingPoint> SwingHighs 
    {
        get { return swingHighs; }
    }
    My question is whether this way of doing it is going to be a performance killer compared to another way, maybe subclassing IDataSeries. I have an old recollection of discussing IDataSeries but I can't find any reference to subclassing it now online.

    Additionally I'm worried at this point that writing the swing points algorithm into a seperate indicator will also incur unnecessary overhead compared to writing it as a simple function in an NinjaTrader.Indicator partial class. Please advise.

    Thanks.

    #2
    An Dataseries interface would be more resource intensive as it is synced with each bar on the chart.

    If you only have a handful of swing points, a dictionary or list would be more efficient and easier to access these values.

    I have no advice on writing a new indicator or using a function. This would ultimately depend on how you're using it. They should both process the same amount of resources.
    MatthewNinjaTrader Product Management

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by mbesha, Today, 09:26 AM
    0 responses
    1 view
    0 likes
    Last Post mbesha
    by mbesha
     
    Started by Brillo, Today, 08:58 AM
    0 responses
    3 views
    0 likes
    Last Post Brillo
    by Brillo
     
    Started by avrege, Today, 01:48 AM
    2 responses
    9 views
    0 likes
    Last Post avrege
    by avrege
     
    Started by markbb10, Today, 07:14 AM
    0 responses
    6 views
    0 likes
    Last Post markbb10  
    Started by leodrz, Today, 05:09 AM
    0 responses
    9 views
    0 likes
    Last Post leodrz
    by leodrz
     
    Working...
    X