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

Option expiration date

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

    Option expiration date

    Hello,

    I'm trying to back-test an option strategy. I would like to add a condition where a long position or a short position closes every 3rd Friday of the month because then the options expire. How can I build this condition in strategy builder? Someone who can help me with this?

    #2
    Hello Jimmy73,

    Thanks for your post.

    Options support on the NinjaTrader platform is in a preliminary phase. NinjaScript strategies are not yet supported. Support for NinjaScript strategies is intended for some point in the future, but we cannot offer an ETA on when that support will be available.

    Let us know if you have any questions.
    JimNinjaTrader Customer Service

    Comment


      #3
      Ok, thanks anyway for your reaction.

      Comment


        #4
        Is there maybe a way to do this with a certain code in Ninjascript instead of doing this in Strategy Builder?
        I don't think it's going to be easy to write a code to determine every 3rd Friday of the month together with closing a long position or a short position.
        Is there anyone who can help me get started with this?

        Comment


          #5
          I think i found it in the topic with the link below :


          Comment


            #6
            I cannot make it work to close an open position on every 3rd friday of the month.
            I have found an indicator that marks a weekday or every 3rd friday of the month but it is written for Ninjatrader 7. Is there a way to convert this to Ninjatrader 8?
            Attached Files

            Comment


              #7
              Hello Jimmy73,

              You will need the source code if you want to convert the indicator to NinjaTrader 8. If you have the source code, you can use our Code Breaking Changes page of the Help Guide to direct you further for implementation changes and changes to NinjaScript objects from NinjaTrader 7 to NinjaTrader 8.

              Code Breaking Changes - https://ninjatrader.com/support/help...ng_changes.htm

              You could use DateTime checks to see if Time[0] is the third Friday of the month. The example code below should get you moving in the right direction.

              Code:
              private int lastMonth = 0;        
              private int fridayCount = 0;
              
              protected override void OnBarUpdate()
              {
                  if (Time[0].Month != lastMonth)
                  {
                      lastMonth = Time[0].Month;
                      fridayCount = 0;
                  }
                  if (Time[0].DayOfWeek == DayOfWeek.Friday)
                      fridayCount++;
              
                  if (fridayCount == 3 && Time[0].DayOfWeek == DayOfWeek.Friday)
                  {
                      Draw.Dot(this, "tag" + CurrentBar, true, 0, High[0] + 5 * TickSize, Brushes.White);
                  }
              }
              More information on working with DateTime objects can be found publicly on Microsoft's MSDN resources - https://docs.microsoft.com/en-us/dot...tframework-4.5

              Another publicly available resource can be found here - https://www.dotnetperls.com/datetime

              We look forward to assisting.
              JimNinjaTrader Customer Service

              Comment


                #8
                Thanks Jim,

                Your peace of code was the missing link!
                I've added this code in my strategie and now it works just fine.

                Thanks again for your help!

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by wzgy0920, 04-20-2024, 06:09 PM
                2 responses
                26 views
                0 likes
                Last Post wzgy0920  
                Started by wzgy0920, 02-22-2024, 01:11 AM
                5 responses
                32 views
                0 likes
                Last Post wzgy0920  
                Started by wzgy0920, Yesterday, 09:53 PM
                2 responses
                49 views
                0 likes
                Last Post wzgy0920  
                Started by Kensonprib, 04-28-2021, 10:11 AM
                5 responses
                192 views
                0 likes
                Last Post Hasadafa  
                Started by GussJ, 03-04-2020, 03:11 PM
                11 responses
                3,235 views
                0 likes
                Last Post xiinteractive  
                Working...
                X