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 NullPointStrategies, Today, 05:17 AM
    0 responses
    51 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    129 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    69 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    42 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    46 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X