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

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(Close8)[0] < EMA(Close8)[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 reynoldsn, 05-10-2024, 07:04 PM
        3 responses
        25 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Started by llanqui, Today, 11:10 AM
        1 response
        15 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Started by llanqui, Today, 10:29 AM
        1 response
        12 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Started by Trader146, 05-10-2024, 09:17 PM
        1 response
        22 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Started by bourasrafik, Today, 03:26 PM
        0 responses
        5 views
        0 likes
        Last Post bourasrafik  
        Working...
        X