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 argusthome, Yesterday, 10:06 AM
                0 responses
                14 views
                0 likes
                Last Post argusthome  
                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                0 responses
                11 views
                0 likes
                Last Post NabilKhattabi  
                Started by Deep42, 03-06-2026, 12:28 AM
                0 responses
                9 views
                0 likes
                Last Post Deep42
                by Deep42
                 
                Started by TheRealMorford, 03-05-2026, 06:15 PM
                0 responses
                4 views
                0 likes
                Last Post TheRealMorford  
                Started by Mindset, 02-28-2026, 06:16 AM
                0 responses
                31 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Working...
                X