Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Default (stock) @ADX indicator code

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

    Default (stock) @ADX indicator code

    Hello,

    I applied the ADX indie to a renko chart (lots of bars) and found performance somewhat lacking in fast moves. I took a look at the code. I noticed this

    Code:
            private Series<double>      dmPlus;
            private Series<double>      dmMinus;
            private Series<double>      sumDmPlus;
            private Series<double>      sumDmMinus;
            private Series<double>      sumTr;
            private Series<double>      tr;
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Description                 = NinjaTrader.Custom.Resource.NinjaScriptIndicatorDescriptionADX;
                    Name                        = NinjaTrader.Custom.Resource.NinjaScriptIndicatorNameADX;
                    IsSuspendedWhileInactive    = true;
                    Period                      = 14;
                    AddPlot(Brushes.DarkCyan,       NinjaTrader.Custom.Resource.NinjaScriptIndicatorNameADX);
                    AddLine(Brushes.SlateBlue,  25, NinjaTrader.Custom.Resource.NinjaScriptIndicatorLower);
                    AddLine(Brushes.Goldenrod,  75, NinjaTrader.Custom.Resource.NinjaScriptIndicatorUpper);
                }
                else if (State == State.DataLoaded)
                {
                    dmPlus      = new Series<double>(this);
                    dmMinus     = new Series<double>(this);
                    sumDmPlus   = new Series<double>(this);
                    sumDmMinus  = new Series<double>(this);
                    sumTr       = new Series<double>(this);
                    tr          = new Series<double>(this);
                }
            }​

    None of those series is actually required as the code appears to only ever use the [0] and [1] values.

    It would seem (and appears) much faster to simply use 2 variables, or as I changed it, private double[] tr = new double[1]; and just shift the values, e.g. tr[1] = tr[0]; on IsFirstTickOfBar.

    By my count, this saves at least 6 x 256 count series updating and shifting on each bar! Now, perhaps that is not a huge saving, but the original code does just seem somewhat wasteful of precious resources.

    Just a suggestion...

Latest Posts

Collapse

Topics Statistics Last Post
Started by Hwop38, 05-04-2026, 07:02 PM
0 responses
152 views
0 likes
Last Post Hwop38
by Hwop38
 
Started by CaptainJack, 04-24-2026, 11:07 PM
0 responses
305 views
0 likes
Last Post CaptainJack  
Started by Mindset, 04-21-2026, 06:46 AM
0 responses
244 views
0 likes
Last Post Mindset
by Mindset
 
Started by M4ndoo, 04-20-2026, 05:21 PM
0 responses
345 views
0 likes
Last Post M4ndoo
by M4ndoo
 
Started by M4ndoo, 04-19-2026, 05:54 PM
0 responses
176 views
0 likes
Last Post M4ndoo
by M4ndoo
 
Working...
X