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 Taddypole, 04-26-2024, 02:47 PM
      1 response
      12 views
      0 likes
      Last Post NinjaTrader_Eduardo  
      Started by futtrader, 04-21-2024, 01:50 AM
      6 responses
      58 views
      0 likes
      Last Post futtrader  
      Started by sgordet, Today, 11:48 AM
      0 responses
      4 views
      0 likes
      Last Post sgordet
      by sgordet
       
      Started by Trader146, Today, 11:41 AM
      0 responses
      5 views
      0 likes
      Last Post Trader146  
      Started by jpapa, 04-23-2024, 07:22 AM
      2 responses
      22 views
      0 likes
      Last Post rene69851  
      Working...
      X