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

Problem with multiple close signals

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

    Problem with multiple close signals

    Hi,

    the code below, when I set "entries per direction" to more than 1 (say 5) during a backtest results in an error "Error on running backtest: Object reference not set to an instance of an object." and some of the positions close by a wrong exit: say, "IQ Entry" may be closed by a "PQ exit".

    ------------------ begin -----------------

    protected override void OnBarUpdate()
    {
    // Condition set 1
    if (CrossAbove(SMA(Fast), SMA(Slow), 1))
    {
    EnterLong(DefaultQuantity, "IQ");
    }

    // Condition set 2
    if (CrossBelow(SMA(Fast), SMA(Slow), 1))
    {
    ExitLong("IQ Exit", "IQ");
    }

    // Condition set 3
    if (DonchianChannel(Channel).Upper[0] > DonchianChannel(Channel).Upper[1])
    {
    EnterLong(DefaultQuantity, "PQ");
    }

    // Condition set 4
    if (Low[0] < Low[1])
    {
    ExitLong("PQ Exit", "PQ");
    }
    }

    ------------------ end -----------------

    What is the problem and how to solve it?

    Thank you.

    #2
    Hello dmitry75,

    Welcome to the NinjaTrader Support Forums!

    The "Error on running backtest: Object reference not set to an instance of an object." maybe referring to a different part of your code that that was not posted.

    Does your strategy still run after this or do you have to restart the Strategy?
    Last edited by NinjaTrader_JC; 08-07-2013, 07:23 AM.
    JCNinjaTrader Customer Service

    Comment


      #3
      Hello NinjaTrader_JC,

      you said:

      So you may want to change the ExitLong() methods to:
      Code:
      ---------
      ExitLong("IQ", "IQ Exit");
      ExitLong("PQ", "PQ Exit");

      --------
      Are you sure? If I do this, the stops don't work at all. "IQ" and "PQ" are entry signals, not "IQ Exit" and "PQ Exit".

      Comment


        #4
        Hello dmitry75,

        Sorry for the confusion on the Exit methods.

        What you have is fine, the reason that you may see the "PQ Exit" paired with an "IQ" entry order is due to how NinjaTrader pairs the trades. NinjaTrader will use a FIFO only, when pairing trade results using the Backtest. Using a Live account you should not experience this.

        With that said, we do have this trade pairing change in our future enhancements list that our development team is considering.

        Happy to be of further assistance.
        JCNinjaTrader Customer Service

        Comment


          #5
          True, I don't have this problem trading a live account. But I need to backtest a strategy that has two different positions that are entered/exited based on a different set of rules. Is there any way around? Also, when do you expect to make this "trade pairing change" you mentioned? Thank you!

          Comment


            #6
            Hello dmitry75,

            The easiest way around this for backtesting may be to create two different strategies, one with the "IQ" entry and the other with the "PQ" entry.

            As for the feature enhancement we do not have a time when/if this will be changed, but I would not expect this to change in NinjaTrader 7. If it is going to be changed it will most likely happen in NinjaTrader 8, which we do not have a release date for yet.
            JCNinjaTrader Customer Service

            Comment


              #7
              For some reasons, I need to do it within a single strategy. Are there any other ways around? I don't care if it would require a lot of programming. Still want to stick to a managed approach. Thanks again.

              Comment


                #8
                Hello dmitry75,

                There is not good way to get around this besides creating two different strategies but you may view the following post which a user has shared how they were tried to get around this.



                Happy to be of further assistance.
                JCNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by maybeimnotrader, Today, 05:46 PM
                0 responses
                6 views
                0 likes
                Last Post maybeimnotrader  
                Started by quantismo, Today, 05:13 PM
                0 responses
                6 views
                0 likes
                Last Post quantismo  
                Started by AttiM, 02-14-2024, 05:20 PM
                8 responses
                166 views
                0 likes
                Last Post jeronymite  
                Started by cre8able, Today, 04:22 PM
                0 responses
                8 views
                0 likes
                Last Post cre8able  
                Started by RichStudent, Today, 04:21 PM
                0 responses
                5 views
                0 likes
                Last Post RichStudent  
                Working...
                X