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 CarlTrading, 03-31-2026, 09:41 PM
          1 response
          72 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by CarlTrading, 04-01-2026, 02:41 AM
          0 responses
          39 views
          0 likes
          Last Post CarlTrading  
          Started by CaptainJack, 03-31-2026, 11:44 PM
          0 responses
          63 views
          2 likes
          Last Post CaptainJack  
          Started by CarlTrading, 03-30-2026, 11:51 AM
          0 responses
          63 views
          0 likes
          Last Post CarlTrading  
          Started by CarlTrading, 03-30-2026, 11:48 AM
          0 responses
          53 views
          0 likes
          Last Post CarlTrading  
          Working...
          X