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

How to Limit Code to Executing Once per Day

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

    How to Limit Code to Executing Once per Day

    Hi All,

    I am trying to limit my code to executing only once per day while having COBC = false. I started with what I found previously:

    if (CurrentBar < 2) return;
    if (Time[0].DayOfWeek != Time[1].DayOfWeek) // new day, reset bool flag
    {
    signalMadeToday = false;
    }

    if(signalMadeToday = false)
    {....Code...
    signalMadeToday = true;
    }


    But when I have COBC = false, it constantly resets. I took a look at the printed output with the following and can see the first print shows a bool of True, while the second shows False.

    if (CurrentBar < 2) return;
    if (Time[0].DayOfWeek != Time[1].DayOfWeek) // new day, reset bool flag
    {
    Print(signalMadeToday.ToString());
    signalMadeToday = false;
    Print(signalMadeToday.ToString());
    }

    What is the issue here? I saw a post about this that recommended to do the following:

    if (Bars.FirstBarOfSession)
    {
    // Store the strategy's prior number of trades
    priorTradesCount = Performance.AllTrades.Count;
    }

    {
    // Returns out of the OnBarUpdate() method. This prevents any further evaluation of trade logic in the OnBarUpdate() method.
    return;
    }

    But this caused my strategy to not function properly. I didn't spend too much time looking at this option, but even if it will work, it only pertains to trades (which is most important). But I also want to limit emails, drawing objects, etc., and I don't think this will do that.

    So what is the issue with the bool being reset even though the logic says it should not reset until the next day? How can I get it to stay true throughout the day with COBC = false? Or what other way can I simply limit the code to executing once per day whatever it may be?

    Thank you,

    Regards,

    Lee

    #2
    Hello Lee,

    if (Time[0].DayOfWeek != Time[1].DayOfWeek) // new day, reset bool flag
    {
    signalMadeToday = false;
    }
    This would be true throughout the day and therefore occur all day.

    Comment


      #3
      Originally posted by lee612801 View Post
      Hi All,

      I am trying to limit my code to executing only once per day while having COBC = false. I started with what I found previously:

      if (CurrentBar < 2) return;
      if (Time[0].DayOfWeek != Time[1].DayOfWeek && FirstTickOfBar) // new day, reset bool flag
      {
      signalMadeToday = false;
      }

      if(signalMadeToday = false)
      {....Code...
      signalMadeToday = true;
      }


      But when I have COBC = false, it constantly resets. I took a look at the printed output with the following and can see the first print shows a bool of True, while the second shows False.

      if (CurrentBar < 2) return;
      if (Time[0].DayOfWeek != Time[1].DayOfWeek) // new day, reset bool flag
      {
      Print(signalMadeToday.ToString());
      signalMadeToday = false;
      Print(signalMadeToday.ToString());
      }

      What is the issue here? I saw a post about this that recommended to do the following:

      if (Bars.FirstBarOfSession)
      {
      // Store the strategy's prior number of trades
      priorTradesCount = Performance.AllTrades.Count;
      }

      {
      // Returns out of the OnBarUpdate() method. This prevents any further evaluation of trade logic in the OnBarUpdate() method.
      return;
      }

      But this caused my strategy to not function properly. I didn't spend too much time looking at this option, but even if it will work, it only pertains to trades (which is most important). But I also want to limit emails, drawing objects, etc., and I don't think this will do that.

      So what is the issue with the bool being reset even though the logic says it should not reset until the next day? How can I get it to stay true throughout the day with COBC = false? Or what other way can I simply limit the code to executing once per day whatever it may be?

      Thank you,

      Regards,

      Lee
      Addition in red in your original code.

      Comment


        #4
        Great, I will give this a try! I am running day bars btw.

        Thanks for the response and help!

        Regards,

        Lee

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by halgo_boulder, 04-20-2024, 08:44 AM
        2 responses
        21 views
        0 likes
        Last Post halgo_boulder  
        Started by mishhh, 05-25-2010, 08:54 AM
        19 responses
        6,189 views
        0 likes
        Last Post rene69851  
        Started by gwenael, Today, 09:29 AM
        0 responses
        5 views
        0 likes
        Last Post gwenael
        by gwenael
         
        Started by Karado58, 11-26-2012, 02:57 PM
        8 responses
        14,830 views
        0 likes
        Last Post Option Whisperer  
        Started by Option Whisperer, Today, 09:05 AM
        0 responses
        2 views
        0 likes
        Last Post Option Whisperer  
        Working...
        X