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

enter positions x days prior to specific dates

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

    enter positions x days prior to specific dates

    Hello,

    I'm trying to enter and exit a position x number of days prior and after a specific date. I have the exit condition working but not the enter. Here's what i have so far.

    #region Variables
    // Wizard generated variables
    private int entD = 1; // Default setting for EntD
    private int extD = 1; // Default setting for ExtD

    protected override void OnBarUpdate()
    {
    // Condition set 1
    if (ToDay(Time[0]) - EntD == 20091105 )
    {
    EnterLong(DefaultQuantity, "Ent1");
    }

    // Condition set 2
    if (ToDay(Time[0]) - ExtD > 20091105 )
    {
    ExitLong("DefaultQuantity", "Ent1");
    }
    }

    Thanks

    #2
    wahooj, please add a visual check to your entry to see if the condition evaluates to 'true' at all, was this a valid trading day and do you have data for this day present?
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Bertrand,

      I see what's is happening. I do have data for my specific dates. If my variable days lands on a weekend or holiday it will skip those days and execute on the next available trading, which is fine.
      There is one issue though. If I set the exit variable to extend into the next month it will only exit on the first day of the month. So, if the last day of any given month is the 30th and my variable wants to exit on the 2nd of the following month it tries to exit on the 32nd, which doesn't exist.
      How can i fix that?

      Comment


        #4
        wahooj, you will probably have to start working directly with the DateTime objects. There is a reference sample that deals with manipulating DateTime objects, which will probably help you on your quest.
        AustinNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by algospoke, Today, 06:40 PM
        0 responses
        4 views
        0 likes
        Last Post algospoke  
        Started by maybeimnotrader, Today, 05:46 PM
        0 responses
        7 views
        0 likes
        Last Post maybeimnotrader  
        Started by quantismo, Today, 05:13 PM
        0 responses
        6 views
        0 likes
        Last Post quantismo  
        Started by AttiM, 02-14-2024, 05:20 PM
        8 responses
        168 views
        0 likes
        Last Post jeronymite  
        Started by cre8able, Today, 04:22 PM
        0 responses
        9 views
        0 likes
        Last Post cre8able  
        Working...
        X