Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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;
                    }
    Paul H.NinjaTrader Customer Service

    Comment


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

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by AaronKoRn, Yesterday, 09:49 PM
      0 responses
      11 views
      0 likes
      Last Post AaronKoRn  
      Started by carnitron, Yesterday, 08:42 PM
      0 responses
      10 views
      0 likes
      Last Post carnitron  
      Started by strategist007, Yesterday, 07:51 PM
      0 responses
      12 views
      0 likes
      Last Post strategist007  
      Started by StockTrader88, 03-06-2021, 08:58 AM
      44 responses
      3,982 views
      3 likes
      Last Post jhudas88  
      Started by rbeckmann05, Yesterday, 06:48 PM
      0 responses
      10 views
      0 likes
      Last Post rbeckmann05  
      Working...
      X