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

How to fix DrawRegion "lag"

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

    How to fix DrawRegion "lag"

    Hi there,

    I've added opaque bands when the stochastics becomes overbought or oversold. Since I am not plotting a continuous band of one color, I've had to use the code below. Unfortunately "bars ago" has to be set to "1" which means it is plotting the band one bar behind as well as the current bar. Please see the picture to see what I mean.

    Code:
    if (CurrentBar > 0)
    			{	
    			if (DUpper[0] >= 75) DrawRegion("tag1"+ CurrentBar,1, 0, DUpper, 75, Color.Empty, Color.Lime, 1);
    			if (DLower[0] <= 25) DrawRegion("tag2"+ CurrentBar,1, 0, DLower, 25, Color.Empty, Color.Red, 1);
    			}
    Any ideas to get around this? Thanks in advance!
    Attached Files

    #2
    Hello Sim22,

    Draw region does draw as you have shown as it cannot access future bars so this would be expected.

    As for performance the way you currently have it would consume a lot of CPU as it is drawing a region for every bar especially as you get more data loaded on the chart.

    One way around this would be to set up a condition that when met it will set a variable to that specific bar as a start bar for the region. After this you could reference the start bar and current bar in the region so that it draws a single region from point A to point B instead of drawing a new region every bar.

    Please let me know if I may be of additional assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Okay, that makes sense. Cheers Jesse

      Comment


        #4
        Originally posted by NinjaTrader_Jesse View Post
        Hello Sim22,

        As for performance the way you currently have it would consume a lot of CPU as it is drawing a region for every bar especially as you get more data loaded on the chart.

        One way around this would be to set up a condition that when met it will set a variable to that specific bar as a start bar for the region. After this you could reference the start bar and current bar in the region so that it draws a single region from point A to point B instead of drawing a new region every bar.
        Just found this note and had a question.

        If I use "1" for the StartBarsAgo and "0" for EndBarsAgo will that cause all bars between my conditions to repaint on each new bar?

        And the next question is: Does it repaint all previous regions on the chart for that condition?

        Regards,
        taddypole...
        Attached Files

        Comment


          #5
          Hello,

          Thank you for the question.

          Using the BarsAgo of 1 and 0, this would depend if you are using a Unique tag name or not.

          Using a Unique tag name, a new Drawing Object Region would be placed for the distance between these two bars and this would occur over and over. Using a non unique tag name would result in 1 object being moved to a new location over and over.

          In general, it is usually more efficient to calculate the bars ago from the current bar, and use the value calculated and 0 for the bars ago. This would create one object that spans the entire region instead of multiple objects spanning a region.

          I look forward to being of further assistance.
          JesseNinjaTrader Customer Service

          Comment


            #6
            Thanks Jesse,

            I had downloaded an indicator and couldn't understand the reasoning for the DrawRegion code. I think you have finally made it clear.

            I see now. Refer to attachment.

            regards,
            taddypole...
            Attached Files

            Comment


              #7
              I have an additional question. I'm trying to expose the DrawRegion objects but having problems compiling the code. Can someone help? Trying to follow the example in Ninja Trader Help but stuck.

              See attachment:

              regards,
              taddypole...
              Attached Files

              Comment


                #8
                In the Help documentation there are:

                DrawType.Region
                DrawType.Rectangle

                But I had to use: DrawType.Normal


                foreach(ChartObject o in ChartControl.ChartObjects)
                {
                if(o.DrawType == DrawType.Normal)
                {
                Print("Found One");

                }
                }

                Appears the Help document could use some updating...

                found some other code snippets that helped me complete my exposing drawObjects exercise.
                See attached.

                Appears "Normal" is the non rectangular form of DrawRegion. As far as I can tell, "DrawType.Region" can't be found using Visual Studio.


                regards,
                taddypole...
                Attached Files
                Last edited by Taddypole; 09-29-2015, 12:20 AM.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by wzgy0920, 04-20-2024, 06:09 PM
                2 responses
                26 views
                0 likes
                Last Post wzgy0920  
                Started by wzgy0920, 02-22-2024, 01:11 AM
                5 responses
                32 views
                0 likes
                Last Post wzgy0920  
                Started by wzgy0920, Yesterday, 09:53 PM
                2 responses
                49 views
                0 likes
                Last Post wzgy0920  
                Started by Kensonprib, 04-28-2021, 10:11 AM
                5 responses
                192 views
                0 likes
                Last Post Hasadafa  
                Started by GussJ, 03-04-2020, 03:11 PM
                11 responses
                3,234 views
                0 likes
                Last Post xiinteractive  
                Working...
                X