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

Output value after comparison

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

    Output value after comparison

    Hi All,

    I am new to programming and am trying to update my first basic indicator which checks to see whether the end of day close (I am connecting to Yahoo) is below the bottom Bollinger band. If that is the case then I need the output to be shown as a value of -1. I then plan to use this value in the market analyser to filter on stocks which have this value.

    I am hoping that one you kind souls may be able to give me some pointers or perhaps point me to similar code in another indicator which I can adapt.

    Many thanks in advance.

    Evan

    #2
    Hello Evan, and welcome to NinjaTrader and the support forums!

    I have prepared a short video which demonstrates creating and using the strategy you mentioned. Please don't hesitate to reach out with any more questions. We are always excited to have new coders in our community.

    Free online storage and sharing with Screencast.com. 2 GB of storage and 2 GB of bandwidth per month for free. We won't compress, alter or take ownership of your content.
    Jessica P.NinjaTrader Customer Service

    Comment


      #3
      Many thanks for your quick response Jessica and for providing the very useful video. I was hoping to be able output the value so that I can pull in the indicator value into the Market Analyzer.

      My understanding is that I can't use a strategy in the market analyser or is my understanding incorrect.

      I presume therefore I can take a look at the code generated automatically after having used the wizard and then copy and paste it into the custom indicator I set up. I presume this is what you were expecting me to do, which is exactly what I was hoping to be able to do.

      Please let me know if my understanding is correct.

      Many thanks,

      Evan

      Comment


        #4
        I decided to crack on and copy the pertinent code into my indicator. I have tried outputting the code as a window output and as a variable output but in both cases I get an error when compiling the code in my custom indicator. It seems that it doesn't like the fact that I am using the variable and probably haven't declared it higher up in the code. The specific error message I get is: The name 'Variable0' does not exist in the current context.
        I have reviewed the code for the custom strategy but I can't find the declaration of the variable or at least it isn't obvious to me.

        Hopefully Jessica or someone else can assist me further.

        Many thanks,

        Evan

        Comment


          #5
          We will be happy to help in any way we can.

          One thing you may have noticed is that the strategy wizard is a lot more robust than the indicator wizard. One great strategy for generating NinjaScript (C#) code that you can use in your indicators, is to set up your logic the way you would like it in the strategy wizard, followed by pressing the "View Code" button in the lower left hand corner. A lot of the code in your Initialize and OnBarUpdate sections can be copied right into your indicator.

          That said, if you could attach a copy of the NinjaScript source you are working with - in your filesystem, this is located in (My) Documents\NinjaTrader 7\bin\Custom\Indicator - we will be happy to attempt to assist further.

          By the way, if you want a value such as -1 to show up on a chart or in the Market Analyzer, you will need to set the indicator's

          Values[0][0]

          member to the value you would like to output.
          Jessica P.NinjaTrader Customer Service

          Comment


            #6
            Thanks for getting back to me Jessica and for the quick responses and assistance.

            I managed to get through the error by declaring the variable and also updating the output looking at the code of another standard indicator.

            When I look at my indicator in a chart it behaves as expected. In other words I see a value of -1 plotted when the day's close is below the lower Bollinger band. I see no value when it does not meet the condition (above the lower Bollinger band). So all good there.

            The problem is that when I use my indicator in the Market Analyser it seems to be bringing back the last close of the share price. I am expecting to see a whole load of blanks with occasional values of -1. So either the Market Analyser is not using the latest code (I have removed and reinserted my custom indicator into the Market Analyser and also reloaded the code by right-clicking in the Market Analyser).

            I have attached the file with the code for the indicator and have also attached a screen shot of the settings I am using in the Market Analyser. I suspect that it might be the settings for my indicator in the Market Analyser.

            Hopefully you will be able to spot where I am going wrong.

            Many thanks,

            Evan
            Attached Files

            Comment


              #7
              It looks like what has occurred is that you have found a default value - the closing price - that shows up in the Market Analyzer column when you do not specify one.

              Typically when programming, unspecified behavior results in a program crash. This makes it very easy for programmers to fix code, since the program stops right where the problem occurred, and a record of what the program was doing called the stack trace is made available that tells programmers as much information as possible about where in their code the crash was caused. The program continuing to act would otherwise destroy valuable debugging information. However, sometimes as is the case here a crash would be undesirable, and so to prevent the program from crashing, a default value is used.

              I am returning a copy of your indicator with these lines added :

              Code:
              else[FONT=Courier New]
              {
                  Value.Set(0.0);
              }[/FONT]
              As you will be able to see, you will now have either -1 or 0 in your market analyzer column.
              Attached Files
              Jessica P.NinjaTrader Customer Service

              Comment


                #8
                Many thanks Jessica for your guidance and solutions to my queries. That makes perfect sense and I understand totally now. I have updated the code and it works perfectly in the Market Analyser. Now I can create further indicators based on the methods and tools you have shown me. It is much appreciated.

                Many thanks,

                Evan

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by algospoke, Yesterday, 06:40 PM
                2 responses
                23 views
                0 likes
                Last Post algospoke  
                Started by ghoul, Today, 06:02 PM
                3 responses
                14 views
                0 likes
                Last Post NinjaTrader_Manfred  
                Started by jeronymite, 04-12-2024, 04:26 PM
                3 responses
                45 views
                0 likes
                Last Post jeronymite  
                Started by Barry Milan, Yesterday, 10:35 PM
                7 responses
                21 views
                0 likes
                Last Post NinjaTrader_Manfred  
                Started by AttiM, 02-14-2024, 05:20 PM
                10 responses
                181 views
                0 likes
                Last Post jeronymite  
                Working...
                X