Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Stop Trading Activity 1 Hour before end of trading day

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

    Stop Trading Activity 1 Hour before end of trading day

    Hello NT Team,

    I want to stop trading activity 1 hour prior to market day trading closing time, and I came across this code in your NT8 DOC, but when I added it is shows me several erros

    This is the code I found : https://ninjatrader.com/support/helpGuides/nt8/

    Code:
    private SessionIterator sessionIterator;
    
    protected override void OnStateChange()
    {
      if (State == State.DataLoaded)
      {
        //stores the sessions once bars are ready, but before OnBarUpdate is called
        sessionIterator = new SessionIterator(Bars);
      }
    }
    
    protected override void OnBarUpdate()
    {
      // Only process strategy logic up until three hours prior to the end of the trading day at the exchange
      if (DateTime.Now <= sessionIterator.GetTradingDa yEndLocal(Bars.SessionIterator.ActualTradingDayExc hange).AddHours(-3))
      {
          // Strategy logic here
      }
    }
    I did all what I'm supposed to do, declarations, initiations and everything just as mentioned here, but same error which I attached here

    Can you please tell me how to do it the right way ?

    This is the code snippet I'm using now :


    Code:
    if (DateTime.Now <= sessionIterator.GetTradingDayEndLocal(Bars.Session Iterator.ActualTradingDayExchange).AddHours(-1))
    {
       TimeUp = true;
    }
    Thank you very much

    #2
    Hello MohammedAmine,

    The error is specifically because of this line:

    Bars.SessionIterator.ActualTradingDayExchange

    You would need to remove the Bars.S and make it just lowercase sessionIterator.

    Code:
    sessionIterator.ActualTradingDayExchange
    Alternatively you could just use the ToTime method to make a time window.


    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Hello Jesse,

      Thanks for your reply, effectively when i removed the Bars. and turned s into lower case it removed the error, but still not working because when I printed this :
      Code:
      Print("Today Trading Will end at : " + sessionIterator.GetTradingDayEndLocal(sessionIterator.ActualTradingDayExchange));
      it printed an Old date of year 1800, u can check the attached image

      so how to know the REAL DayTrading End Date and Time ?

      Thank you

      Comment


        #4
        Never mind, I solved it, here was the missing line :

        Code:
        protected override void OnBarUpdate()
        {
          // on new bars session, find the next trading session
          if (Bars.IsFirstBarOfSession)
          {
            // use the current bar time to calculate the next session
            sessionIterator.GetNextSession(Time[0], true); // This was the missing line :)
        
            Print("The current session end of day is " + sessionIterator.ActualTradingDayEndLocal);
          }
        }

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by LauraBauer1, Today, 09:41 AM
        0 responses
        6 views
        0 likes
        Last Post LauraBauer1  
        Started by proptradingshop, Yesterday, 11:30 AM
        9 responses
        29 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by NRITV, Today, 09:05 AM
        1 response
        11 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by xiinteractive, Today, 08:29 AM
        1 response
        7 views
        0 likes
        Last Post NinjaTrader_Clayton  
        Started by DT215, 08-08-2023, 11:03 AM
        3 responses
        445 views
        0 likes
        Last Post NinjaTrader_Clayton  
        Working...
        X