• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Default Settings for Total Control of Flat and Exiting Session End?

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

    Default Settings for Total Control of Flat and Exiting Session End?

    Would the following code for a simple trailing stop strategy conflict with the Flat settings. Before I added the revised the code below, I only entered if the buyStop and shortStop were triggered without the time booleans that appear.

    As soon as I revised the code in the format below, the strategy analyzer stops at iteration 26 and kind of hangs there. Somehow I think that trying to fully control my own time exits is conflicting with something in the default. Please lookover the code, as I only want to trade after 0830 and before 1455, and exit any open trade after 1455. The rest is simply use of booleans to know when a last position is active, and whether it is long or short.

    It is very straightforward, but I think a default setting related to Flat, or exiting at session end is conflicting. Wouldn't the code below essentially need to tell NT8 that it will be in total control of all Flat information, and doing anything related to close of session, etc.?

    Code:
                    after0835= ToTime(Time[0]) >= 083500;
                    before1455 = ToTime(Time[0]) < 145500;
                    after1455 = ToTime(Time[0]) > 145500;
                               
                    buyStop=  CrossAbove( emahigh, trailhigh,1) && after0835 && before1455 ;
                    shortStop= CrossBelow( emalow, traillow,1) && after0835 && before1455 ;
                
                    if ( Position.MarketPosition != MarketPosition.Flat)
                    {
                        IsLastPositionActive=true;
                        if ( Position.MarketPosition == MarketPosition.Long)
                            IsPositionLong=true;
                        if ( Position.MarketPosition == MarketPosition.Short)
                            IsPositionShort=true;
                    }
                    if ( Position.MarketPosition == MarketPosition.Flat)
                        IsLastPositionActive=false;
                         
                            
                    if( IsLastPositionActive )
                     {
                        //Exit any open position 5 minutes before closing bell
                         if ( after1455 && IsPositionLong )
                            EnterShort(800,"Time");
                        if ( after1455 && IsPositionShort )
                             EnterLong(800,"Time");
    
                         //Exit any open position if necessary
                        if( IsPositionLong ) 
                        {
                            if ( shortStop ) 
                              EnterShort(800,"Limit"); 
                        }
                        else         
                        {                    
                            if ( buyStop ) 
                              EnterLong(800,"Limit"); 
                        }
                    }
                    else
                    {
                        //Open new position if nothing is open
                        if ( shortStop ) 
                         {
                            EnterShort(800,"Short");
                            IsLastPositionActive=true;
                        }
                        if ( buyStop && IsLastPositionActive == false ) 
                        {
                            EnterLong(800,"Long");
                        } 
                    }                     
                }
    Last edited by pel11; 06-22-2018, 01:46 PM.

    #2
    Hello pel11,

    Thanks for your post.

    Having exits at a certain time would not affect the behavior of the ExitOnSessionClose setting. If the strategy closes positions before the session close and this option is enabled, those positions would have already been closed. If the strategy has open positions at the time of session close (including the ExitOnSessionCloseSeconds property) and ExitOnSessionClose is enabled, the positions will be exited.

    My recommendation would be to either use the ExitOnSessionClose property, or if you want to manage your own separate exit times, to disable ExitOnSessionClose and use time checks to control your exits.

    Time checks - https://ninjatrader.com/support/help...to_limit_t.htm

    With your code, I see that you are entering new positions but there are not any exit methods.

    To provide some further direction for using the Managed Approach for Entering and Exiting, I will provide a documentation link below. This document explains the different Entry and Exit methods and the internal rules that govern them.

    Managed Approach - https://ninjatrader.com/support/help...d_approach.htm

    I also recommend using debug prints and the TraceOrders property to monitor the strategies actions in the NinjaScript Output window. The Playback Connection is also useful for repeating scenarios for testing.

    Debugging - https://ninjatrader.com/support/help...script_cod.htm

    TraceOrders - https://ninjatrader.com/support/help...aceorders2.htm

    Playback Connection - https://ninjatrader.com/support/help...connection.htm

    Please let us know if we can be of further assistance.
    JimNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by aligator, Today, 01:49 PM
    1 response
    3 views
    0 likes
    Last Post NinjaTrader_ChrisL  
    Started by KINGKODA, Today, 12:08 PM
    1 response
    11 views
    0 likes
    Last Post NinjaTrader_Jim  
    Started by zulok, Today, 12:54 PM
    3 responses
    6 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Started by RadarTradar, 01-04-2020, 10:02 AM
    12 responses
    129 views
    0 likes
    Last Post Eric M.
    by Eric M.
     
    Started by [email protected], Today, 10:54 AM
    3 responses
    20 views
    0 likes
    Last Post NinjaTrader_ShawnB  
    Working...
    X