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

Day of Week Monday Not Working

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

    Day of Week Monday Not Working

    Hey,

    Maybe someone can help me out here. I am learning nt programming by writing code for very simple strategies.

    I have added at the beginning

    protected override void OnBarUpdate()
    {
    // Condition set 1

    // If it's Monday, do not trade.
    if (Time[0].DayOfWeek == DayOfWeek.Monday)
    {
    return;
    }
    else{ //Then check stuff and trade }

    however, in strategy backtesting, it shows that trades are entered on Mondays.

    My strategy is such that a position is opened on next candle (daily chart), so in the above code, no trades are entered on the Tuesday instead of Monday. So when I changed the day of the week to Sunday and then Friday, trades were still entered on the Monday.

    Is there any way I can stop entering trades on Mondays?

    #2
    Time[0] refers to your local time zone. Before you check for a Monday you need to convert your local time to exchange time. In a second step you need to determine the trading day and check whether the time is part of the trading day. Usually trades for trade date Monday are from both Sunday as Monday, as the Monday session may start on Sunday evening,

    Probably the following will do what you try to achieve

    Code:
    if(Bars.GetTradingDayFromLocal(Time[0]).DayOfWeek == DayOfWeek.Monday)
       return;

    Comment


      #3
      Hello Asimbhuta,

      Thank you for your note.

      Harry's response is correct in this matter. You will want to convert your time for the bar to get the Monday day.

      Let me know if I can be of further assistance.
      Cal H.NinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by jaybedreamin, Today, 05:56 PM
      0 responses
      3 views
      0 likes
      Last Post jaybedreamin  
      Started by DJ888, 04-16-2024, 06:09 PM
      6 responses
      18 views
      0 likes
      Last Post DJ888
      by DJ888
       
      Started by Jon17, Today, 04:33 PM
      0 responses
      1 view
      0 likes
      Last Post Jon17
      by Jon17
       
      Started by Javierw.ok, Today, 04:12 PM
      0 responses
      6 views
      0 likes
      Last Post Javierw.ok  
      Started by timmbbo, Today, 08:59 AM
      2 responses
      10 views
      0 likes
      Last Post bltdavid  
      Working...
      X