Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Exit from position not intended

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

    Exit from position not intended

    I have a simple strategy that takes a short position on SMA(3) cross below HMA(20) when Stochastics(20,90,3) is above 80. Here is my code:
    protectedoverridevoid OnBarUpdate()
    {
    // Enter position
    if (CrossBelow(SMA(Fast), HMA(Slow), 1) && CrossAbove(Stochastics(20,90,3), 80, 1))
    EnterShort();
    }
    When I place this strategy on a 30 min SPY chart I get exited from the position even though I did not code any exit. See image. What do I need to do to prevent being exited from this position and why did it occur? Thanks.
    Attached Files

    #2
    Hi winja, please set ExitOnClose to false in your Initialize() - http://www.ninjatrader-support.com/H...itOnClose.html

    This is used to exit all open strategy positions by the session end, to define how much in advance ExitOnCloseSeconds can be used - http://www.ninjatrader-support.com/H...seSeconds.html

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by cmoran13, Yesterday, 01:02 PM
    0 responses
    29 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    21 views
    0 likes
    Last Post PaulMohn  
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    160 views
    1 like
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    95 views
    1 like
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    148 views
    2 likes
    Last Post CaptainJack  
    Working...
    X