Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

What day is it?

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

    What day is it?

    Will we be able to determine what day it is in a strategy? For example, I don't like to trade on Fridays.

    If Monday, Tuesday, Wednesday, Thursday
    and SMA5>SMA20

    Enter long 1 contract.

    #2
    Hello mainstream,

    As far as I know this is not supported. However, I suggest not to run the strategy on Friday and run it for the days you like to trade.

    Comment


      #3
      ok thanks.

      Comment


        #4
        Code:
        [SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] ([/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]DateTime[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].Now.DayOfWeek == [/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]DayOfWeek[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].Friday)[/SIZE]
        [SIZE=2]{[/SIZE]
        [SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]// dont't trade[/COLOR][/SIZE]
        [/COLOR][/SIZE][SIZE=2]}[/SIZE]

        Comment


          #5
          C# is available to help

          Don't forget that NinjaScript is operating in C#. There are programming features available in C#, so NinjaTrader doesn't need to add them. The DateTime object in C# includes a DayOfWeek property you can use.

          Add the following declaration to your Variables:

          DateTime myDate = new DateTime();

          In your OnBarUpdate handler, add the following:

          myDate = DateTime.Today;
          if ( myDate.DayOfWeek != DayOfWeek.Friday )
          {
          // Put your normal strategy logic here.
          }

          This will work for real-time strategies, but not for backtesting, since DateTime.Today returns the current date, not the simulated date. Check out MSDN for other methods you can use to evaluate backtest dates:

          http://msdn.microsoft.com/en-us/libr...ds(VS.80).aspx

          j2

          Comment


            #6
            Great. Thank you.

            Comment

            Latest Posts

            Collapse

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