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 CarlTrading, 03-31-2026, 09:41 PM
        1 response
        67 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        36 views
        0 likes
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        60 views
        1 like
        Last Post CaptainJack  
        Started by CarlTrading, 03-30-2026, 11:51 AM
        0 responses
        62 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 03-30-2026, 11:48 AM
        0 responses
        53 views
        0 likes
        Last Post CarlTrading  
        Working...
        X