Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Handle Entry After Exit On Session Close

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

    Handle Entry After Exit On Session Close

    How can I handle following situation is my Strategy ?

    1 Entered Long
    2 Exit On Session Close

    3. Market Open and Price is still in favor but due to Condition which says Enter on Crossover that is not there. -- But ideally I should be in the trade in Exit On Session Close is not there - But I must have to use exit on Session Close.
    Attached Files

    #2
    Hello futtrader,

    Thank you for your post.

    Can you clarify what the situation you're encountering is? Are you reporting your strategy is entering a position after the exit on session close behavior triggers?

    I look forward to your response.

    Comment


      #3
      Originally posted by NinjaTrader_Gaby View Post
      Hello futtrader,

      Thank you for your post.

      Can you clarify what the situation you're encountering is? Are you reporting your strategy is entering a position after the exit on session close behavior triggers?

      I look forward to your response.
      No, as per my Plan I must have to exit on Session Close. But my concern is if previous position is closed due to exit on Session Close Condition -then on market Open I should reenter the same position until the next Entry Condition triggered.

      Comment


        #4
        Hello,

        One way you could do this is to use a bool 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:

        Code:
        if (Bars.IsFirstBarOfSession)
        {
        if (LastTradeLong)
        {
        EnterLong();
        }
        }
        
        else
        EnterShort();
        Please let me know if you have any other questions.

        Comment


          #5
          Originally posted by NinjaTrader_Gaby View Post
          Hello,

          One way you could do this is to use a bool 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:

          Code:
          if (Bars.IsFirstBarOfSession)
          {
          if (LastTradeLong)
          {
          EnterLong();
          }
          }
          
          else
          EnterShort();
          Please let me know if you have any other questions.
          thanks but I only want to place the trade if

          Code:
          if (LastTradeLong && CurrentAskPrice() > LastTradeClosingPrice)
          {
          EnterLong();
          }
          
          if (LastTradeLong && CurrentAskPrice() < LastTradeClosingPrice)
          {
          EnterLong();
          }
          My question is how can I get the LastTradeClosingPrice Price ?
          Last edited by futtrader; 12-15-2023, 12:15 AM.

          Comment


            #6
            Hello,

            This can be accessed from the SystemPerformance.

            https://ninjatrader.com/support/help...erformance.htm


            Code:
            if (SystemPerformance.AllTrades.Count > 1)
            {
            Trade lastTrade = SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count - 1];
            
            Print(lastTrade.Exit.Price);
            }

            Comment


              #7
              Originally posted by NinjaTrader_Gaby View Post
              Hello,

              This can be accessed from the SystemPerformance.

              https://ninjatrader.com/support/help...erformance.htm


              Code:
              if (SystemPerformance.AllTrades.Count > 1)
              {
              Trade lastTrade = SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count - 1];
              
              Print(lastTrade.Exit.Price);
              }
              thanks Gaby.

              How can I say in Strategy Builder or Custom Ninjascript

              Basically if I met daily loss or daily profit --I don't want strategy to execute for the day.

              if (TodayRealizedProfit >50 || TodayRealizedLoss > 100)
              {
              return;
              }

              Comment


                #8
                Hello,

                Please see the link below which has a sample script demonstrating how to implement a daily loss limit in the Strategy Builder.

                https://forum.ninjatrader.com/forum/...ples#post93881

                Comment


                  #9
                  Originally posted by NinjaTrader_Gaby View Post
                  Hello,

                  Please see the link below which has a sample script demonstrating how to implement a daily loss limit in the Strategy Builder.

                  https://forum.ninjatrader.com/forum/...ples#post93881
                  thanks Gaby.

                  Is this right way to handle ?

                  Is there way when ProfitTarget or LossLimit Met for the day then it should not even call OnBarUpdate ?
                  Code:
                          protected override void OnBarUpdate()
                          {
                              if (Bars.IsFirstBarOfSession)
                              {
                                  currentPnL = 0;
                              }
                  
                              if (currentPnL >= ProfitTarget || currentPnL <= -LossLimit) {
                                  string returnMsg = Time[0] + ": " + currentPnL + " <= " + LossLimit + " DailyLoss Limit met, No more trade for the day";
                                  if (currentPnL >= ProfitTarget) {
                                      returnMsg = Time[0] + ": " + currentPnL + " >= " + ProfitTarget + " Profit Target Met, No More trade for the day";                    
                                  }
                                  Print(returnMsg);
                                  return;
                              }​

                  Comment


                    #10
                    Hello,

                    Yes, you can implement the loss limit and profit target that way.

                    OnBarUpdate() will be called until the strategy is disabled. Your return statement will ensure further processing will not be done if the DLL or profit target are met.

                    Please let us know if you have any other questions.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by NullPointStrategies, Today, 05:17 AM
                    0 responses
                    20 views
                    0 likes
                    Last Post NullPointStrategies  
                    Started by argusthome, 03-08-2026, 10:06 AM
                    0 responses
                    119 views
                    0 likes
                    Last Post argusthome  
                    Started by NabilKhattabi, 03-06-2026, 11:18 AM
                    0 responses
                    63 views
                    0 likes
                    Last Post NabilKhattabi  
                    Started by Deep42, 03-06-2026, 12:28 AM
                    0 responses
                    41 views
                    0 likes
                    Last Post Deep42
                    by Deep42
                     
                    Started by TheRealMorford, 03-05-2026, 06:15 PM
                    0 responses
                    45 views
                    0 likes
                    Last Post TheRealMorford  
                    Working...
                    X