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 charlesugo_1, 05-26-2026, 05:03 PM
        0 responses
        55 views
        0 likes
        Last Post charlesugo_1  
        Started by DannyP96, 05-18-2026, 02:38 PM
        1 response
        142 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 05-11-2026, 05:56 AM
        0 responses
        160 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 05-10-2026, 08:12 PM
        0 responses
        96 views
        0 likes
        Last Post CarlTrading  
        Started by Hwop38, 05-04-2026, 07:02 PM
        0 responses
        276 views
        0 likes
        Last Post Hwop38
        by Hwop38
         
        Working...
        X