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

Using Draw.Line with two data series

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

    Using Draw.Line with two data series

    I've developed an indicator that plots lines to show divergences between the main symbol and an indicator that plots a calculated value in panel 2. The indicator in panel 2 can be a standard indicator such as RSI, or it can be a custom indicator.
    The divergence indicator plots lines on both the main symbol and the indicator in panel 2 showing where, for example, the main symbol is rising while the indicator in panel 2 is falling.

    The divergence lines are plotted using the following two instructions:

    Code:
    Draw.Line(this,"BLDmain"+AA+BB,true,CurrentBar-PivLBar[i],PivotLow_FloatArray[i], CurrentBar-PivLBar[1], PivotLow_FloatArray[1],BullishDivBrush,DashStyleHelper.Dot, DivergenceLineWidth,true);
    Draw.Line(this,"BLDcomp"+CC+DD,true,CurrentBar-PivLSRBar[i],PivotStoRSI[i], CurrentBar-PivLSRBar[1], PivotStoRSI[1],BullishDivBrush,DashStyleHelper.Dot, DivergenceLineWidth,false);
    (Note: The strings AA, BB, CC and DD are simply used to uniquely identify each plotted line).

    This indicator works well in all cases except one.
    If I plot a second data series in panel 2 rather than a calculated value (e.g. I have ES in the main price panel and NQ in panel 2), then instead of plotting one divergence line on ES in the main panel and one on NQ in panel 2, it plots both divergence lines in panel 2.

    The divergence indicator is clearly calculating the divergences correctly because the two lines it plots are in locations where divergence was present and the plotted lines are in opposite directions, i.e. one is rising and the other falling.
    The only problem is that the divergence line that should be in the main price panel is in panel 2
    As you can see, the first Draw.Line instruction has the DrawInPricePanel parameter set to true so I would expect that line to be drawn in the main panel on the ES data series. However, it seems that the addition of a second data series causes that second data series' location to be treated as the main price panel as far as the Draw.Line instruction is concerned..

    I would appreciate any guidance on how to fix this problem.
    Thanks.​

    #2
    Hello Scotty33,

    Thank you for your post.

    So I may accurately assist you, please answer all of the following questions:
    • What version of NinjaTrader are you using? Please provide the entire version number. This can be found under Help -> About (Example: 8.?.?.?)
    • What interval is selected for each data series? For example, 5 minute, 1 day, 2000 volume, 4 Renko, etc.
    • Do you receive an error on the screen? Are there errors on the Log tab of the Control Center? If so, what do these errors report?
    • Please provide a screenshot demonstrating the scenario you are describing.
      • To send a screenshot with Windows 10 or newer I would recommend using the Windows Snipping Tool.
      • Alternatively to send a screenshot press Alt + PRINT SCREEN to take a screenshot of the selected window. Then go to Start--> Accessories--> Paint, and press CTRL + V to paste the image. Lastly, save it as a jpeg file and send the file as an attachment to your forum reply.

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

    Comment


      #3
      Hello Emily,
      Thanks for your reply.
      Here are the answers to your questions:
      • Version 8.0.28.0 64-bit
      • 1 minute on each chart.
      • There are no errors on the screen or in the Control Center Log.
      • Screenshot attached below
      • Click image for larger version

Name:	image.png
Views:	129
Size:	40.8 KB
ID:	1264592​Thanks for any help.

      Comment


        #4
        Hello Emily,
        I've just added some Print statements to try to identify what is happening and I believe the problem is that statements in the routines to check for highs and lows in the main price panel using variables such as Close[1+i] are picking up values from the second data series rather than the main price panel.
        How can I differentiate between the two data series in order to pick up highs and lows from each one separately?

        Comment


          #5
          Hello Scotty33,

          Thank you for your reply.

          Based on your screenshot, the indicator is applied with the NQ 09-23 series as the input series. This means NQ will be used as the primary series for indicator calculations. You could check the differences if you change the input series to ES 09-23 in the indicator settings, as well as if you create two instances of the indicator, one on ES 09-23 and the other on NQ 09-23.

          Additionally, what is the indicator's value for DrawOnPricePanel in OnStateChange when the state is State.SetDefaults? The default value is True, which will draw objects on the price panel, otherwise if the indicator is in a different panel and you set DrawOnPricePanel to false the objects will be drawn in the indicator panel rather than the price panel.


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

          Comment


            #6
            Hello Emily,
            Yes, the Input Data Series for the divergence indicator is usually pointing at the indicator or data series to be compared with the symbol in the main price panel. Changing this to ES rather than NQ just results in the indicator using ES data for both the data series in the main price panel and the data series in panel 2. It now plots lines in both panels but those in panel 2 are not aligned with the values of the NQ data series. (see screenshot below).
            The indicator's value for DrawOnPricePanel in OnStateChange when the state is State.SetDefaults is True.
            I'm not sure what you mean by using two instances of the indicator. Do you mean that each instance is collecting data from the relevant data series and then the two instances are communicating with each other to determine if divergence is present?

            Click image for larger version

Name:	image.png
Views:	164
Size:	46.9 KB
ID:	1264640

            Comment


              #7
              Hello Scotty33,

              Thank you for your reply.

              "Do you mean that each instance is collecting data from the relevant data series and then the two instances are communicating with each other to determine if divergence is present?".
              • No, the two instances would not communicate with each other. I simply meant to apply the indicator to both the primary panel as well as the secondary added panel to compare if the lines are drawn only in the panel the indicator instance is applied to or not
              I'm not sure that I follow the behavior you are trying to describe with the lines; you mentioned that the lines show, "divergences between the main symbol and an indicator that plots a calculated value in panel 2" and this is working as expected when you plot an indicator in the second panel, correct? Yet the indicator is not behaving as expected when you add a data series to panel 2? Does your indicator call AddDataSeries() to add a series programmatically?


              OnBarUpdate() is processed for the primary data series that the indicator is applied to, as well as any data series that are added programmatically. Adding a data series visually from the chart's right-click Data Series window should not affect how your indicator is calculated. If you configure it so that the ES series is in Panel 1, then the NQ series is in panel 2, then the indicator is in its own panel (Panel 3) what are the results?

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

              Comment


                #8
                Hello Emily,
                • I simply meant to apply the indicator to both the primary panel as well as the secondary added panel to compare if the lines are drawn only in the panel the indicator instance is applied to or not
                This would not generate lines correctly. Each indicator instance needs to compare price action in two panels simultaneously in order to identify divergence.
                • the lines show, "divergences between the main symbol and an indicator that plots a calculated value in panel 2" and this is working as expected when you plot an indicator in the second panel, correct? Yet the indicator is not behaving as expected when you add a data series to panel 2?
                This is correct.

                Here's an example of lines drawn correctly comparing ES with a custom indicator:

                Click image for larger version

Name:	image.png
Views:	176
Size:	80.1 KB
ID:	1264747
                • Does your indicator call AddDataSeries() to add a series programmatically?
                No, because the indicator does not know in advance whether it will be comparing the main symbol with a custom indicator or a data series (nor which data series might be involved).
                • If you configure it so that the ES series is in Panel 1, then the NQ series is in panel 2, then the indicator is in its own panel (Panel 3) what are the results?
                No lines are drawn because the indicator is designed to run in the same panel as the indicator/data series that is being compared with the data series in the main panel, and in your scenario there is no comparison indicator/data series in panel 3.
                There are two parameters that are relevant: one is Input Series which specifies the indicator/data series that is to be compared with the main symbol, and the other is the panel in which that indicator/data series resides (it doesn't have to be panel 2)..

                Comment


                  #9
                  Hello Scotty,

                  Thank you for your reply.

                  Adding an indicator to a chart does not give the indicator a reference to any other indicators on the chart or what panels exist on the chart. To run indicator calculations based on the primary input series and another data series, the additional data series would need to be added programmatically with AddDataSeries():


                  It is also important to keep the following warning in mind:
                  Arguments supplied to AddDataSeries() should be hardcoded and NOT dependent on run-time variables which cannot be reliably obtained during State.Configure (e.g., Instrument, Bars, or user input). Attempting to add a data series dynamically is NOT guaranteed and therefore should be avoided. Trying to load bars dynamically may result in an error similar to: Unable to load bars series. Your NinjaScript may be trying to use an additional data series dynamically in an unsupported manner.​
                  This type of concept has been discussed in the following thread for NinjaTrader 7 and NinjaTrader 8:


                  Ultimately, it is advised to use two separate indicators and have one that plots to the price panel and one that draws on the indicator panel.

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

                  Comment


                    #10
                    Hello Emily,
                    Thanks for your reply.
                    • Arguments supplied to AddDataSeries() should be hardcoded
                      If I understand this correctly, my indicator would need to know in advance which data series was to be added and which parameters would be applied to it.
                      This is contrary to the current philosophy of my indicator whereby users can compare the main chart symbol with any standard or custom indicator of their choosing and they can specify which parameters they want to use for that indicator.
                      Now, if they wish to use a data series for comparison they will only be able to select the pre-defined data series and parameter set(s) offered by the divergence indicator. Correct?

                      This seems a really cumbersome approach.
                      For info, I develop my package of indicators on both NinjaTrader and SierraChart. The SC version of the divergence indicator works perfectly with indicators and data series without any need to hardcode parameters.

                      Thanks anyway for trying to help.

                    Comment


                      #11
                      Hello Scotty33,

                      Thank you for your reply.

                      That is correct; based on what you have described, it seems your indicator will not be able to achieve the desired results in NinjaTrader. That said, there is an existing feature request to allow dynamic handling and loading of additional Data Series in NinjaScript and I will gladly add your vote to track additional interest. The internal tracking number for this feature request is SFT-882. Please reference this internal tracking number when contacting Platform Support if you ever have questions regarding this feature request.

                      When a feature request is implemented, you'll find a description of the new feature in the release notes:Thank you for using NinjaTrader.​
                      Emily C.NinjaTrader Customer Service

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by pibrew, Today, 06:10 PM
                      0 responses
                      4 views
                      0 likes
                      Last Post pibrew
                      by pibrew
                       
                      Started by pibrew, 04-28-2024, 06:37 AM
                      2 responses
                      17 views
                      0 likes
                      Last Post pibrew
                      by pibrew
                       
                      Started by Philippe56140, 04-27-2024, 02:35 PM
                      7 responses
                      56 views
                      0 likes
                      Last Post kevinenergy  
                      Started by arunkumar3, 08-25-2023, 12:40 PM
                      3 responses
                      169 views
                      0 likes
                      Last Post Trader2024!  
                      Started by DJ888, 04-26-2024, 10:57 PM
                      2 responses
                      17 views
                      0 likes
                      Last Post DJ888
                      by DJ888
                       
                      Working...
                      X