Announcement

Collapse
No announcement yet.

Time trigger not activating

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

  • Time trigger not activating

    Hi all,

    I'm trying to create an event that is triggered at an exact time. However, either my code is faulty or I can only assume that the EFS code is only run when a new tick comes in and unless a new tick comes in right at the exact second I'm trying to hit, my code doesn't get executed.

    My example code below:

    var now = new Date();
    var tMinute = now.getMinutes();
    var tSecond = now.getSeconds();

    if (tMinute == 15 && tSecond == 50) {
    Alert.playSound("chime down.wav")
    }

    Please let me know if there's any way to circumvent this issue, or if you can offer any hints or help at all it would be much appreciated.

    PS. I'm planning to get the time issue correct with an alert, but I want to eventually add a strategy buy, then eventually a market order if all goes well.

    Cheers,

    Scott

  • #2
    You are correct. A script which doesn't have setComputeOnClose() placed in the preMain() function will only executed the main() loop when a new tick comes in and that may not always be on the precise second you want.

    Instead of an exact second, you'll check a range of seconds and if a tick comes in within that time span, then you'll set a flag that it's been signaled and you won't reset it (the alert) until, for example, the next minute ticks over.

    So, something like:

    var triggered = false;
    ...
    //
    // assumption here is that you'll at least 1 tick coming in within a 10 second period
    //
    if (tMinute == 15 && tSecond >= 50 && tSecond <= 59 && triggered == false) {
    triggered = true;
    Alert.playSound("chime down.wav");
    }

    if (tMinute == 16) {
    triggered = false;
    }

    Dunno exactly when you want to reset your trigger. It could be on a new bar coming in [if (getBarState() == BARSTATE_NEWBAR)], etc. but I think you get the idea now.

    Yeah, bummer...even though they use Javascript, they don't have any concept of a timer which forces your script to execute at a certain time.

    Comment


    • #3
      Thanks Steve. I thought that might be the case.

      Scott

      Comment

      Working...
      X