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

Close Open Position at 09:00 AM

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

    Close Open Position at 09:00 AM

    Hi,

    I'm trying to create a strategy to close any open positions at a certain time of day, but I can't get it to work. I'm using the strategy builder and I have the following conditions:

    // Condition set 1
    if (ToTime(Time[0]) == ToTime(9, 0, 0)
    && Position.MarketPosition == MarketPosition.Long)
    {
    ExitLong(
    "", "");
    }
    // Condition set 2
    if (ToTime(Time[0]) == ToTime(9, 0, 0)
    && Position.MarketPosition == MarketPosition.Short)
    {
    ExitShort(
    "", "");
    }

    What am I doing wrong?

    Thanks.

    #2
    Bob,

    I'm not sure but I think it's simply a matter of changing your ToTime(9, 0, 0) to the integer form of 9:00 am which I believe is 090000.

    Comment


      #3
      *without seeing your enterlong code, & assuming you are using "" ....

      then enter here:


      If you are using OnBarUpdate, 9:00:00 am might never have a trade....and your code might never execute.

      You probably would be better with some sort of epsilon or something

      try checking for 9:00:00 to 9:05:00... ??

      or add a timer to fire at 9:00 am or something...








      Originally posted by bob77713 View Post
      Hi,

      I'm trying to create a strategy to close any open positions at a certain time of day, but I can't get it to work. I'm using the strategy builder and I have the following conditions:

      // Condition set 1
      if (ToTime(Time[0]) == ToTime(9, 0, 0)
      && Position.MarketPosition == MarketPosition.Long)
      {
      ExitLong(
      "", "");
      }
      // Condition set 2
      if (ToTime(Time[0]) == ToTime(9, 0, 0)
      && Position.MarketPosition == MarketPosition.Short)
      {
      ExitShort(
      "", "");
      }

      What am I doing wrong?

      Thanks.

      Comment


        #4
        Coolmoss,

        I'm using the strategy builder and you can only enter a time, which 09:00 AM equates to (9, 0, 0).

        Sledge,

        You got me thinking about the time, so I tried some different options with time and >= variables and the strategy still won't close the trades.

        Thanks for your help guys. I'll keep on searching, this shouldn't be this hard.

        Comment


          #5
          Does anyone from Ninjatrader support know how to close all open positions at a certain time of day?

          Thank you.

          Comment


            #6
            Hello bob77713,

            Thank you for your post.

            You have the right concept here using ExitLong() and ExitShort() along with the idea of the >= operator.

            However, the bar would need to update on or after the time set. What bar type and interval are you using? (Example: 1 Minute)

            I look forward to your response.

            Comment


              #7
              Hi Patrick,

              I'm using UniRenko bars which I downloaded from NinjaTrader's forum.

              Thanks

              Comment


                #8
                Hello bob77713,

                Thank you for your response.

                So I may investigate this matter further please advise what the Open Offset, Tick Trend, and Tick Reversal are set to for the UniRenko bars you are using.

                Comment


                  #9
                  Hi Patrick,

                  40, 40, 120.

                  I appreciate your extra help.

                  Thank you.

                  Comment


                    #10
                    Hello bob77713,

                    Thank you for your response.

                    The Session Template you use, does it exceed 9 AM your time?

                    What instrument are you testing this item on?

                    Comment


                      #11
                      Hi Patrick,

                      The session template is Forex, so yes it exceeds 09:00 AM. One of the instruments is $EURUSD.

                      Thank you.

                      Comment


                        #12
                        Hello bob77713,

                        Thank you for your response.

                        From the details you have provided I would not think there should be any items that would prevent your code form running especially if using >=.

                        Can you provide your full code? If you prefer, you can send this to support[at]ninjatrader[dot]com with 'ATTN: Patrick - 869698' in the subject line and a reference to this thread in the body of the e-mail: http://www.ninjatrader.com/support/f...ad.php?t=58682

                        Comment


                          #13
                          Hi Patrick,

                          I removed the time coding because it was not working. I just added it back in to show you my coding and it's working fine now. Sorry about that.

                          I believe what happened is that I didn't change the == variable to >= like I thought I had. It's clear to me now, that you cannot use == for Renko bars, since the bar usually won't close at exactly at 09:00.

                          Thanks for all your help. Maybe someone will see the mistake which I made and will learn from it.

                          Thank you.

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Option Whisperer, Today, 09:55 AM
                          1 response
                          11 views
                          0 likes
                          Last Post bltdavid  
                          Started by port119, Today, 02:43 PM
                          0 responses
                          1 view
                          0 likes
                          Last Post port119
                          by port119
                           
                          Started by Philippe56140, Today, 02:35 PM
                          0 responses
                          3 views
                          0 likes
                          Last Post Philippe56140  
                          Started by 00nevest, Today, 02:27 PM
                          0 responses
                          2 views
                          0 likes
                          Last Post 00nevest  
                          Started by Jonafare, 12-06-2012, 03:48 PM
                          5 responses
                          3,986 views
                          0 likes
                          Last Post rene69851  
                          Working...
                          X