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 sjsj2732, Today, 04:31 AM
0 responses
20 views
0 likes
Last Post sjsj2732  
Started by NullPointStrategies, 03-13-2026, 05:17 AM
0 responses
280 views
0 likes
Last Post NullPointStrategies  
Started by argusthome, 03-08-2026, 10:06 AM
0 responses
279 views
0 likes
Last Post argusthome  
Started by NabilKhattabi, 03-06-2026, 11:18 AM
0 responses
130 views
1 like
Last Post NabilKhattabi  
Started by Deep42, 03-06-2026, 12:28 AM
0 responses
90 views
0 likes
Last Post Deep42
by Deep42
 
Working...
X