Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

ExitLong opens Short position

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

    ExitLong opens Short position

    Hi all, i have a simple strategy which suppose to do only the Long positions. So basically i have a condition for EnterLong and i have separate condition which calls ExitLong .. i did a lot of testing on playback data, and everything works fine. But when i go for real, my ExitLong opens Short position... I understand, that in principle Enter position consist from closing previous one, but i didn't find any description, that the Exit are doing the same in oposit.... Any suggestion, how to avoid that behaviour and simple close long position without opening Short ? Thank you

    #2
    Hello dorasvk,

    Thanks for your post and welcome to the NinjaTrader forums!

    Note: When you post about your strategy, it will help us to provide a reply if we know if you are using the Strategy Builder or coding directly in Ninjascript.

    The ExitLong() method places a sell market order. It would not create a new sell position entry unless there were multiple sell orders submitted at once while there was a long position. Does your strategy have both an ExitLong and a SetStopLoss or multiple separate conditions that use ExitLong()?



    Comment


      #3
      hmm, thank you very much. Yes, basically when i open position EnterLong(n,""); i set the SetStopLoss after that. and i also have a condition which call ExitLong(); so you are right, that i use ExitLong and SetStopLoss ... is it a problem ? the exist condition includes also && Position.MarketPosition == MarketPosition.Long..

      Comment


        #4
        Hello dorasvk,

        Thanks for your reply.

        It would be a problem if the ExitLong() occurs at the same time SsetStopLoss() as they would send then 2 sell market orders at the same time so one closes the position and the other would leave you then in a 1 short position. Order processing is asynchronous to your strategy code execution and position updates do not occur until the position is changed which again is asynchronous to the strategy coding.

        You will need to rework your exit logic so that it prevents using ExitLong() when the SetStopLoss is about to fire. This would mean comparing current price to the price level that the setstop loss is set to and setting a condition false to prevent the ExitLong().

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Yesterday, 05:17 AM
        0 responses
        54 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        131 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        73 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        44 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        49 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X