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 SalmaTrader, 07-07-2026, 10:26 PM
        0 responses
        35 views
        0 likes
        Last Post SalmaTrader  
        Started by CarlTrading, 07-05-2026, 01:16 PM
        0 responses
        20 views
        0 likes
        Last Post CarlTrading  
        Started by CaptainJack, 06-17-2026, 10:32 AM
        0 responses
        12 views
        0 likes
        Last Post CaptainJack  
        Started by kinfxhk, 06-17-2026, 04:15 AM
        0 responses
        18 views
        0 likes
        Last Post kinfxhk
        by kinfxhk
         
        Started by kinfxhk, 06-17-2026, 04:06 AM
        0 responses
        20 views
        0 likes
        Last Post kinfxhk
        by kinfxhk
         
        Working...
        X