• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

delay with multi instrument strategy

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

    delay with multi instrument strategy

    Hi ninjatraders.I wrote a simple multi instrument strategy shown below, using the example in the ninjatrader 7 guide. It uses 4 tick range bars for both the first and second instrument. It's set to COBC equals true. I can attach for import the actual strategy if needed.

    Code:
    if(Closes[1][1] >= Closes[0][0])
    {
    EnterLong(0,1,"Long");	
    }
    I noticed that in another simple strategy that isn't multi instrument such as
    Code:
    if(Close[1]<= Close[0] && Close[2] >= Close[1])
    {
    EnterLong();	
    }
    the live fills take place as soon as Close[0] closes at the open of the next bar, or at the close of Close[0]. This is how I'd expect the multinstrument strategy to work at the close of Closes[0][0]. The problem is nearly every fill is two ticks further from the open of the next bar or the close of Closes[0][0].

    I made an indicator that draws an arrow each time the multinstrument condition is met, and what I also noticed is that sometimes the arrow is drawn well after the close of Closes[0][0], and during the next bar. I'd like to know if this is typical of multi instrument scripts, to cause a delay, and if not what could be causing this?

    #2
    Hello sampras010,

    Thank you for the post.

    I wouldn't necessarily be able to say what is happening from the description I would likely need to see the strategy and how the logic is created.

    Are you currently using BarsInProgress at all to control these conditions? That would be one item which may create differences if you are filtering the condition based on BarsInProgress.

    If you have a simple example script you could upload for me to view that would be helpful.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Hello,

      Thank you for providing the file.

      I reviewed the strategy but I am not sure what to compare this against as you have not included and debugging or other items to indicate what the problem is in the script. You had noted you created an indicator that also shows a problem, I would likely suggest combining this test into the strategy to display the problem visually. Otherwise, could you provide an image of the result you are seeing as well as your expectation to compare what you see versus what you may be expecting?

      One Item I had noted is that you are always submitting the order to the Primary series, was this intended?

      Regarding the series being used, because these are range bars I would expect that they do not close at the same time or frequency and make close at arbitrary times based on price movement. Is this what you are seeing and expecting that the bar closes at a more synchronized time? If so, it would be expected in this case as the Range bars are strictly price movement based, time-based bars would be more in sync and would be expected to call OBU at regular intervals if that was the expectation.


      I look forward to being of further assistance.
      JesseNinjaTrader Customer Service

      Comment


        #4
        I think I know what I need now. What I'm trying to do is wait for each close in the second series, and compare the closing prices between those closes and the primary bar closes that come directly after them. So if there are 50 secondary bars in a day, there can only be 50 trades or less. The problem is I need the market orders to go into the primary series only, and on those closes. What I need help with most is somehow checking that a bar has closed in the second series, but under the primary series condition. I've been attempting with a bool that I cant get to work. Is this even possible?


        Code:
        private bool barjustclosed = false;
        
        if (BarsInProgress == 1 ) {
        
                if(I NEED SOMETHING HERE THAT MEANS BAR HAS CLOSED?){
                
                barjustclosed = true;
                }
        
        }
        
        if (BarsInProgress == 0) {
        
                if(barjustclosed && MYCOMPARISONCONDITION?){
                    EnterLong(0, 1, "Long");
                }
        Last edited by sampras010; 01-16-2018, 07:50 PM.

        Comment


          #5
          I'm still struggling with this. I also tried to get this to work by using the instructions for granular fills. When I try it like this the way it is in the example
          Code:
               if(BarsInProgress==0)
             {
                              if (Closes[0][1]>= Closes[1][0] )
          	           { 
          			     EnterShort(1,1,"short");
          		   }
              }
          it waits for the primary bar to close, but then instead of waiting until the secondary bar closes before placing the trade in the secondary instrument (which is what I want), it enters into the secondary instrument immediately after the close of the primary bar. Is there a way maybe with the bool I've been trying to get it to wait for onbarupdate in one instrument, then wait for onbarupdate in the other instrument to take the trade?

          Comment


            #6
            Hello,

            Thank you for the reply.

            In your prior example with the bool, that is close to what you would need if you wanted to signal a bar was closed after a certain point but I don't see that you are resetting your bool. You could reset the bool to false on each primary bar close after checking if the bool is true to enter. Each secondary BIP could set it to true to signal they have closed since the last time the primary had checked this.

            To answer your most recent question, you would likely need a bool like you have created to do what you are asking. In your most recent example, when that condition is true in BIP 1, and you are submitting the order to BIP 1, it would be submitted when that bar is closed. To wait you would need to use a bool and signal that the time is ready to enter for the next primary bars close.

            I would likely suggest using prints here to see how your logic is being executed so you can fine tune what needs to happen or see what is missing. In the case of the bool example, I would suggest printing the value of the bool on each bar to see if its value is changing over time. If the value is always false, you need to look at the condition that sets it to true. If the value is false then always true, you are not resetting the bool.

            https://ninjatrader.com/support/foru...6558#post16558

            I look forward to being of further assistance.
            JesseNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by antrux, Yesterday, 06:26 PM
            0 responses
            3 views
            0 likes
            Last Post antrux
            by antrux
             
            Started by kevinenergy, Yesterday, 03:34 PM
            0 responses
            10 views
            0 likes
            Last Post kevinenergy  
            Started by Bidder, Yesterday, 01:50 PM
            1 response
            9 views
            0 likes
            Last Post NinjaTrader_PatrickG  
            Started by markbb10, Yesterday, 01:50 PM
            1 response
            8 views
            0 likes
            Last Post NinjaTrader_PatrickG  
            Started by Orden33, Yesterday, 10:09 AM
            3 responses
            12 views
            0 likes
            Last Post NinjaTrader_Jim  
            Working...
            X