Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Alternative to ExitLong() while still using managed orders?

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

    Alternative to ExitLong() while still using managed orders?

    Hello everyone, this is my first time on this forum so I will do my best to be concise. I am having a problem creating a strategy that uses a manual trailing stop condition. The reason for a manual trailing stop is that I read on another forum post that it is not possible to utilize a managed trailing stop while also using a stoploss...

    The code utilizes ExitLong() to terminate the position, the problem is that ExitLong() seems to stop all following orders on the day while utilizing backtesting.

    My Question: How do I exit a historical position without cancelling future orders for the day? Do I need to switch to unmanaged orders?

    code snippet below:

    Code:
    if (LongPositionOpen == true)
    {
         LongPriceList.Add(High[0]);
         if (MaxLong != 0)                  // This code will make a list of all the bar's high's since a position opens, and stores the highest high in a variable called MaxLong.
         {                                            // This list gets cleared every time LongPositionOpen == false so as to reset.
              if (LongPriceList.Max() > MaxLong)
              {
                   MaxLong = LongPriceList.Max();
              }
         }
    else
    {
         MaxLong = LongPriceList.Max();
    }
    if (MaxLong !=0 )
    {
         if (Low[0] < MaxLong - (MaxLong * 0.002)) // If the most recent low is more than X percent below the value of MaxLong, exit the position.
         {
              ExitLongLimit((MaxLong - (MaxLong * 0.002)));
         }
    }

    #2
    Hi, thanks for posting and welcome to the NinjaTrader forums. If you are mixing manual trading and automated trading you should ignore the historical backtest completely by adding this to the top of OnBarUpdate:

    if(State == State.Historical)
    return;

    Alternatively, you can set your start behavior to AdoptAccountPosition to adopt whatever position your real account is in before starting the strategy in real time.

    Kind regards,
    -ChrisL

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    45 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    21 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    31 views
    1 like
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    50 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    42 views
    0 likes
    Last Post CarlTrading  
    Working...
    X