Time Seconds not calculating correctly.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #105440 quote
    VonasiVonasi
    Moderator
    Master

    I was considering coding an indicator to detect the time frame of a chart but I was getting strange results on a 1 second chart. Here is a simple code that should calculate what the current seconds are from the open time but sometimes it returns a negative number for the seconds!

    The 2nd image is returning just SS.

    hhmmss = opentime
    hhmm = (round(opentime/100))*100
    hh = (round(opentime/10000))*10000
    ss = hhmmss - hhmm
    
    return  ss as "ss", hhmmss as "hhmmss", hhmm as "hhmm", hh as "hh"
    Screenshot_3-3.png Screenshot_3-3.png Screenshot_4-1.png Screenshot_4-1.png
    #105443 quote
    VonasiVonasi
    Moderator
    Master

    After a little further testing it seems that on a 20 second or 30 second or 40 second or 50 second chart it Calculates SS correctly but on any other chart it returns minus numbers.

    Screenshot_5-2.png Screenshot_5-2.png
    #105445 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    Rounding hhmm when it’s 204040 will return 204000,  when it’s 204050 will return 204100.

    You should subtract-0.5 to return always 204000.

    #105447 quote
    VonasiVonasi
    Moderator
    Master

    Thanks Roberto – I knew that it was something obvious that I had forgotten!

    hhmmss = opentime
    hhmm00 = (round(opentime/100-0.5))*100
    hh0000 = (round(opentime/10000-0.5))*10000
    ss = hhmmss - hhmm00
    mm = (hhmmss - hh0000 - ss)/100
    hh = hh0000/10000
    
    
    
    return  mm as "mm", ss as "ss", hh as "hh", hhmmss as "hhmmss"
    Screenshot_6-2.png Screenshot_6-2.png
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.
ProRealAI ProRealAI New

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

Time Seconds not calculating correctly.


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
Vonasi @vonasi Moderator
Summary

This topic contains 3 replies,
has 2 voices, and was last updated by VonasiVonasi
7 years, 1 month ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 08/24/2019
Status: Active
Attachments: 4 files
ProRealCode ProRealCode
Loading...