Announcement

Collapse
No announcement yet.

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?

    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 Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        648 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        369 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        108 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        572 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        573 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X