Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Time session management

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

    Time session management

    I have session management code. This code works if I don't use IOrder primitive to handle the orders. When I try to use IOrders first session do not finish (last open entry do not exit in the same day) and second session do not start. If somebody have this problem and resolved it please help.

    PHP Code:
    if ((ToTime(Time[0]) >= fisrtSessionStart && ToTime(Time[0]) < firstSessionEnd)  //first session hours
        && Time[0].DayOfWeek != DayOfWeek.Saturday && Time[0].DayOfWeek != DayOfWeek.Sunday) //weekend days
     {
     sessionIsRunning = true; 
     }
     if(SecondSesionEnable && 
       (ToTime(Time[0]) >= secondSessionStart && ToTime(Time[0]) < secondSessionEnd) //second session hours
         && Time[0].DayOfWeek != DayOfWeek.Saturday && Time[0].DayOfWeek != DayOfWeek.Sunday)
     {
     sessionIsRunning = true; 
     }
     
     
    if (sessionIsRunning == true){
    //check conditions exit one direction entry one in another direction 
     
    //for example
    if (EMA(Close, 8)[0] < EMA(Close, 8)[1])
               {
                    ExitLong();
                    orderShort = EnterShort();
                }
     
    }
     
    //Code for session end
    //littel modifiied, but still don't work (almost the same code is for second session)
     
      if ((ToTime(Time[0]) >= firstSessionEnd) )  { 
       CancelOrder(orderShort);
       CancelOrder(orderLong);
       CancelAllOrders(true,true);
       ExitShort();
       ExitLong();
       } 
    
    If somebody ask I use OnOrderUpdate(IOrder order) to handle the orders.

    Thanks in advance.
    Last edited by wlodi; 03-07-2012, 08:05 AM.

    #2
    Hello wlodi,
    Thanks for writing in and I am happy to assist you.

    Make sure the orderShort and orderLong objects are not null. Like:
    If (orderShort != null) CancelOrder(orderShort);

    Also since orderShort orderLong are market orders they will be filled (unless theres no buyer/seller or exchange issues). So to cancel market orders are somewhat redundant.

    Please let me know if I can assist you any further.
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      Hello

      Thanks for helping . This one line of code solves one problem. Last trade in session doesn’t move to other day , but… still I don't understand why my code doesn’t work exactly like before (with entries instead of IOrder). I mean second session doesn’t want to turn on, but before I don’t have any problem with that. Some ideas?

      Comment


        #4
        Hello wlodi,
        Unfortunately we cannot debug your strategy fully. Please use the Print function and see whether you are getting the expected results. Simplify your code and test the same in parts to debug more efficiently.
        For more please refer to this post http://www.ninjatrader.com/support/f...ead.php?t=3418

        Please let me know if I can assist you any further.
        JoydeepNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        671 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        379 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        111 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        575 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        582 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X