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.?
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"); } } }
Comment