• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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.
    Patrick H.NinjaTrader Customer Service

    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 Cyanez, Today, 08:41 AM
          0 responses
          1 view
          0 likes
          Last Post Cyanez
          by Cyanez
           
          Started by TonyParisi, Today, 07:38 AM
          1 response
          7 views
          0 likes
          Last Post NinjaTrader_Kate  
          Started by tgn55, 09-24-2019, 06:34 AM
          13 responses
          48 views
          0 likes
          Last Post NinjaTrader_Jim  
          Started by jasphere, Today, 07:37 AM
          4 responses
          20 views
          0 likes
          Last Post jasphere  
          Started by w0lverine, Today, 07:06 AM
          1 response
          7 views
          0 likes
          Last Post NinjaTrader_PaulH  
          Working...
          X