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 Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    648 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    369 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    108 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    572 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    574 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X