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 CarlTrading, 03-31-2026, 09:41 PM
        1 response
        152 views
        1 like
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        87 views
        1 like
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        131 views
        2 likes
        Last Post CaptainJack  
        Started by CarlTrading, 03-30-2026, 11:51 AM
        0 responses
        127 views
        1 like
        Last Post CarlTrading  
        Started by CarlTrading, 03-30-2026, 11:48 AM
        0 responses
        106 views
        0 likes
        Last Post CarlTrading  
        Working...
        X