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 Mindset, 04-21-2026, 06:46 AM
    0 responses
    88 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    134 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
    119 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    69 views
    0 likes
    Last Post PaulMohn  
    Working...
    X