Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Can't exit at 5am using ToTime

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

    Can't exit at 5am using ToTime

    Trying to exit positions at 5am after entering after 1am. Entries are working fine but the exits occur just one bar later instead of staying in the position until 5am. What am I doing wrong?

    Exit code is as follows:

    Code:
                    switch(Position.MarketPosition)
                    {
                        case MarketPosition.Short:
                            if (ToTime(Time[0]) >= 50000)
                                
                                Print("Time is " + Time.ToString());
                                Print("Exiting SHORT Position");
                                ExitShort(shares,"ES", "E1");    // ES is name of exit and E1 is the entry name                                      
                                // ExitShort(int quantity, string signalName, string fromEntrySignal)
                                break;
                            
                        case MarketPosition.Long:
                            if (ToTime(Time[0]) >= 50000)
                                
                                Print("Time is " + Time.ToString());
                                Print("Exiting LONG Position");
                                ExitLong(shares,"ES", "E1");    // ES is name of exit and E1 is the entry name
                                                                  // ExitShort(int quantity, string signalName, string fromEntrySignal)
                            
                                break;
                    }
    Also, curiously, the only print statement in the exit code that prints to output is the phrase 'Exiting short/long position'. The "Time is xxxx" statement does not print. I don't know why.
    Attached Files
    Last edited by ShruggedAtlas; 07-27-2015, 09:24 AM.

    #2
    Hello ShruggedAtlas,

    Thanks for your post.

    From the code you posted it appears you are missing "{}" after the if statement to contain all the statements. As written, the if statement only affects the next statement which is a print statement, all others would be immediately executed.

    Code:
                  switch(Position.MarketPosition)
                    {
                        case MarketPosition.Short:
                            if (ToTime(Time[0]) >= 50000)
                               [COLOR="Red"] {[/COLOR]
                                Print("Time is " + Time.ToString());
                                Print("Exiting SHORT Position");
                                ExitShort(shares,"ES", "E1");    // ES is name of exit and E1 is the entry name              
    [COLOR="red"]                           } [/COLOR]                       
                                // ExitShort(int quantity, string signalName, string fromEntrySignal)
                                break;
                            
                        case MarketPosition.Long:
                            if (ToTime(Time[0]) >= 50000)
                               [COLOR="red"] {[/COLOR]
                                Print("Time is " + Time.ToString());
                                Print("Exiting LONG Position");
                                ExitLong(shares,"ES", "E1");    // ES is name of exit and E1 is the entry name
    [COLOR="red"]                            }   [/COLOR]                                                          // ExitShort(int quantity, string signalName, string fromEntrySignal)
                            
                                break;
                    }

    Comment


      #3
      grrrr...I should have known. Thank you that was the solution precisely.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by sjsj2732, Yesterday, 04:31 AM
      0 responses
      30 views
      0 likes
      Last Post sjsj2732  
      Started by NullPointStrategies, 03-13-2026, 05:17 AM
      0 responses
      286 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      282 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      132 views
      1 like
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      90 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Working...
      X