Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

ToTime not exiting trades

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

    ToTime not exiting trades

    Hi,

    I have a program which i only want to run during the following hours:
    start at Session1Start (150000)
    end at Session1End (170000)

    My program only takes trades during these times but it will not exit the trade if it is already in the trade at 170000. I believe this is because it is not looking at the program after 170000 when it tells it to exit if still in the trade! Please help! Thank you very much!

    here is the code

    if ((ToTime(Time[0]) <= Session1Start || ToTime(Time[0]) >= Session1End))
    {
    return;
    }

    if ((ToTime(Time[0]) >= Session1Start && ToTime(Time[0]) <= Session1End))
    {
    enter here w certain conditions
    }



    if (Position.MarketPosition == MarketPosition.Short
    && ToTime(Time[0]) <= Session1Start || ToTime(Time[0]) >= Session1End )
    {
    ExitShort("short");
    }
    if (Position.MarketPosition == MarketPosition.Long
    && ToTime(Time[0]) <= Session1Start || ToTime(Time[0]) >= Session1End )
    {
    ExitLong("long");
    }

    #2
    Hello malhome,

    Thank you for your post.

    Your code prevents exits during these times, is this what you intend?

    Can you detail the expected behavior you want?

    Comment


      #3
      I want my trades to take place only during the hours of 150000-170000 and then the strategy to be flat. Currently it only opens trades during these hours, but is a trade starts before 170000 it doesn't exit after. I'd like it to exit as soon as the bar closes after 170000.
      Thanks for your help!

      Comment


        #4
        Hello malhome,

        Thank you for your response.

        You will want to remove the following line of code:
        Code:
        if ((ToTime(Time[0]) <= Session1Start || ToTime(Time[0]) >= Session1End))
        {
        return;
        }

        Comment


          #5
          Thank you works gr8!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          605 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          351 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          105 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          560 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          561 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X