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 CarlTrading, 05-11-2026, 05:56 AM
            0 responses
            25 views
            0 likes
            Last Post CarlTrading  
            Started by CarlTrading, 05-10-2026, 08:12 PM
            0 responses
            19 views
            0 likes
            Last Post CarlTrading  
            Started by Hwop38, 05-04-2026, 07:02 PM
            0 responses
            182 views
            0 likes
            Last Post Hwop38
            by Hwop38
             
            Started by CaptainJack, 04-24-2026, 11:07 PM
            0 responses
            335 views
            0 likes
            Last Post CaptainJack  
            Started by Mindset, 04-21-2026, 06:46 AM
            0 responses
            260 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Working...
            X