Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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
    Chris L.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by llanqui, Yesterday, 12:51 PM
    3 responses
    9 views
    0 likes
    Last Post llanqui
    by llanqui
     
    Started by FAQtrader, 04-25-2024, 12:00 PM
    4 responses
    52 views
    0 likes
    Last Post blkbird
    by blkbird
     
    Started by dcriador, Yesterday, 10:45 AM
    5 responses
    32 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Started by llanqui, Today, 09:59 AM
    0 responses
    1 view
    0 likes
    Last Post llanqui
    by llanqui
     
    Started by Haiasi, Today, 09:16 AM
    2 responses
    7 views
    0 likes
    Last Post Haiasi
    by Haiasi
     
    Working...
    X