Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Custom Indicator - Similar to ADL

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

    Custom Indicator - Similar to ADL

    Hi,

    I am trying to build a custom indicator, one that appears to be similar to an ADL indicator. I say ADL because the A-D Line sums the current MF Value with the preceding A-D Line to get the current A-D Line.

    My indicator, call it the ABC Line, does the following:

    (Close[0] - Close[1]) * 10000 = Net
    ((Net - ABC Line[1]) *0.5) + ABC Line[1] = Current ABC Line


    The Variables code for ADL is: AD.Set((CurrentBar == 0 ? 0 : AD[1]) + (High[0] != Low[0] ? (((Close[0] - Low[0]) - (High[0] - Close[0])) / (High[0] - Low[0])) * Volume[0] : 0));




    Thus wouldn't my ABC code be:

    ABC.Set((CurrentBar == 0 ? 0 : ABC[1]) + (High[0] != Low[0] ? ((((Close[0] - Close[1]) * 10000) - ABC[1]) * 0.5): 0));


    Currently if I add this to a chart there are no values appearing.
    Please advise on how to fix, thank you



    #2
    Hello Scarlett09,

    Your syntax looks correct. Do you get an error inside the Log tab of the Control Center?

    Happy to be of further assistance.
    JCNinjaTrader Customer Service

    Comment


      #3
      Yes, I am receiving the following error:

      Error on calling 'OnBarUpdate' method for indicator 'test' on bar 0: You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.


      I have 21 days of data on my intra-day chart thus there should be plenty of data to equate.

      Comment


        #4
        Hello Scarlett09,

        This error is because in "OnBarUpdate()" is trying to access the data series that does not exist yet or have enough bars to calculate. More information about making sure you have enough bars can be found at the following link.



        This can be fixed by adding in a check to "CurrentBar" to make sure we have enough for the calculations in "OnBarUpdate()". Example:


        Code:
        protected override void OnBarUpdate()
        {
                if(CurrentBar < 5)
                {
                          return;
                }
        //Rest of your code
        }

        The "if(CurrentBar < 5)" makes sure that there is at least 5 bars worth of data before starting your calculation. This ensures that we are not trying to access data that has not been created yet.


        Let us know if we can be of further assistance.
        JCNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        656 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        371 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        109 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        574 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        579 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X