Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Scale out problem

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

    Scale out problem

    I am developing a system to trade 2 contracts with different stops and targets.

    I am using 2 different entry/stop/target signals, like "longlimit1" and "longlimit2"

    I am able to get both orders submitted, and both stops and targets working properly. My problem is, is when one target gets hit, it cancels the remaining stop and target.

    So, say the target for "longlimit1" gets hit, it should just cancel the stop for "longlimit1", instead it is canceling both the target and stop for "longlimit2" and leaving me with one open contract and no stops/targets.

    The two stops/targets have different oco id's in the order list.

    It seems to work fine in backtesting, I can see both entries and both exits where they should be, but running it in live or in replay is when the orders get canceled when they shouldn't.

    In the initialize section I have these set: Any ideas?

    EntriesPerDirection = 1;
    EntryHandling = EntryHandling.UniqueEntries;
    Last edited by woodside; 11-30-2007, 05:59 PM.

    #2
    Here is the code I'm using for entries. Does this look correct?
    (entryL is calculated above this code snippet).

    Code:
    SetProfitTarget("Long1", CalculationMode.Ticks, 160);
    SetProfitTarget("Long2", CalculationMode.Ticks, 80);    
    SetStopLoss("Long1", CalculationMode.Ticks, 55, false);
    SetStopLoss("Long2", CalculationMode.Ticks, 50, false);                    
    EnterLongLimit(entryL , "Long1"); 
    EnterLongLimit((entryL-2) , "Long2");

    Comment


      #3
      Correction:

      The workaround I suggested in the original edit of this post (below) should be unnecessary. I just re-tested this feature under 6.0.1000.6, and as Josh mentions in the prior post, it does work.

      I suspect that this was either a problem in an earlier NT version, or more likely, that the problem I was trying to work around was related to the caching of parameter values by the Strategy Analyzer causing a change in these default values set by the code to be ignored until NinjaTrader was restarted.

      Old Post:


      EntryHandling defaults to AllEntries and unfortunately, setting EntriesPerDirection and EntryHandling in the Initialize method has no effect on the strategy.

      I found the following was useful to prevent a strategy from being run with the wrong settings when placed in the OnBarUpdate method:

      Code:
      if ((EntryHandling != EntryHandling.UniqueEntries)  // Correct setting?
        || (EntriesPerDirection != 1))
      {                                                  // No.  This is an error.
        Print( "**** Error - Entry handling is not set to UniqueEntries 1" );
        throw new System.ApplicationException("EntryHandling must be UniqueEntries, 1"); // Abort this run.
      }
      Last edited by KBJ; 12-01-2007, 08:13 PM.

      Comment


        #4
        Setting EntriesPerDirection and EntryHandling in the Initialize method does work. It adjusts the setting for you away from the default settings automatically when you are loading up a strategy.

        Woodside can you confirm with us what version of NinjaTrader you are on? I am also guessing you've seen this reference sample correct? http://www.ninjatrader-support.com/v...ead.php?t=3751 Not exactly the same as what you are doing but similar.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          I'm running 6.0.1.0006 multi broker.

          I was able to get your example working, but when I try to incorporate that into my script it doesn't work right.

          I guess I'll have to work with your sample and try to put my code in there and see what is different.

          Comment


            #6
            My strategy uses multiple time frames. I think that is the issue.

            Can someone look at the simple attached script? This will reproduce the issue I'm having. If you remove the

            Add(PeriodType.Minute, 15);

            and the:

            if (BarsInProgress == 0)

            The script will work fine, put those in and the extra orders get canceled. I'm running this strategy on a one minute ym12-07 if that matters.

            -Erik
            Attached Files
            Last edited by woodside; 12-01-2007, 01:43 PM.

            Comment


              #7
              woodside,

              This is a bug in NT6. Your code works as expected in NT6.5 though. Thanks for reporting.
              Josh P.NinjaTrader Customer Service

              Comment


                #8
                Thanks for verifying that, I was driving myself crazy. I downloaded 6.5 and am having a few issues with my 2 contract strategy due to some changes.

                I am getting an error on this line:

                && (BarsSinceExit() > 60 || BarsSinceExit() == -1 ))

                this is the error:

                Strategy,Error on calling 'OnBarUpdate' method for strategy 'RegressionTwoContract': You must use the overload that has a 'BarsInProgress' parameter when calling the BarsSinceExit() method in the context of a multi-time frame and instrument strategy.,

                Can you help me with the changes I need to make? I've tried a few things without out success. It compiles fine but gives that error when running it.

                Thanks.

                -Erik

                Comment


                  #9
                  In multi-time framed strategies the proper syntaxing for that method is as follows:
                  BarsSinceExit(int barsInProgressIndex, string signalName, int exitsAgo)
                  Josh P.NinjaTrader Customer Service

                  Comment


                    #10
                    Thanks for the help Josh, I have my strategy running correct under 6.5 now.

                    -Erik

                    Comment


                      #11
                      Originally posted by Josh View Post
                      Setting EntriesPerDirection and EntryHandling in the Initialize method does work. It adjusts the setting for you away from the default settings automatically when you are loading up a strategy.
                      Josh: I just retested this and you are correct - it does work. I suspect that my problem in this area was related to the Strategy Analyzer caching old values of the parameters, which were then not overridden by a change in the default settings in the source code; these settings only take effect when NinjaTrader is restarted or when the strategy name is changed.

                      Comment

                      Latest Posts

                      Collapse

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