Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Auto refresh screen

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

    Auto refresh screen

    I am new to OOP language.

    I download MACDUpDown from Ninjatrader script sharing file for 7.0.
    Then I added a couple lines of coding at the bottome of OnBarUpdate() section as follows:

    // My code - MACD main vs signal dots
    if (Value[0] > Avg[0] && Value[1] < Avg[1] )
    DrawDot(
    "tag"+CurrentBar, true, Time[0], Low[0], Color.Lime);

    if (Value[0] < Avg[0] && Value[1] > Avg[1] )
    DrawDot(
    "tag"+CurrentBar, true, Time[0], High[0], Color.Red);

    The intention is to display a dot on the price chart when MACD main and signal line crosses over. It looks fine when I update my chart at the end of a day. I see green/red/green/red pattern.

    When I applied it on a real-time chart, e.g. 3-min chart, during that bar interval, the condition may be met. A dot is generated. But when the condition was changed and the criteria was no longer met, the dot stays. Then I see pattern like green/green/red/red, etc.

    When I hit F5 to refresh screen, the chart becomes correct and cleaned up.

    How to have a clean up a chart in real-time without hitting F5? Before a price interval is completed, when the condition is changed, how to remove the display of a dot?

    Thank you.

    #2
    It sounds like you have "CalculateOnBarClose = false". Is that correct?

    Comment


      #3
      Yes. It is correct.

      Comment


        #4
        In that case, you have to code around the specific scenario that you are trying to create. Essentially you are evaluating the condition on every tick, and then you want to draw or remove the dot as required.

        Here is how I would go about it.

        Code:
        bool Condition1 = Value[0] > Avg[0] && Value[1] < Avg[1] ;
        bool Condition2 = Value[0] < Avg[0] && Value[1] > Avg[1] ;
        
        if (Condition1)
        {
        DrawDot("tag"+CurrentBar, true, Time[0], Low[0], Color.Lime);
        }
        else if (Condition2)
        {
        DrawDot("tag"+CurrentBar, true, Time[0], High[0], Color.Red);
        }
        else
        {
        RemoveDrawObject("tag"+CurrentBar);
        }
        I was too lazy to actually test the code (a no, no, I know, but hey?), so if you get any errors, let me know, and I will stop being lazy.

        Of course, you can concatenate the code the way you have it. This just happens to be my coding style, because it will be so much easier for me to understand what the heck I was thinking if I look at this code again a few months from now, when I want to change the conditions or something else for that matter. I can just change the conditions code, and not bother with the rest of my code at all.
        Last edited by koganam; 06-01-2011, 08:54 PM.

        Comment


          #5
          Thank you for the suggestion. I will test it when I have chance again.

          I assume that the removedrawobject will only remove the unnecessary dots created by this particular coding segment.

          If it happens that, for the same price bar, it has another dots created by other coding segment, will this removedrawobject remove other dots too?

          Comment


            #6
            Originally posted by Benluk View Post
            Thank you for the suggestion. I will test it when I have chance again.

            I assume that the removedrawobject will only remove the unnecessary dots created by this particular coding segment.

            If it happens that, for the same price bar, it has another dots created by other coding segment, will this removedrawobject remove other dots too?
            RemoveDrawObject() is highly specific and targeted. It will remove ONLY the object that has the specified tag. If your DrawObjects have unique tags, then only one object can possibly be removed; the one that has the specified tag,

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            578 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            334 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            101 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            553 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            551 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X