Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How can I update an indicator each second instead of tick or price change?

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

    How can I update an indicator each second instead of tick or price change?

    I created an indicator to show how long each non-time based bar takes to form.
    But it seems that the indicator updates only each tick, not each second.

    I used a seconds timer to update the Value[0] in the plot, like below.
    Print(thetime) works fine, but the plot update doesn't.


    lastTime = DateTime.Now;
    myTimer = new System.Timers.Timer(1000);
    myTimer.Elapsed += TimerEventProcessor;
    myTimer.Enabled = true;


    private void TimerEventProcessor(Object myObject, EventArgs myEventArgs) {
    TriggerCustomEvent(SetPriceMarker, 0, null);
    }

    private void SetPriceMarker(object dummy) {
    ChartControl.Dispatcher.InvokeAsync((Action)(() =>
    {
    int secs = (int)(DateTime.Now.Subtract(lastTime).TotalMinutes *60);
    string info = string.Format("{0:0}:{1:00}", secs/60, secs%60);

    Print(info); //works and prints every second

    //but these don't do anything before a tick appears:
    Draw.TextFixed(this, "WjaTimeInBar", info, TextPosition.TopRight, ChartControl.Properties.ChartText, ChartControl.Properties.LabelFont, Brushes.White, Brushes.White, 100);
    UpdateBar();
    }));
    }

    protected override void OnBarUpdate()
    {
    if (IsFirstTickOfBar || Calculate==Calculate.OnBarClose) {
    lastTime = Time[0];
    }
    UpdateBar();
    }

    private void UpdateBar() {
    if (State==State.Realtime) {
    Value[0] = DateTime.Now.Subtract(lastTime).TotalMinutes;

    } else if (State==State.Historical) {
    if (CurrentBar>1 && Time[0].Day==Time[1].Day) {
    Value[0] = Time[0].Subtract(Time[1]).TotalMinutes;
    }
    }
    }

    #2
    you can add data series of 1 second and plot using that dataseries

    Comment


      #3
      Can't, because I want to detect how long a 1000 tick or a Renko bar takes to form.
      Which I can't do using a 1 second series, without disrupting the view in the tick or renko chart.
      I'm just asking how to refresh/update the indicator panel using the timer, or at least force the drawText to display.

      Comment


        #4
        put it in your ninjascript

        it will not disrupt the view.
        place the value in BarsInProgress == 1 but plot on BarsInProgress ==0

        Comment


          #5
          I don't understand.
          can you supply an example script?

          Comment


            #6
            Hello wjadevries,

            Thank you for your post.

            How can I update an indicator each second instead of tick or price change?

            NinjaTrader cannot build bars based on a timer because bars are created using incoming tick data. Something you could do is calculate new plot values based on a timer instead of each time the bar updates. I have attached an example script demonstrating how to calculate new plot values based on a timer. In the example script, our timer calculates new values and those calculated values get set to plot in OnBarUpdate.

            I'm just asking how to refresh/update the indicator panel using the timer, or at least force the drawText to display.

            You could use ForceRefresh() to force chart visuals to re-render. As the chart is optimized on a timer, calling ForceRefresh() will NOT immediately trigger a render event. Calling ForceRefesh() simply re-queues the render event to trigger during the next timed event. In other words, it may take up to 250ms for the render event to function.

            Please see this help guide link for more information about ForceRefresh() - https://ninjatrader.com/support/help...rcerefresh.htm

            If you would like to calculate how long it takes a Renko bar to form, you could consider doing something similar to the BarTimes indicator located in our publicly available User App Share center.

            BarTimes - https://ninjatraderecosystem.com/use.../nt8-bartimes/

            Let us know if we may assist further.


            The NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The add-ons listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.
            Attached Files
            <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

            Comment


              #7
              Thanks.
              One more question:
              if I call ForceRefresh in an indicator that is in a separate panel, will it refresh the whole chart with all panels or just the indicator panel calling ForceRefresh()?

              Comment


                #8
                Hello wjadevries,

                Thank you for your note.

                Calling ForceRefresh() will refresh all render targets in a chart window, not just for an individual panel. This would include chart bars, indicators, and drawing objects. ForceRefresh() sets the entire chart's RenderTarget to be repainted which means any items in that RenderTarget would refresh.

                As the chart is optimized on a timer, calling ForceRefresh() will NOT immediately trigger a render event. Calling ForceRefesh() simply re-queues the render event to trigger during the next timed event. In other words, it may take up to 250ms for the render event to function.

                Please let us know if we may further assist.
                <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                670 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                379 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                111 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                575 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                582 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X