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 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