Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Problem with DrawText drawing in advance of actual bars on screen

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

    Problem with DrawText drawing in advance of actual bars on screen

    Hi guys,

    I have an indicator which uses DrawText to write the number of the bar (starting at
    1 each day) underneath the bar as this serves as a reference when I am writing notes.

    I also maintain a largish right side margin on the chart (i.e. an area in which bars are not drawn) so that bars do not interfere with other symbols or display markers which appear there and I can see the bars clearly.

    The problem is that when I am advancing through charts bar-by-bar, the right side margin, although lacking bars (as desired) still plots the bar numbers in the margin area. This is troublesome to me because sometimes I like to be 'blind' to the price development that is about to come, but the DrawText labels, because they are positioned at a fixed interval below the bars give me a hint as to what is about to happen.

    Any thoughts?

    (And yes, the labels do need to be close to the bars they are labelling otherwise there is little added value.)

    Edit: On further inspection, the problem arises when I have a chart loaded and I decide to scroll all the way back. It appears that NT is not erasing the markers when I do this. Is there is a quick fix for this or should I amend my code to somehow handle this?
    (The other way for me to do this is to remove the indicator and add it back in again. Is there a quick way of enabling and disabling indicators without removing them altogether?)

    Thanks
    Last edited by trader_rick; 02-02-2016, 08:03 AM.

    #2
    Hello trader_rick,

    The drawing objects are not affected by the right side margin the way that plots and bars are.

    If you wanted these to disappear when historical bars they are drawn under are in the margin area, a check would need to be done to see if that bar is within the visible area of chart and then if it is not, the drawing object would need to be removed.

    Once the bar is back into the viewable area, the textbox would need to be redrawn.
    As this would happen as the chart is scrolling, this would be a CPU intensive indicator.

    If you would like I can add a feature request to not allow textboxes to render in the right side margin. Would you like me to submit a feature request for this?


    To reload an indicator without removing and re-adding it, right-click your chart and select Reload NinjaScript. Or click on the chart and hit F5 on your keyboard.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Chelsea,

      Thanks for the reply.

      What is the attribute I need to query or function I need to call in my NinjaScript in order to see whether a bar is in the visible area or not? I think that would be the best fix for me at present.

      As for feature request, it does seem logical to me that if bars are not plotted in the margin then there is not much sense in having associated indicators continue to be plotted there too, so yes, a feature would be nice but I'm sure you have more pressing things to attend to.

      Rick

      Comment


        #4
        Hi Rick,

        The tools needed are undocumented and not in the help guide.

        ChartControl.LastBarPainted should return the bar number visible on the chart. If the bar number that is being drawn on is above this, then its in the margin.
        ChartControl.FirstBarPainted will tell you the first bar on the chart.

        This would need to be checked in the Plot override so that it is triggered anytime you scroll the chart.

        Basically, what I suggest is to use a loop to loop through all the bars past the last bar painted to the last bar and remove drawing objects there, (or set their colors to transparent which might use less CPU than removing and re-adding. Then you would need a second loop that runs through the first bar painted and last bar painted, for any bars that don't have drawing objects (or the drawing objects are transparent) draw the textboxes back or set the colors.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hi Chelsea,

          The function LastBarPainted returns a static number i.e. it does not change as the chart is advanced in the window.

          Similarly with FirstBarPainted. However, LastBarTimePainted does appear to update and give the timestamp for the last visible bar so I am trying to work with this instead.

          Just letting anyone else who may be interested know.

          Regards

          Comment


            #6
            Hi Rick,

            That was my mistake.

            That should be LastBarIndexPainted and FirstBarIndexPainted.

            http://ninjatrader.com/support/forum...ad.php?t=21560
            Chelsea B.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Max238, Today, 01:28 AM
            5 responses
            42 views
            0 likes
            Last Post Max238
            by Max238
             
            Started by giulyko00, Yesterday, 12:03 PM
            3 responses
            12 views
            0 likes
            Last Post NinjaTrader_BrandonH  
            Started by habeebft, Today, 07:27 AM
            1 response
            14 views
            0 likes
            Last Post NinjaTrader_ChristopherS  
            Started by AveryFlynn, Today, 04:57 AM
            1 response
            12 views
            0 likes
            Last Post NinjaTrader_Erick  
            Started by r68cervera, Today, 05:29 AM
            1 response
            10 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Working...
            X