Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Programming an event to occur once every 5 seconds?

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

    Programming an event to occur once every 5 seconds?

    I am trying to create a strategy to change a double value once every 5 seconds. I am using the DateTime class but I'm not sure if this is the right way to do it.

    Code:
    #region Variables
    ...
    private DateTime Timer = DateTime.Now;
    private double myPrice = 0;
    private bool firstrun = true;
    ...
    #end region
    
    protected override void OnBarUpdate()
    {
    if (firstrun = true)
    {
            Timer.AddSeconds(DateTime.Now.Second+5);
            firstrun = false;
    }
    
    if(Timer.Second > DateTime.Now.Second)
    {
               Timer.AddSeconds(-1);
               if(Timer.Second==DateTime.Now.Second)
               {
                     LongBreakoutPrice = GetCurrentAsk();
                     Timer.AddSeconds(DateTime.Now.Second+5);
               }
    }
    }
    Is there a timer class? I'm trying to make a time value to be 5 seconds greater than the current time, and then subtract it by 1 second. This looks like a HORRIBLE way to implement it but I have no idea where to start. I tried compiling a strategy to run like this and to draw a line on the chart where the double value is and it is not really working the way I want it to. And can I have the statement Timer.AddSeconds(DateTime.Now.Second+5); under void initialize()?
    Last edited by dennho; 01-27-2010, 05:28 AM.

    #2
    dennho, please review the reference sample below dealing with the TriggerCustomEvent() you could use for this task - http://www.ninjatrader-support2.com/...ead.php?t=5965

    Comment


      #3
      Thanks for the heads up. Can you apply this to strategies as well? Or is this limited only to indicators?

      Comment


        #4
        You're welcome, applicable to both indicators and strategies.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        566 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        330 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
        547 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        548 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X