Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

timestamp in graph

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

    timestamp in graph


    I would like to make an indicator that shows me the timestamp of each tick close, these timestamps will be joined by a line. As an example, the tick at 00:19 (x axis) will have a value of 1711066740​. My code is here but dont draw nothing:
    private int lastBarIndex = -1;
    private double lastTimestampValue = 0;

    protected override void OnBarUpdate()
    {
    // Asegurarte de que tienes suficientes datos
    if (CurrentBar < 1) return;

    // Obtener el timestamp del tick actual y convertirlo a un valor numérico (por ejemplo, segundos desde la medianoche)
    DateTime timestamp = Time[0];
    double secondsSinceMidnight = timestamp.TimeOfDay.TotalSeconds;

    // Verificar si es el primer tick procesado
    if (lastBarIndex == -1)
    {
    // Solo actualiza los valores sin dibujar una línea
    lastBarIndex = CurrentBar;
    lastTimestampValue = secondsSinceMidnight;
    }
    else
    {
    // Dibujar una línea desde el último tick hasta el actual
    Draw.Line(this, "line" + CurrentBar, false, lastBarIndex - CurrentBar, lastTimestampValue, 0, secondsSinceMidnight, Brushes.Blue, DashStyleHelper.Solid, 2);

    // Actualizar los valores para el próximo tick
    lastBarIndex = CurrentBar;
    lastTimestampValue = secondsSinceMidnight;
    }
    }

    }​

    #2
    Hello dcriador,

    Thank you for your post.

    Are there errors appearing on the Log tab of the Control Center?

    Is this script running Calculate.OnEachTick?

    To confirm the script is not drawing anything, if you open up the list of Drawing Objects on the chart is it blank?

    I recommend debugging using prints. Add prints (outside of any conditions) that print the date time of the bar and all values compared in every condition. I also suggest adding a print before your Draw.Line call that prints out the values being used to draw the line, such as lastBarIndex - CurrentBar, lastTimestampValue, and secondsSinceMidnight.

    It is very important to include a text label for each value and for each comparison operator in the print to understand what is being compared in the condition sets.

    ​I am happy to assist you with analyzing the output from the output window.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by charlesugo_1, 05-26-2026, 05:03 PM
    0 responses
    46 views
    0 likes
    Last Post charlesugo_1  
    Started by DannyP96, 05-18-2026, 02:38 PM
    1 response
    141 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 05-11-2026, 05:56 AM
    0 responses
    160 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 05-10-2026, 08:12 PM
    0 responses
    96 views
    0 likes
    Last Post CarlTrading  
    Started by Hwop38, 05-04-2026, 07:02 PM
    0 responses
    275 views
    0 likes
    Last Post Hwop38
    by Hwop38
     
    Working...
    X