Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Error when running strategies live

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

    Error when running strategies live

    I have the following in my code:

    if (ToTime(Time[0]) >= 160000 || ToTime(Time[0]) < 90000) {

    if (Position.MarketPosition == MarketPosition.Long) {ExitLong(); return;}

    if (Position.MarketPosition == MarketPosition.Short) {ExitShort(); return;}

    //ExitShort();ExitLong();

    return;}


    ​It works correctly in that it never takes trades before 90000, however, it doesn't always exit at 160000. I'd say about 90% of the time, it executes correctly and exits any position at 160000, but the rest of the time, it leaves the position open and never closes or changes it in any way (it doesn't take trades based on the rest of the strategy logic following the above snippet). Using prints, it clearly registers the if statements as true and then registers the return. It appears the strategy does not recognize it's own position and theirfore will not ExitLong() or ExitShort(). How can I fix this?

    #2
    Hello samish18,

    Is there a bar closing with the exact time of 16:00:00?

    Is the condition evaluating as true?

    Add debugging prints and provide the output.

    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Yes, there is a bar closing 160000, but even if there was not, the position does not close at all (not at 170000, at 180000, etc.). I already worked with prints and the conditions evaluate correctly.

      Comment


        #4
        Hello samish18,

        Temporarily comment out all prints.

        At the top of OnBarUpdate() call Print(Time[0]);.

        This will print the close time of all bars.

        Save the output to a text file and attach this to your next post.
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Mindset, 04-21-2026, 06:46 AM
        0 responses
        87 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by M4ndoo, 04-20-2026, 05:21 PM
        0 responses
        128 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by M4ndoo, 04-19-2026, 05:54 PM
        0 responses
        65 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by cmoran13, 04-16-2026, 01:02 PM
        0 responses
        117 views
        0 likes
        Last Post cmoran13  
        Started by PaulMohn, 04-10-2026, 11:11 AM
        0 responses
        67 views
        0 likes
        Last Post PaulMohn  
        Working...
        X