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

Plot data is showing in Data Box but Printing as 0 to Output window

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

    Plot data is showing in Data Box but Printing as 0 to Output window

    I want to use indicators on various panels plus an additional series to create entry and exit points on the pricing panel. The easiest way to think of it would be similar to using MACD with additional Upper & Lower points plotted.

    I have set up a new indicator with just the basics to check that the data will print and everything is working but some plot data is not returning a value. Basic set up is:

    This is all working
    Initialise - private indicator indicator1; and private indicator indicator2;
    State.Configure - AddRenko(null, 12, MarketDataType.Last); (indicator2 = my second series)
    State.DataLoaded - indicator1 = indicator(Closes[0],parameters); and indicator2 = indicator(Closes[1],parameters);
    OnBarUpdate() - Print MACD, Ave, and Diff works for both series fine and Print values as per the Data Box (these all change value on each bar)

    This is not working
    OnBarUpdate() - Print Upper & Lower for both series plot ok and is listed correctly in Data Box but Print as 0 in Output Window (these don't change value on every bar)

    The indicator.Upper & indicator.Lower are the same value as the indicator.Diff on their respective bars and that also matches the Data Box (bars in between plots is "n/a" in the Data Box and should Print as 0) I have already checked for typos so that is not the problem

    Because Upper & Lower dont change value on every single bar do I need to add something to BarsinProgress ==0 & BarsinProgress ==1 to get a variable value other than 0 to print
    It is a bit confusing that everything that updates every bar Prints the data perfectly even if I add other Ema's





    #2
    Hello Ray12345,

    If you are printing Values[0][0] after the value has been set and getting a 0 in the output window but a value on the chart for that plot series, this would be unexpected.

    May I test the script? (You can remove all custom logic from the script and just plot a value of 1 to see that its plotting if you like)

    To export a NinjaTrader 8 NinjaScript so this can be shared and imported by the recipient do the following:
    1. Click Tools -> Export -> NinjaScript...
    2. Click the 'add' link -> check the box(es) for the script(s) and reference(s) you want to include
    3. Click the 'Export' button
    4. Enter a unique name for the file in the value for 'File name:'
    5. Choose a save location -> click Save
    6. Click OK to clear the export location message
    By default your exported file will be in the following location:
    • (My) Documents/NinjaTrader 8/bin/Custom/ExportNinjaScript/<export_file_name.zip>
    Below is a link to the help guide on Exporting NinjaScripts.
    http://ninjatrader.com/support/helpG...-us/export.htm

    Once exported, please attach the file as an attachment to your reply.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Chelsea

      Thank you for your reply. I tested a print on a standard indicator so I didn't add too much complexity. The bwFractal indicator also has an Upper & Lower that plots and displays in the DataBox correctly but only prints as 0 on the output window. I must be doing something wrong with the print statement. I have found that if the data updates on every bar it works fine but when it updates only on certain bars, as on this indicators Upper & Lower it only prints 0.
      Attached Files

      Comment


        #4
        Hello Ray12345,

        This indicator is not setting a value on the current bar.

        It sets values historically some bars ago.

        If there is no value set on the current bar, the plot will have a value of 0 on the current bar.

        You are setting 'period' number of bars ago:
        Lower[period] = Low[period];

        Trying printing the value you are setting for the bar 'period' bars ago:
        Print(Lower[period]);
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hi Chelsea

          Thank you

          [period] or [2] works since as you say it plots 2 bars ago

          But if I call this indicator inside another indicator [period] is not recognised and 2 does not work (goes back to only printing 0 values throughout)
          Last edited by Ray12345; 10-27-2020, 09:54 AM.

          Comment


            #6
            Hello Ray12345,

            Yes, I did test it.

            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Hi Chelsea

              Thank you. Sorry I butchered my edit attempt.

              [period] or [2] works since as you say it plots 2 bars ago

              But if I call this indicator inside another indicator [period] is not recognised and 2 does not work (goes back to only printing 0 values throughout)

              Comment


                #8
                Hello Ray12345,

                It would be the same series as what the print in the indicator is printing.

                Try looping through all of the plots bar values on each bar update. Make sure the hosted indicator is still printing correctly when called from host script.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Hi Chelsea

                  If I call the above indicator from inside another indicator I am back to where I started above. Anything that updates every bar prints fine.

                  private bwFractalPrintTest bwFractalPrintTest1;
                  bwFractalPrintTest1 = bwFractalPrintTest(Closes[0],false, false, 1, 1); (in Data.Loaded)

                  Print (""); // Print blank line
                  Print (Times[0][0]); // sample TIME TEST
                  Print (string.Format ("CurrentBar1 is {0}", CurrentBars[0])); // Sample PRINT TEST
                  Print (string.Format ("Upper1 is {0}", bwFractalPrintTest1.Upper[2])); // Sample PRINT TEST
                  Print (string.Format ("Lower1 is {0}", bwFractalPrintTest1.Lower[2])); // Sample PRINT TEST

                  I am just using CurrentBars[0] & Closes[0] because I will have a second series later once I work out what I am doing wrong
                  everything prints as expected but not the Upper & Lower values even with the bars ago of 2 fixed

                  Comment


                    #10
                    Hello Ray12345,

                    The hosted indicator is not longer printing correctly with it's internal prints?

                    Have you looped through all of the plots bars on every update?
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Hi Chelsea

                      If I call an indicator like the bwfractal with Upper & Lower plots into a new indicator the print (2) only prints 0's. If I call the MACD I get .MACD .AVG & .DIFF for every bar. Isn't the indicator already in a loop with OnBarUpdate. How would I do another loop inside that or is it easier and better to just copy all the called indicator code into the new indicator to save the CPU performing extra loops on every bar.

                      Comment


                        #12
                        Hello Ray12345,

                        Since you are doing something complex with the logic, looping through all of the values would let you see what data is available and help you understand the issue more clearly.

                        This is similar to how I was able to print the values and see that you were not setting a value for the most recent bar.

                        Using prints is necessary to understand behavior.

                        Yes, indicators do update OnBarUpdate() but only for the most recent bar. So if you are not setting a value on the current bar, printing without looping through all the data does not give you any useful information.

                        You may need to expend the extra CPU performance while trying to debug the code and understand the data using prints.
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          Hi Chelsea

                          Do you have a sample loop method

                          Comment


                            #14
                            Hello Ray12345,

                            for (int index = 0; index < CurrentBar; index++)
                            Chelsea B.NinjaTrader Customer Service

                            Comment


                              #15
                              Hi Chelsea

                              I fixed the problem by using a second transparent plot on the original indicator so I could call the data on the new indicator without looping. As it is calculated on the next bar I just set the new Plot Value to Plot(1) so it listed the Value from the previous bar. Now the correct data is listed on the next bar number (the one it is actually calculated on) on the print output.

                              I have another question about Plots called from another indicator. When I do call an indicator from another indicator with the Plot Value whether it is Diff, Close, High etc obviously you get that data as per the Plot Value. What about the bar number of the Plot. If you get the Value from the Plot a number of bars ago how do you get the bar number of the Plot or the number of bars ago to use in an if statement as you can with the Plot Value.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Christopher_R, Today, 12:29 AM
                              0 responses
                              6 views
                              0 likes
                              Last Post Christopher_R  
                              Started by sidlercom80, 10-28-2023, 08:49 AM
                              166 responses
                              2,235 views
                              0 likes
                              Last Post sidlercom80  
                              Started by thread, Yesterday, 11:58 PM
                              0 responses
                              3 views
                              0 likes
                              Last Post thread
                              by thread
                               
                              Started by jclose, Yesterday, 09:37 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post jclose
                              by jclose
                               
                              Started by WeyldFalcon, 08-07-2020, 06:13 AM
                              10 responses
                              1,415 views
                              0 likes
                              Last Post Traderontheroad  
                              Working...
                              X