Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

BarsSinceExit on Multi-Instrument Charts

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

    BarsSinceExit on Multi-Instrument Charts

    I am trying to improve backtesting results (as in make them actually compare in some useful way to what happens in real-time), so I am using a chart with signals taken from a larger interval and executed on a smaller interval. In order to be able to test a variety of time frames I use the primary instrument as the signal source but execute the trades on the secondary instrument at a much finer resolution. I also am trying to avoid getting cut up in chop and so I'm using the "BarsSinceExit" method, but it doesn't appear to be working, Here's my code:

    Code:
    			if (BarsInProgress == 1)
    				return;
    			if (BarsInProgress == 0)
    			{
    			if (Position.MarketPosition == MarketPosition.Flat)
    			{
    			SetTrailStop("", CalculationMode.Ticks, StopLoss, false);
    			StopMove = StopLoss - 1;
    			} 
    				// When the median of price crosses above avg high band or across the fast follower line if it is above the avg high band go long.
    				if ((CrossAbove(Median, EMABand(11, 11, 21).AvgHigh, 1 )  || (CrossAbove(Median, EMABand(11, 11, 21).Follow, 1 ) && EMABand(11, 11, 21).Follow[0] > EMABand(11, 11, 21).AvgHigh[0] ))
    					&& Position.MarketPosition == MarketPosition.Flat
    					&& (BarsSinceExit(1,"",0) > 5 || BarsSinceExit(1,"",0) == -1)
    					&& ((ToTime(Time[0]) > TT1_Start && ToTime(Time[0]) < TT1_End ) || (ToTime(Time[0]) > TT2_Start && ToTime(Time[0]) < TT2_End )))
    
    				{
    					/* The entry condition is triggered on the primary bar series, but the order is sent and filled on the
    					secondary bar series. The way the bar series is determined is by the first parameter: 0 = primary bars,
    					1 = secondary bars, 2 = tertiary bars, etc. */
    					EnterLong(DefaultQuantity, 1, "HIB_L");
    				}
    			
    				// When the median of price crosses below the avg low band or across the fast follower line if it is below the avg low band go short.
    				else if ((CrossBelow(Median, EMABand(11, 11, 21).AvgLow, 1 ) || (CrossBelow(Median, EMABand(11, 11, 21).Follow, 1 ) && EMABand(11, 11, 21).Follow[0] < EMABand(11, 11, 21).AvgLow[0] ))
    					&& Position.MarketPosition == MarketPosition.Flat
    					&& (BarsSinceExit(1,"",0) > 5 || BarsSinceExit(1,"",0) == -1)
    					&& ((ToTime(Time[0]) > TT1_Start && ToTime(Time[0]) < TT1_End ) || (ToTime(Time[0]) > TT2_Start && ToTime(Time[0]) < TT2_End )))
    
    				{
    					/* The entry condition is triggered on the secondary bar series, but the order is sent and filled on the
    					primary bar series. The way the bar series is determined is by the first parameter: 0 = primary bars,
    					1 = secondary bars, 2 = tertiary bars, etc. */
    					EnterShort(DefaultQuantity, 1, "HIB_S");
    				}
    My question is, is the BarsSinceEntry method properly configured because when I test it there is no apparent affect on my outcome. I essentially get the same results whether it is there or not, so I suspect I have buggered it up somehow but it does compile and run without error so it must be s subtle problem.
    Can you let me know if the syntax is correct?
    Thanks
    DaveN

    #2
    Hello,

    Is it the BarsSinceEntry or BarsSinceExit that is not working? I did not see reference to BarsSinceEntry in your code.

    I look forward to assisting you further.
    MatthewNinjaTrader Product Management

    Comment


      #3
      My bad, I used both terms in my message but it is actually BarsSinceExit that I am trying to use, the logic being once price has had a big move, it often chops for awhile and I am trying to suppress trades for some number of bars after a trade closes to prevent entry in the midst of the chop.
      Sorry I inserted the confusion.
      Here is the line of code that doesn't appear to be working:

      Code:
      	&& (BarsSinceExit(1,"",0) > 5 || BarsSinceExit(1,"",0) == -1)
      DaveN
      Last edited by daven; 05-01-2013, 09:49 AM. Reason: Add some code I forgot to include.

      Comment


        #4
        So that I may more accurately test on my end could you please attach the .cs file that replicates the issue. If possible please simplify the script as much as possible so that I may isolate the cause.

        Located in (MY)Documents\NinjaTrader 7\bin\Custom\Strategy

        I look forward to assisting you further.
        LanceNinjaTrader Customer Service

        Comment


          #5
          BarsSinceExit Problem

          Here it is.
          Thanks
          DaveN
          Attached Files

          Comment


            #6
            BarsSinceExit continued

            Not sure if it will work for you since it uses a custom indicator. Here is that indicator.
            Attached Files

            Comment


              #7
              Thanks for those files.

              I'm noticing you're checking your exit based off of BIP == 1
              Your entries are all based on BIP == 0

              Be aware that when using Set() like you are, these will always need to be checked in BIP == 0

              From HG: Should you have multiple Bars objects of the same instrument and are using Set() methods in your strategy, you should only submit orders for this instrument to the first Bars context of that instrument. This is to ensure your order logic is processed correctly and any necessary order amendments are done properly.


              Let me know if I can be of further assistance.
              LanceNinjaTrader Customer Service

              Comment


                #8
                The problem with the last statement you made is that when backtesting or optimizing a multi-time frame instrument strategy one can only vary key parameters like range bar size, etc. on the primary instrument, but that limitation defeats the entire purpose of gaining more accurate backtesting information by executing trades on a smaller time frame than the time frame used to decide on trade entries and exits. That makes the whole topic of using more granular data to improve a strategy pretty much moot.
                Perhaps I didn't understand what you said, or if I did, how does one actually improve back-testing predictability if you can't actually execute trades on a smaller time frame while also varying key aspects of the trade strategy on a larger primary data bar set?
                I hope I am confused about this.
                One last question. If I completely eliminated the trailstop would this stategy test as I intended using the primary data to vary inputs to test, and the secondary data to increase predictability by increasing trade granularity?
                DaveN

                Comment


                  #9
                  The example you provide is placing the entry on the primary time frame. If you want to take advantage of the secondary series you would need to submit the entry order on the 2nd series

                  If you wanted to still use the SetTrailStop() What you could consider doing is set the primary time frame to your 10 second chart.

                  Then perform calculations on the secondary time frame but execute your trades to the primary by sending them to BIP 0

                  If this is not an options you would not want to sue the Set() methods and instead would need to use your own order handling
                  The OnOrderUpdate() and OnExecution() methods are reserved for experienced programmers. Instead of using Set() methods to submit stop-loss and profit target orders, you can submit and update them manually through the use of IOrder and IExecution objects in the OnOrderUpdate() and OnExecution() methods. The OnOrderUpdate()


                  Originally posted by daven View Post
                  One last question. If I completely eliminated the trailstop would this stategy test as I intended using the primary data to vary inputs to test, and the secondary data to increase predictability by increasing trade granularity?
                  DaveN
                  Consider adding Print statements along the way to ensure each aspect of your if statements are returning values you expect. It's not yet clear to me if the BarsSinceExit() is the condition check that isn't working as you would expect.

                  For example:
                  //this would allow you to know the bar's time stamp and the bars since the last exit
                  Print(Time[0] + " " + BarsSinceExit(1,"",0));

                  Let me know if I can better clarify any aspects of this
                  LanceNinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by pibrew, Today, 06:37 AM
                  0 responses
                  1 view
                  0 likes
                  Last Post pibrew
                  by pibrew
                   
                  Started by rbeckmann05, Yesterday, 06:48 PM
                  1 response
                  12 views
                  0 likes
                  Last Post bltdavid  
                  Started by llanqui, Today, 03:53 AM
                  0 responses
                  6 views
                  0 likes
                  Last Post llanqui
                  by llanqui
                   
                  Started by burtoninlondon, Today, 12:38 AM
                  0 responses
                  11 views
                  0 likes
                  Last Post burtoninlondon  
                  Started by AaronKoRn, Yesterday, 09:49 PM
                  0 responses
                  15 views
                  0 likes
                  Last Post AaronKoRn  
                  Working...
                  X