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