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 Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                647 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                368 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                108 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                571 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                573 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X