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 Mindset, 04-21-2026, 06:46 AM
        0 responses
        91 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by M4ndoo, 04-20-2026, 05:21 PM
        0 responses
        137 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by M4ndoo, 04-19-2026, 05:54 PM
        0 responses
        68 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by cmoran13, 04-16-2026, 01:02 PM
        0 responses
        121 views
        0 likes
        Last Post cmoran13  
        Started by PaulMohn, 04-10-2026, 11:11 AM
        0 responses
        72 views
        0 likes
        Last Post PaulMohn  
        Working...
        X