Jump to content

Need exact timers for 1 min, 5 min, 15min etc


Recommended Posts

Hey guys, I am working on a script. It feeds an array every quarter second, turns a toggle to true after 30 seconds and finally runs a func at full speed.

Currently full speed is about 100 loops a second. I need it to stay around that time.

Here's the issue. I Need some sort of indicator every 1 minute, 5 minutes, 15 minutes, 30 minutes, 60 minutes, and 24 hours.

It will call a function for each that can only run once per related indicator and then wait till it x minutes again to run.

-it cant be missed, it cant be run twice before the next time period.

@ 1 min call func1 (loop)

@ 5 min call func2 (loop)

@ 15 min call func3 (loo)

So at 15 min it would really call, func1, then, func2 then func3 because all three are at their next period.

As you can see below, it is close but has issues. -it could run in between periods a few times . . . thats bad.

$PushArrayStart = _Timer_Init()
$StartSpikeTestTimer = _Timer_Init()


While 1
    Offers()
    If _Timer_Diff($PushArrayStart) >= 250 Then
        _ArrayPush($RateStore, $BidStore)
        $PushArrayStart = _Timer_Init()
    EndIf
    If _Timer_Diff($StartSpikeTestTimer) >= 30000 And _Timer_Diff($StartSpikeTestTimer) <= 30510 Then
        $EnableTestSpike = True
    EndIf
WEnd
Link to comment
Share on other sites

The way you're using them, the UDF functions _Timer_Init() and _Timer_Diff() are no different than the built-in functions TimerInit() and TimerDiff().

Take a look instead at _Timer_SetTimer(), which will let you register callbacks to functions.

The code you posted doesn't show any 1/5/15/30/60m / 24h intervals.

If the issue you're describing is the .51 second window where $EnableTestSpike is being set, then why not reset $StartSpikeTestTimer after 30 seconds the same way you're resetting $PushArrayStart?

[font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font]

Link to comment
Share on other sites

I think the easiest here would be _Timer_SetTimer(), you can find under "Timers Management" in the helpfile.

Edit: Skruge writes faster than me :P

Edited by AdmiralAlkex
Link to comment
Share on other sites

Hey, I haven't added the others yet. I was pointong out the flaw in the method I have. the new addins cant afford to run more than once per period.

If _Timer_Diff($StartSpikeTestTimer) >= 30000 And _Timer_Diff($StartSpikeTestTimer) <= 30510 Then
        $EnableTestSpike = True
    EndIf

This is reset in the main function loop. It resets at the bottom of the section if it is allowed to enter that section (toggle entry)

problem = I need the functions to run once.

I am betting that $EnableTestSpike is set to True 10-50 times before _Timer_Diff($StartSpikeTestTimer <= 30510 -but it has working in the main loop that takes longer than that so i was ok until now.

Edited by Hatcheda
Link to comment
Share on other sites

Hey, I haven't added the others yet. I was pointong out the flaw in the method I have. the new addins cant afford to run more than once per period.

If _Timer_Diff($StartSpikeTestTimer) >= 30000 And _Timer_Diff($StartSpikeTestTimer) <= 30510 Then
        $EnableTestSpike = True
    EndIf

This is reset in the main function loop. It resets at the bottom of the section if it is allowed to enter that section (toggle entry)

problem = I need the functions to run once.

I am betting that $EnableTestSpike is set to True 10+ times before _Timer_Diff($StartSpikeTestTimer <= 30510

That was what Skruge talked about in his last line:

If the issue you're describing is the .51 second window where $EnableTestSpike is being set, then why not reset $StartSpikeTestTimer after 30 seconds the same way you're resetting $PushArrayStart?

Just do with $StartSpikeTestTimer as you do with $PushArrayStart..... And you may aswell use the inbuilt TimerInit/TimerDiff to gain some speed.
Link to comment
Share on other sites

That was what Skruge talked about in his last line:

Just do with $StartSpikeTestTimer as you do with $PushArrayStart..... And you may aswell use the inbuilt TimerInit/TimerDiff to gain some speed.

Hey, I can't . . . To explain:

$EnableTestSpike = True is like a fishing pole. It is set to not fish until 30 seconds after the script starts.

After that my array from $PushArrayStart is built and it goes fishing. It may fish for 10 seconds or 3 days. (Fishing is checking the array for data with each cycle)

If it catches (finds spike) it opens another toggle and closes ($EnableTestSpike = False) . The next toggled section may run 2 loops, it may run 300 loops. Then at the last run it resets the $StartSpikeTestTimer to open the loop again.

Its just that it never hits at exactly 30000 so I had to expand it.

As for _Timer_SetTimer($hGUI, 1000, "_UpdateStatusBarClock") ; create timer

This was the first thing I looked at. I have to say its the worst help section in the book. Far to over written. Can anyone simplify this. What does it have to do with a gui?

Any simple example? Thanks!

Link to comment
Share on other sites

That's just how that func works, you can read more at MSDN. The gui doesn't need to be visible or anything, just do:

$hWnd = GuiCreate("something")
_Timer_SetTimer($hWnd, 30000, "somefunc")
Edited by AdmiralAlkex
Link to comment
Share on other sites

Ok, will give it a go! Thanks for the tip on changing out _Timer_Diff.

If all works I can replace

If _Timer_Diff($StartSpikeTestTimer) >= 30000 And _Timer_Diff($StartSpikeTestTimer) <= 30510 Then

$EnableTestSpike = True

EndIf

As a one line function

$EnableTestSpike = True

and just set a timer for it at the beginning of the script and end of the second toggle.

Thanks alot!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...