Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Question about Draw.Line()

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

    Question about Draw.Line()

    I am trying to change the values in Draw.Line() function regardless whether the price has been updated or not, here is what I did (with an event of a 1000ms timer):

    static double MyValue1;
    static double MyValue2;

    private void TimerEventProcessor(Object myObject, EventArgs myEventArgs)
    {
    TriggerCustomEvent(o =>
    {
    MyValue1 = MyValue1 + 0.001;
    MyValue2 = MyValue2 + 0.001;

    Print (MyValue1 + " " + MyValue2);

    Draw.Line(this, "myTag" + 1, false, CurrentBar, MyValue1, 0, MyValue2, Brushes.Black, DashStyleHelper.Solid, 1, true);


    }, null);
    }​

    The output window shows both MyValue1 and MyValue2 are updated every second, it seems that the timer works fine, but the line position stay the same until there is a price update

    Not sure what I had missed,

    Thanks so much!

    #2
    Hello warpinator,

    Thank you for your post.

    Just looking at this snippet it is not clear to me what could be happening.

    I recommend taking a look at the Help Guide which has sample script demonstrating how to properly implement a timer using TriggerCustomEvent:



    Please let me know if this doesn't guide you in the right direction.

    Comment


      #3
      Hi Gaby,

      Thanks so much for your reply, I read the document and made some modification, but the issue still exists.

      I attached a simple/meaningless indicator (the .zip file) just for the purpose of testing and reproducing the issue.

      What this indicator does is it moves a horizontal line up and down between the highest and lowest of previous day, at the speed of 5 points/second, and print the value (horizontal location) of the horizontal line in Output window every second.

      I get the correct value for line position in Output window, which is updated every second, but the line position on the chart stop moving when there is no price update or when I pause during replay (meanwhile the output window continues giving the correct values every second). I wouldn't have noticed this issue when there had been busy price actions, because the line position would change every second as I expected.

      Not sure what I had missed.

      Thanks again!!
      Attached Files
      Last edited by warpinator; 05-18-2024, 05:53 PM.

      Comment


        #4
        Hello warpinator,

        Thank you for your response.

        Have you tried calling ForceRefresh() in the script? This will force the chart visuals to re-render.

        Please see the Help Guide page below for more information and a code snippet.

        Comment


          #5
          Hi Gaby,

          Yes, ForceRefresh() fixed everything. Thanks so much!!

          Comment


            #6
            Gaby,

            ForceRefresh() does not seem to be working for me. The ForceRefresh manual page you linked to says
            In most cases, the conditions listed above should be satisfactory for rendering standard and custom chart objects; however for more advance programming concepts, there may be other situations you run into which would NOT force the chart to refresh (e.g., a user interacting with a custom control ). In these special cases, you can use the ForceRefresh() method to re-queue the render event.
            I have an indicator that is just such a case. It puts a menu in the title bar, one of whose entries is to toggle bar numbering on and off. If I set bar numbering on I have to manually force a refesh somehow for them to show.

            I put a print the line before the ForceRefresh() call and another the line after. Both prints happen so I am comfortable I am issuing the call.

            I also put a print the first thing in OnBarUpdate() and that print does not happen after calling ForceRefresh().

            Any suggestion for what the likely problem is? Shouldn't OnBarUpdate() be getting called after ding a ForceRefresh()?

            Thanks
            Last edited by ETFVoyageur; 05-20-2024, 11:21 AM.

            Comment


              #7
              Hello ETFVoyaguer,

              ForceRefresh() does not call OnBarUpdate(). This method is only resetting an internal marker used to determine if the chart visuals need to re-render.

              You may be thinking of the Update() method which forces the OnBarUpdate() method to be called for all data series.



              Please let us know if you have any further questions.

              Comment


                #8
                Thanks, but no joy. I tried calling Update() with the same result as before -- no call to OnBarUpdate(). Perhaps that is due to this line from the documentation you linked?
                If the values are already up to date, the Update() method will not be run.

                Comment


                  #9
                  Hello ETFVoyageur,

                  Yes, as stated in the Help Guide this method will only be run if the indicator values aren't already up to date with the current bar index. OBU will only update if there is (1) a bar update or (2) if there is a call to Update() and indicator values need to be updated.

                  Comment


                    #10
                    I see my reply got lost. Let me try again.

                    I'm not wedded to my approach of doing bar numbering from OnBarUpdate(). That just seemed like the obvious place to do it. Since it seems to be impossible to get the system to run a bar data refresh for my indicator, how do you suggest I go about it?
                    • The user commands turning on bar numbering by making a menu choice.
                    • I set a flag in the callback handler and that works fine if OnBarUpdate() does get called. I establish that by manually forcing it.
                    • Unfortunately, I have not been able to find a way to get my OnBarsUpdate() called automatically.
                    What I need is either a reliable way to get my OnBarUpdate() called for the series, or else an alternative way to paint selected bar numbers (e.g. every fifth bar). Can you suggest either a way to get my OnBarUpdate() called or else an alternative approach to ensuring a prompt reaction to the user command? There has to be some way to provide a timely response to the user command.

                    Comment


                      #11
                      Hello ETFVoyageur,

                      Since this is unrelated to the original post, your post was moved: https://forum.ninjatrader.com/forum/...rupdate-update

                      Comment


                        #12
                        Perhaps I misunderstand the various parts of the forum, but why did you move it to General Development? To me, it is about indicator development -- my indicator has an issue that I would like help understanding how to solve. I know that other indicator developers have had this same issue..

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                        0 responses
                        607 views
                        0 likes
                        Last Post Geovanny Suaza  
                        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                        0 responses
                        353 views
                        1 like
                        Last Post Geovanny Suaza  
                        Started by Mindset, 02-09-2026, 11:44 AM
                        0 responses
                        105 views
                        0 likes
                        Last Post Mindset
                        by Mindset
                         
                        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                        0 responses
                        560 views
                        1 like
                        Last Post Geovanny Suaza  
                        Started by RFrosty, 01-28-2026, 06:49 PM
                        0 responses
                        561 views
                        1 like
                        Last Post RFrosty
                        by RFrosty
                         
                        Working...
                        X