Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Indicator of Custom Indicator

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

    Indicator of Custom Indicator

    Hi,

    I am creating an indicator based on Real time tick data. The indicator calculates average price of each bar. The indicator works fine stand alone.
    When i use indicator on that indicator example EMA of the my custom indicator i could not get the values.
    Code:
    Print("Strategy "+ MyTestIndicator()[0]+"  "+ MyTestIndicator()[1]+"  "+EMA(MyTestIndicator().WP,5)[0]);
    I am getting the result as "Strategy 129.972837802219 129.946845515136 NaN"

    i have attached the indicator cs file for your reference.
    can you let me know what i am missing
    Attached Files

    #2
    Hello investic,

    Thank you for your post and welcome to the NinjaTrader Support Forum!

    The indicator will only need to be passed and not it's plot. For example:
    Code:
    EMA(MyTestIndicator(),5)[0]
    Please let me know if you have any questions.

    Comment


      #3
      Originally posted by investic View Post
      Hi,

      I am creating an indicator based on Real time tick data. The indicator calculates average price of each bar. The indicator works fine stand alone.
      When i use indicator on that indicator example EMA of the my custom indicator i could not get the values.
      Code:
      Print("Strategy "+ MyTestIndicator()[0]+"  "+ MyTestIndicator()[1]+"  "+EMA(MyTestIndicator().WP,5)[0]);
      I am getting the result as "Strategy 129.972837802219 129.946845515136 NaN"

      i have attached the indicator cs file for your reference.
      can you let me know what i am missing
      Regardless of any other issue, you have this line in your OBU.
      WP.Set(TotalValue/TotalVolume);
      You have not handled the case when TotalVolume is zero, so you are sometime or the other going to come a cropper on a "division by zero" error. It sometimes shows up as a NaN (Not A Number) error. At other times, it just causes an exception that stops the processing.

      Comment


        #4
        Thanks koganam,

        I am getting divide by zero exception in the first bar calculation , addressing it makes the EMA working.

        As a follow up to MyTestindicator, its calculating the indicator after bar close. so the totalvalue and totalvolume should have values. Lets assume

        when currentbar == 0 and Totalvalue = 100000 and Totalvolume = 1000 then indicator value will be 100

        the next bar
        when currentbar == 1 and Totalvalue = 99000 and Totalvolume = 1000 then indicator value will be 99

        the next bar (same as currentbar > 1 as in the indicator)
        when currentbar == 2 and Totalvalue = 98000 and Totalvolume = 1000 then indicator value will be 98

        In all the scenarios totalvalue and totalvolume has values. in that case how come zero exception happens.

        Is my understanding correct.
        As a note i have set Barsrequired= 1

        Comment


          #5
          Hello,

          Thank you for the question.

          I am unsure if the question here is still relevant regarding the first script you had posted.

          If you are still using the script from post #1, on bar 0 both values are assigned the value of 0, so they would be dividing by 0. The assignment comes later in the script during live market data so this would produce a NaN value until live market data has assigned values to the two variables.

          If the original script has been modified, please post the updated copy so I can address the current issue.

          I look forward to being of further assistance.
          JesseNinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by bortz, 11-06-2023, 08:04 AM
          47 responses
          1,602 views
          0 likes
          Last Post aligator  
          Started by jaybedreamin, Today, 05:56 PM
          0 responses
          8 views
          0 likes
          Last Post jaybedreamin  
          Started by DJ888, 04-16-2024, 06:09 PM
          6 responses
          18 views
          0 likes
          Last Post DJ888
          by DJ888
           
          Started by Jon17, Today, 04:33 PM
          0 responses
          4 views
          0 likes
          Last Post Jon17
          by Jon17
           
          Started by Javierw.ok, Today, 04:12 PM
          0 responses
          12 views
          0 likes
          Last Post Javierw.ok  
          Working...
          X