Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Exit Positions not working

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

    Exit Positions not working

    I'm trying to figure out why my strategy isnt exiting my open positions when the time conditions are met. The close condition works, just not the time. I'm using a large renko bar for the strategy so rather than use ToTime(Time[0]) which sometimes would close me out an hour or more late due to the time stamp i figured Date.Time.Now.Ticks would work. My coding knowledge is very very limited so i have no clue if this is even right. I know i cannot backtest it, but running it live didnt work either.

    Code:
    // Condition to exit long
    if (Close[0] < Close[1] || DateTime.Now.Ticks == 120000 || DateTime.Now.Ticks == 160000)
    			{
    				ExitLong();
    			}

    #2
    Instead of

    DateTime.Now.Ticks == 120000

    try something like

    ToTime(Time[0]) == 120000

    Comment


      #3
      Would that work for even a large renko bar where the bar formation may take an hour or more to complete?

      Comment


        #4
        No, in that case you could try ToTime(DateTime.Now) == 120000

        Comment


          #5
          I restarted the strategy with ToTime(DateTime.Now) == 130000 to see if it would close out positions at 1pm and it still didnt work.

          The renko bar is midbar so it doesnt close my order even the time is 1pm.

          Comment


            #6
            To be able to exit intrabar, the CalculateOnBarClose setting needs to 'false' for the script.

            Comment


              #7
              I set CalculateOnBarClose = false and my strategy went haywire and was entering and exiting trades every couple seconds. Not sure where to go from here.

              There is no way to flatten all positions based on the system clock?

              Comment


                #8
                You would then need to look into separating your entry vs exit logic to work on the close of a bar and intrabar as desired - http://www.ninjatrader.com/support/f...ad.php?t=19387

                A alternative would be adding another series, for example a 1 minute to the strategy to be able to access those timestamps via Times - http://www.ninjatrader.com/support/h.../nt7/times.htm

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by charlesugo_1, 05-26-2026, 05:03 PM
                0 responses
                65 views
                0 likes
                Last Post charlesugo_1  
                Started by DannyP96, 05-18-2026, 02:38 PM
                1 response
                149 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Started by CarlTrading, 05-11-2026, 05:56 AM
                0 responses
                162 views
                0 likes
                Last Post CarlTrading  
                Started by CarlTrading, 05-10-2026, 08:12 PM
                0 responses
                99 views
                0 likes
                Last Post CarlTrading  
                Started by Hwop38, 05-04-2026, 07:02 PM
                0 responses
                286 views
                0 likes
                Last Post Hwop38
                by Hwop38
                 
                Working...
                X