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 NullPointStrategies, Today, 05:17 AM
        0 responses
        44 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        124 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        65 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        42 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        46 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X