Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Seasonal Analysis in Ninja Script

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

    Seasonal Analysis in Ninja Script

    Hi Support Team,

    I strongly try to create a ninja script which does allow to enter the day of the month and the month itself and to backtest the last 10 or 20 years.
    The strategy builder I used for the beginning and later I adjusted the code. Basically the code does work, but the problem is that when the Startday or Endday of the month is on weekends, the ninja script does not work and takes other years (see attachement).


    Would be appreciated for your support to get this code fixed.

    Thanks and have a great weekend.

    Regards

    Stefan






    #2
    Hello Stefan1982,

    Thank you for your post.

    It sounds like you need to add additional logic to error check your input parameters when you have a new year.

    So something like this:

    Code:
    DateTime ValidDay = new DateTime(Time[0].Year, inputMonth, inputDay);
    if (ValidDay.DayOfWeek == DayOfWeek.Saturday)
    {
        //do stuff to hanlde differently, the input month/year results in in an enter/exit on saturday
    }
    We'd suggest checking that when Time[0].Year changes. The DateTime class has methods like AddMinute() and AddDay() that you could utilize to make sure your entries are on a weekday as you'd intend.

    Please let us know if we may be of further assistance to you.
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Hi Kate,

      many many thanks for your good support.


      I added the function what your recommended, but it does not work, results are the same. Somehow I need to conncet valid date properly to the startdate???

      Do you have an idea, how to fix this and to show all years? Many thanks

      Stefan
      Attached Files
      Last edited by Stefan1982; 08-10-2020, 02:42 AM.

      Comment


        #4
        Hello Stefan,

        Thank you for your reply.

        So you're creating a new DateTime 4 times when you really only need two, but then you aren't using that adjusted DateTime in your conditions for your entries and exits. Try something like this:

        Code:
                    DateTime ValidStartDay = new DateTime(Time[0].Year, Startmonth, Startday);
                    DateTime ValidEndDay = new DateTime(Time[0].Year, Endmonth, Endday);
        
                    if (ValidStartDay.DayOfWeek == DayOfWeek.Saturday)
                    {
                        ValidStartDay = ValidStartDay.AddDays(2);
                    }
                    else if (ValidStartDay.DayOfWeek == DayOfWeek.Sunday)
                    {
                        ValidStartDay = ValidStartDay.AddDays(1);
                    }
        
                    if(ValidEndDay.DayOfWeek == DayOfWeek.Saturday)
                    {
                        ValidEndDay = ValidEndDay.AddDays(2);
                    }
                    else if (ValidEndDay.DayOfWeek == DayOfWeek.Sunday)
                    {
                        ValidEndDay = ValidEndDay.AddDays(1);
                    }
        
                    if(Times[0][0].Day == ValidStartDay.Day && Times[0][0].Month == ValidStartDay.Month)
                    {
                        EnterLong();
                    }
                    if(Times[0][0].Day == ValidEndDay.Day && Times[0][0].Month == ValidEndDay.Month)
                    {
                        ExitLong();
                    }
        Please let us know if we may be of further assistance to you.
        Kate W.NinjaTrader Customer Service

        Comment


          #5
          Hey Kate,

          I just checked and looks very good. Many thanks for your ***** support.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by vivek.n, Today, 03:19 AM
          0 responses
          4 views
          0 likes
          Last Post vivek.n
          by vivek.n
           
          Started by ashwagandhaplus, Today, 12:04 AM
          0 responses
          6 views
          0 likes
          Last Post ashwagandhaplus  
          Started by ashwagandhaplus, Today, 12:02 AM
          0 responses
          9 views
          0 likes
          Last Post ashwagandhaplus  
          Started by truvalastfrnce, Today, 12:01 AM
          0 responses
          5 views
          0 likes
          Last Post truvalastfrnce  
          Started by truvalastfrnce, Today, 12:00 AM
          0 responses
          4 views
          0 likes
          Last Post truvalastfrnce  
          Working...
          X