Announcement

Collapse
No announcement yet.

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.

    World's leading screen capture + recorder from Snagit + Screencast by Techsmith. Capture, edit and share professional-quality content seamlessly.
    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 Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                597 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                343 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                103 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                556 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                555 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X