Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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
    BertrandNinjaTrader Customer Service

    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.
        BertrandNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by TraderBCL, Today, 04:38 AM
        2 responses
        16 views
        0 likes
        Last Post TraderBCL  
        Started by martin70, 03-24-2023, 04:58 AM
        14 responses
        106 views
        0 likes
        Last Post martin70  
        Started by Radano, 06-10-2021, 01:40 AM
        19 responses
        609 views
        0 likes
        Last Post Radano
        by Radano
         
        Started by KenneGaray, Today, 03:48 AM
        0 responses
        5 views
        0 likes
        Last Post KenneGaray  
        Started by thanajo, 05-04-2021, 02:11 AM
        4 responses
        471 views
        0 likes
        Last Post tradingnasdaqprueba  
        Working...
        X