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

Restore closed position on market open

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

    Restore closed position on market open

    Hi Support!

    I am looking to avoid associated costs of holding a position overnight but still want a position to be in the direction of the last signal.

    In the pic below you will see that the strategy exits on session close. How can I get the strategy to automatically reenter the position as soon as the market reopens, based on the last signal?

    #2
    Hello TrendFollowingCapital,

    Thanks for your post.

    You could use a bool variable that is true or false that you set when you place your orders. For example, call the bool LastTradeLong. When you place a long order set the bool to true. When you place a short order set the bool false. The last placed order would provide the direction that the bool is set.

    Then using the system bool Bars.IsFirstBarOfSession to detect the first bar and using the bool LastTradeLong, place your entry order, for example:

    if (Bars.IsFirstBarOfSession)
    {
    if (LastTradeLong)
    {
    EnterLong();
    }
    else
    {
    EnterShort();
    }
    }


    Reference: https://ninjatrader.com/support/help...rofsession.htm
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Any updates?

      Comment


        #4
        Hello JonasZweig,

        Thanks for your post.

        Can you clarify what update you are looking for?

        Did you post in the wrong thread?
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Hi Paul

          Thank you for your response, now as this is an AUTOMATED strategy it's not as if I choose if there is a long or short entry at session close, it is just the last signal given before session close that will determine whether a long or short position is valid on session open, so how do I make sure that the last signal, whether long or short, will open on session open?

          Comment


            #6
            Hello TrendFollowingCapital,

            Thanks for your reply.

            The reply I provided in post 2 was based on your using a strategy, perhaps I was adding confusion by saying "When you place a long order set the bool to true. When you place a short order set the bool false." What I should have stated was, when the strategy places a long order, in the same code block as the order, set the bool to true. When the strategy places a short order, set the bool to false. The last entry placed by the strategy then controls the state of the bool.

            In Post 2 I showed example code that the strategy could use to enter a new trade at the first bar of the new session and would be in the same direction as the last trade of the prior session.

            Paul H.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by andrewtrades, Today, 04:57 PM
            1 response
            9 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by chbruno, Today, 04:10 PM
            0 responses
            6 views
            0 likes
            Last Post chbruno
            by chbruno
             
            Started by josh18955, 03-25-2023, 11:16 AM
            6 responses
            436 views
            0 likes
            Last Post Delerium  
            Started by FAQtrader, Today, 03:35 PM
            0 responses
            8 views
            0 likes
            Last Post FAQtrader  
            Started by rocketman7, Today, 09:41 AM
            5 responses
            19 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Working...
            X