Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to sync indicator or drawing tool chart painting with current price painting?

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

    How to sync indicator or drawing tool chart painting with current price painting?

    I see there is a delay many times (0.25s - 1s) between current price being painted on the chart and "OnRender" function of the indicator or a drawing tool being painted on the chart.

    For example if I take the built in indicator "Bar Timer", and let's say I want the remaining time to be painted always near the current price instead of the default bottom right.

    So I changed / added the following:

    Code:
    private double currentPrice;
    public SpaceFrom = 1; // OnStateChange -> State.SetDefaults​
    ​
    protected override void OnBarUpdate()
    {
        currentPrice = Close[0];
    ​}
    
    private void OnTimerTick(object sender, EventArgs e)
    {
    
        // Draw.TextFixed was replaced with Draw.Text
    
        Draw.TextFixed(this, "NinjaScriptInfo", NinjaTrader.Custom.Resource.BarTimerTimeRemaining + timeLeft, TextPosition.BottomRight, ChartControl.Properties.ChartText, ChartControl.Properties.LabelFont, Brushes.Transparent, Brushes.Transparent, 0); // removed
    
        Draw.Text(this, "MyIndicator", false, timeLeft, -SpaceFrom, currentPrice, 0, ChartControl.Properties.ChartText, ChartControl.Properties.LabelFont, TextAlignment.Left, Brushes.Transparent, Brushes.Transparent, 0); //added​
    ​}
    The indicator and the time left calculation works properly and it's being painted in the right place. But when there is a price change, many times the paint itself isn't in sync with current price Y axis. It takes about 0.5-1 seconds to catch up with current price Y point.

    How can I fix it?

    Same happens with Drawing Tools. The "OnRender" function is delayed compering to current price changes.
    Last edited by xfactscout; 07-23-2024, 04:53 AM.

    #2
    Can anyone help with that? Or point me to the right direction?
    Will really appreciate it.

    Comment


      #3
      Hello xfactscout,

      Chart indicators update every 250 milliseconds. Unfortunately, this cannot be adjusted.

      If the OnTimerTick is from a timer Tick event, this would be a non-data-driven-method and would require calling TriggerCustomEvent() before calling a Draw method or using any method with a barsAgo value or using anything related to a Series<T>.


      If making a visual change, you can call ForceRefresh() to ensure the chart updates on the next render round.

      Chelsea B.NinjaTrader Customer Service

      Comment


        #4
        Thank you ChelseaB.

        Was able to sync it in the Indicator.

        Will try soon in the Drawing Tool as well.
        Last edited by xfactscout; 07-29-2024, 03:02 AM.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        558 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        324 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
        545 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        547 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X