Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multiple entries and multiple exits

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

    Multiple entries and multiple exits

    Hi,

    My strategy has multiple entries and multiple exits, something similar with the following code:
    protected override void OnBarUpdate()
    {
    // Entry condition 1
    if (CrossAbove(SMA(10), SMA(20), 1))
    EnterLong("Condition 1 Entry");

    // Entry condition 2
    if (CrossAbove(RSI(14, 3), 30, 1))
    EnterLong("Condition 2 Entry");

    // Closes the position created by entry condition 1
    if (CrossBelow(SMA(10), SMA(20), 1)
    ExitLong("Condition 1 Entry");

    // Closes the position created by entry condition 2
    if (CrossBelow(RSI(14, 3), 70, 1))
    ExitLong("Condition 2 Entry");
    }

    Actually I have 5 different entries and 4 different exits. Like halfway through my backtesting I am getting the following error message:"Error on running backtest:Object reference not set to an instance of an object" and the backtest ends.
    Looking through Orders Tab I see one order with State "Working" and Action is "Buy to cover". My strategy is Long only! Checking the Trades tab I see that trades triggered by say "Condition 1 Entry" are exited by 2nd or 3rd exit condition or even 4th! Looks like it doesn't matter what "fromEntrySignal" parameter is if the exit condition is true(for that specific instrument) the software sells the entire position!.
    I thought that no matter what the exit condition is if I use "fromEntrySignal" parameter NT will close only the position(with the quantity) associated with that specific EntrySignal!

    Please clarify.

    Thank you,

    Dan

    #2
    Hi Dan, the observations you have are correct and expected - to scale out of a position, you would need to scale in first like shown here - http://www.ninjatrader.com/support/f...ead.php?t=3751

    For the order reference issue, I would tip on a missing for null check in one of your IOrders - http://www.ninjatrader.com/support/f...ead.php?t=4226

    Comment


      #3
      Hi Bertrand,

      I do scale in first! As I said in my previous msg the strategy is LONG only, no short trades! I'm using EnterLong("EntryCondition#") and ExitLong("ExitCondition#","EntryCondition#") only! But when I look at Trades tab I see that, for example, a trade entered with "EntryCondition4" has been closed by "ExitCondition#2" instead of "ExitCondition#4"!
      Any thoughts on this?

      Dan
      Last edited by drusann; 08-08-2013, 01:55 PM.

      Comment


        #4
        Dan, thanks for the clarification so you're referring to the account performance section trades tab then? Here the pairing would be done strictly on FIFO (first in first out), correct that's expected.

        Comment


          #5
          Bertrand,

          I'm referring to Strategy Analyzer->Trades Tab. So, now my questions is: why do you have this method ExitLong(string signalName, string fromEntrySignal) then? What's the purpose if not tying the exit signal to an entry signal? Or, why doesn't your help say that in fact is FIFO and this method doesn't apply? Please read your help http://www.ninjatrader.com/support/h...nt7/index.html especially Tips at bottom of the page where it says that "You can tie an exit to an entry by providing the entry signal name in the parameter "fromEntrySignal".
          Any thoughts?

          Dan

          Comment


            #6
            Dan, in the Trades tab of the Strategy Analyzer backtest I would not expect this behavior as you described, would you see the same with this example shared here?



            On the Account Performance level it would be strictly FIFO though.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            650 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            370 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            109 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            574 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            577 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X