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

Custom Indicator within Custom Strategy Not Plotting or Updating

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

    Custom Indicator within Custom Strategy Not Plotting or Updating

    Hi,

    I have a custom indicator (based on two out of the box indicators) that I'm trying to use within a strategy. While testing the indicator in the chart with playback data, the indicator plots as expected. When I try to add that indicator to a custom strategy the plot doesn't work for the indicator nor do the boolean values from my indicator change as expected (they are always false). What am I doing wrong?

    Thank you.
    Attached Files

    #2
    Hello ToroTrader,

    Thank you for your note.

    You mentioned that the plot doesn't work for the indicator; do you receive any error messages in the log tab of the Control Center or in the NinjaScript Output window? When you are testing just the indicator and not the strategy, are the bools updating as expected or are they also always false?

    As a debugging tool, I recommend adding Print() statements to your script. This can be especially helpful to determine if the parts of your script that should update the bool values are being hit. For more information about using Prints to debug:


    I look forward to your reply.
    Emily C.NinjaTrader Customer Service

    Comment


      #3
      Thanks Emily. I have logging. I see the correct log output when I run the indicator inside a chart using replay data. But when I run a strategy using the indicator with the same replay data, the plot doesn't work and the log values coming back from the strategy (reading the indicator) and the logging coming from the indicator are not correct. I think maybe there is something wrong in how I'm adding or instantiating the indicator into the strategy? See screen captures of what I'm seeing. Thanks again.

      Click image for larger version  Name:	Capture Indicator Working On Chart.png Views:	0 Size:	127.6 KB ID:	1223877

      Click image for larger version

Name:	Capture Plot Not on Strategy Analyzer.png
Views:	252
Size:	118.1 KB
ID:	1223879
      Last edited by ToroTrader; 11-16-2022, 10:17 AM.

      Comment


        #4
        Hello ToroTrader,

        Thank you for your reply.

        Looking at your strategy, is there a reason you are including the following logic in lines 64-67?

        else if (State == State.Configure)
        {
        lock (this.NinjaScripts)
        {
        this.NinjaScripts.Add(new Indicators.MomentumPressureIndicator() { Parent = this, IsCreatedByStrategy = true });
        }




        AddChartIndicator(Momentum(1));
        AddChartIndicator(BuySellPressure());
        AddChartIndicator(MomentumPressureIndicator());
        }

        Utilizing AddChartIndicator should be sufficient; IsCreatedByStrategy is not documented, so there is no guarantee of how it will function or if it was meant to be used in custom NinjaScripts. Please try commenting out the bolded lines as a test, and if the symptom persists let me know.

        I appreciate your patience.
        Emily C.NinjaTrader Customer Service

        Comment


          #5
          Hi Emily,

          I think I just tried that piece of code because someone in a youtube video had recommended it. He said it was needed if you're developing in visualstudio (which I am). I commented it out and I'm still getting the same behavior.

          Thanks for your help.

          Pete
          Last edited by ToroTrader; 11-16-2022, 11:11 AM. Reason: VS development addl info

          Comment


            #6
            Hello ToroTrader,

            Thank you for your reply.

            Are you sure that your indicator is plotting properly? I added it to my platform to test, and I do not get any data plotted. It seems that the following section of conditions is only ever hitting the final "else" statement, so neither LongSignal() nor ShortSignal() is being hit to change the bool series to true or set a plot value. I recommend adding prints inside of each condition to see when they are hit (see the commented print suggestions):

            Code:
            if(pressure == MarketPosition.Long && momentum == MarketPosition.Long)
            {
            
            LongSignal();
            // could add a print here
            // Print(Time[0] + " LongSignal reached.  longIndication[0]: " + longIndication[0] + " shortIndication[0]: " + shortIndication[0] + " Values[0][0]: " + Values[0][0]);
            
            
            }else if(pressure == MarketPosition.Short && momentum == MarketPosition.Short){
            
            ShortSignal();
            // could add a print here
            // Print(Time[0] + " ShortSignal reached.  longIndication[0]: " + longIndication[0] + " shortIndication[0]: " + shortIndication[0] + " Values[1][0]: " + Values[1][0]);​
            
            }else{
            longIndication[0] = (false);
            shortIndication[0] = (false);
            // Print(Time[0] " else statement");
            
            }
            I suspect that pressure and momentum don't seem to be evaluating to the expected MarketPositions. This may require additional debugging and adjustments to get the script to work as expected.

            Please feel free to reach out with any additional questions or concerns.
            Emily C.NinjaTrader Customer Service

            Comment


              #7
              Hello,

              It's definitely hitting when I use the indicator on the chart. You can see it in the screen capture I provided, it's logging long and neutral indications and you can see the green lines below on the indicator chart. You have to enable and use tick data when running with replay data, maybe that is why you are not seeing anything?

              Comment


                #8
                Hello ToroTrader,

                Thank you for your patience.

                If you would like for me to test your code, please reduce the code to only the necessary code to investigate the specific issue, then export the script and provide the export. Additionally, please provide the steps that you are using to test in Playback (i.e. the instrument, timeframe on the chart, date/time for the replay) and I would be glad to test it both in Playback and in Real-time.

                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


                As a debugging tool, I recommend printing the time of the bar and the value being assigned to the plot, one line above where the plot is being assigned a value. That way you can compare the prints when testing the indicator as well as the prints when testing the strategy that uses the indicator values.

                I look forward to resolving this with you.
                Emily C.NinjaTrader Customer Service

                Comment


                  #9
                  Hi Emily,

                  See attached NinjaScript export. I also screen recorded testing the indicator in a chart and in the strategy analyzer so you can see my selections.






                  Thanks.
                  Pete
                  Attached Files

                  Comment


                    #10
                    Hello Pete,

                    Thank you for your patience.

                    I misunderstood the steps you were using to run the backtest in the Strategy Analyzer; the Strategy Analyzer 'Run' button should be disabled in Playback mode. The option to click Run was an issue in earlier versions that was resolved in version 8.0.26.0 per the release notes here (Issue # 15068):


                    I see you are using version 8.0.24.3. To update NinjaTrader, please follow the steps below:
                    • First, copy your license key from NinjaTrader under Help> License Key then exit NinjaTrader
                    • Click on the link: https://ninjatrader.com/PlatformDirect
                    • Enter your license key and press Submit
                    • Select 'Download'
                    • Critical: Before running the installer, ensure NinjaTrader is closed.

                    It is also noted in the Help Guide section that in order to run a backtest you need access to historical data; historical data is different from playback data and they are stored in different files. For more information about historical data in the platform:


                    Please let us know if we may be of further assistance.
                    Emily C.NinjaTrader Customer Service

                    Comment


                      #11
                      Hi Emily,

                      I've downloaded the latest version. I downloaded two days of historical data for the S&P index from tickstory.com, uploaded it in the historical data, where i see it listed now. I then go to strategy, select the backtest, my strategy, s&p 500 index, click the playback window and select historical option for the S&P index dates I downloaded, I click the play button. The chart plots, of the underlying indicators I'm using Momentum is plotting, but buy sell pressure is not, and a result my custom indicator is not plotting since it depends on those two. It seems you don't get buy sell pressure with historical data as you do using market replay. Why is it that the strategy analyzer does not work with market replay? I'm trying to analyze automated trades so I need something that closely simulates the market, which is what market replay seems to do.

                      Please advise.

                      Thanks.
                      Pete

                      Comment


                        #12
                        Hello Pete,

                        Thank you for your reply.

                        Backtesting in the Strategy Analyzer uses historical data and is processed as quickly as possible using data points. It also allows for optimizing. Market replay/Playback uses recorded playback or historical data in a way more like a tape recorder of VHS so the data may be played back in a sequence as if it were in real-time. Since you imported historical data, please try running the Strategy Analyzer without being connected to the Playback Connection. You may be completely disconnected while running a Strategy Analyzer and it will use the cached/stored historical data. Additionally, be sure to enable the "Tick Replay" checkbox in your backtest settings to allow the calculations for BuySellPressure (note: with Tick Replay enabled, you may not also combine it with the High Order Fill Resolution). This should display the indicator on your chart.

                        There are additional notes about developing for tick replay on the help guide page here:


                        I appreciate your patience.
                        Emily C.NinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by maybeimnotrader, Yesterday, 12:58 PM
                        1 response
                        9 views
                        0 likes
                        Last Post NinjaTrader_Eduardo  
                        Started by James Cowart, Yesterday, 10:55 AM
                        1 response
                        12 views
                        0 likes
                        Last Post NinjaTrader_Eduardo  
                        Started by Misplace, Today, 11:55 AM
                        0 responses
                        5 views
                        0 likes
                        Last Post Misplace  
                        Started by dtaylor, Yesterday, 02:24 AM
                        1 response
                        10 views
                        0 likes
                        Last Post NinjaTrader_Eduardo  
                        Started by sofortune, 05-10-2024, 10:28 AM
                        7 responses
                        60 views
                        0 likes
                        Last Post sofortune  
                        Working...
                        X