Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Exits not functioning properly

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

    Exits not functioning properly

    I have written some code that uses a start time and end time to establish trading hours for the day. After my end time, I want to exit all positions. I am using the code below, but it is only functioning properly 50-75% of the time. Any ideas why?

    Code:
    private double starttime = 170000;
    private double stoptime = 160000;
    Code:
    bool tradingtime = (starttime<stoptime && t>=starttime && t<stoptime) || (starttime>stoptime && (t>=starttime || t<stoptime)) || starttime==stoptime;
    
    if (Positions[0].MarketPosition==MarketPosition.Long)
    {
    if (!tradingtime)
    	ExitLong("EODLX","LE");
    }
    My entry is named "LE", so the order is definitely linked properly.

    #2
    toptrader, on which instrument and timeframe are you working with this?

    How did you define 't'?

    Did you take a look already at this sample for time filter examples?

    Comment


      #3
      Sorry I forgot that part.

      Code:
      double t = ToTime(Time[0]);

      Comment


        #4
        ToTime() returns an int, so please try with -

        Code:
        int t = ToTime(Time[0]);

        Comment


          #5
          Bertrand,
          I tried that and still got the same issue. Does it make a difference that I am running the strategy on Range charts?

          Comment


            #6
            Yes, as the needed timestamp granularity may not be present on those - suggest you add 1 minute series to the strategy and work with Times then for the checks.

            Comment


              #7
              Even when running with CalculateOnBarClose=false?

              Comment


                #8
                Yes, this has no influence on the way you access the historical time stamp values - either there's one present or not, thus your conditions evaluate to true or not. I would suggest you break down your time filer rule in parts and add for example draw statements when it triggers so you have visual confirmation of what to expect from it.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                672 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                379 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                111 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                577 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                582 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X