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

CalculateOnBarClose setting overriding other indicators

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

    CalculateOnBarClose setting overriding other indicators

    I have an indicator that accesses the OnRender() method to do some drawing stuff. The problem I am encountering is, then I place another indicator, say the ATR, on the chart with it...the ATR defaults COBC to true. For whatever reason, this causes my other indicator to draw everything with the bar values shifted one bar over. Is there a way to keep other indicators from affecting it?

    #2
    Hello,

    Thanks for the post.

    Can you please confirm what version of NinjaTrader you are coding this for? OnRender is used in NinjaTrader 8 and this forum post is in the NinjaTrader 7 section.

    Each manually added indicator will have its own CalculateOnBarClose setting. Are these indicators in their own plot? Have you set CalculateOnBarClose to false?

    Can you also post screenshots of this issue?

    To send a screenshot with Windows 7 or newer I would recommend using Window's Snipping Tool.

    Click here for instructions:
    Learn how to use Snipping Tool to capture a screenshot, or snip, of any object on your screen, and then annotate, save, or share the image.


    I look forward to your reply.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      NinjaTrader_ChrisL , I am coding this indicator for both NT7 and NT8. The problem is only occurring in NT7. CalcOnBarClose is set to false. This indicator does not have any plots. It is using the OnRender() method to draw objects on the chart via mouse tracking and capturing mouse clicks.

      To try and be more specific, when all the indicator on the chart have their respective CalcOnBarClose set to false...my indicator tracks everything perfectly.

      If MY indicator CalcOnBarClose is set to FALSE (the default), and I use another indicator (such as the ATR) on the same chart....also with its CalcOnBarClose set to FALSE...MY indicator tracks perfectly.

      If I set MY indicator CalcOnBarClose to TRUE...then it suddenly behaves as if all my bar data (OHLC) has been shifted one bar to the right.

      If MY indicator CalcOnBarClose is set to FALSE (the default), and I use another indicator (such as the ATR) on the same chart....but with its CalcOnBarClose set to TRUE...MY indicator suddenly behaves as if all my bar data (OHLC) has been shifted one bar to the right.

      That is what has been occurring. All that said, I did find a way around this. Instead of using the Open[], High[], Low[],Close[] arrays, I called the bar data directly via Bars.Get***(). Doing this effectively just circumvents the problem because the 0 element reference isn't being jacked with via the CalcOnBarClose setting.

      My issue is, why would another indicator interfere with this setting? To the best of my understanding, each indicator is its own instance and the setting in one should not impact the setting in another.

      Comment


        #4
        Hello, thanks for the reply.

        This behavior does not happen with default indicators so it must be caused by something specific to your script. Can you recreate what is happening in a simple version of the script you wrote? It sounds like the logic of your script is experiencing an off-by-one error. I see you mention OnRender for NT7. In NT7 you would use Plot() to do custom plotting. Is this what you meant? Also, can you try to run the CustomPlotSample indicator and see if the same behavior occurs when you add an ATR?

        Please see here for instructions on exporting a script:


        I look forward to your reply.
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          Hello, thank you for the reply.

          It looks like there is some calculation that converts the mouse x value to a bar position. The function GetNdxByX is what does this. Use prints within this method to find why the values are being shifted in the COBC = true use case. Using ChartControl is not documented/supported in NinjaTrader 7. Whatever results ChartControl produces, you may need to observe and make conditions for those specific uses as this is not documented in NT7. When you find the reason for the data shift, you can add in a conditional branch to calculate properly when the COBC=true case is reached.

          Please let us know if you have any questions.
          Chris L.NinjaTrader Customer Service

          Comment


            #6
            I know the indicator behaves incorrectly when COBC is set to true. I don't know how to check if another indicator on the same chart has its COBC set to true. The problem is not my indicator, but that another indicator's COBC setting is affecting it. How do I check for that?

            Comment


              #7
              Hello. Thank you for the reply.

              You would not check for anything outside of your script. You would observe the change in values that occurs once the shifting anomaly occurs and adjust the values that way. Verify that the conversion for your X coordinate is checked to make sure the anchor of the line is at the location you expect it to be. before drawing it.

              This should get you through the debugging process. I noticed in your OnRender you get refbar. This is the thing that determines where the line is drawn. I then noticed that when the anomaly occurs, the difference of the refbar and currentbar were negative. To fix it, add a sanity check with a bit of math:

              Code:
              int ndx = GetNdxByX(ptM.X);
              				
              if((CurrentBar-ndx)-(CurrentBar) < 0)
              	{
              			refbar = (CurrentBar-ndx)-1;
              	}
              else
              	{
              		refbar = CurrentBar-ndx;
              }
              Please let us know if you have any questions.
              Chris L.NinjaTrader Customer Service

              Comment


                #8
                But...why would I do that? That would take up unnecessary processing cycles. The issue is that it is shifting the bar reference. I got around this by switching to calling the bar data directly via Bars.Get****(). The 0 element reference point is at the oldest point on the chart, which COBC has no effect on.

                I was just trying to figure out why an indicator's COBC setting would affect another indicator. I was under the impression this is not supposed to happen.

                Comment


                  #9
                  Hello. Thank you for the reply.

                  If statements negligibly impact time complexity if there is no long-running code in the if block. Also, this code is only run if the chart is rendering. To uncover the reason why this is happening will take debugging of this conversion that takes place between the mouse click and line drawing. ChartControl is not documented in NinjaTrader 7, so you will have to research the behavior of the unsupported/undocumented codes that you are using in this script when a separate indicator's COBC is set to true.

                  Please let us know if you have any questions.
                  Chris L.NinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by TraderBCL, Today, 04:38 AM
                  2 responses
                  7 views
                  0 likes
                  Last Post TraderBCL  
                  Started by martin70, 03-24-2023, 04:58 AM
                  14 responses
                  105 views
                  0 likes
                  Last Post martin70  
                  Started by Radano, 06-10-2021, 01:40 AM
                  19 responses
                  606 views
                  0 likes
                  Last Post Radano
                  by Radano
                   
                  Started by KenneGaray, Today, 03:48 AM
                  0 responses
                  4 views
                  0 likes
                  Last Post KenneGaray  
                  Started by thanajo, 05-04-2021, 02:11 AM
                  4 responses
                  471 views
                  0 likes
                  Last Post tradingnasdaqprueba  
                  Working...
                  X