Go Back   NinjaTrader Support Forum > NinjaTrader 7 > Strategy Development

Strategy Development Support for the development of custom automated trading strategies using NinjaScript.

NinjaTrader
Reply
 
Thread Tools Display Modes
Old 01-12-2018, 02:08 AM   #1
sampras010
Member
 
Join Date: Mar 2016
Posts: 43
Thanks: 6
Thanked 0 times in 0 posts
Default 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?
sampras010 is offline  
Reply With Quote
Old 01-12-2018, 11:31 AM   #2
NinjaTrader_Jesse
NinjaTrader Customer Service
 
NinjaTrader_Jesse's Avatar
 
Join Date: Mar 2014
Location: Denver, CO
Posts: 4,785
Thanks: 30
Thanked 1,216 times in 1,137 posts
Default

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.
NinjaTrader_Jesse is offline  
Reply With Quote
Old 01-15-2018, 12:19 PM   #3
NinjaTrader_Jesse
NinjaTrader Customer Service
 
NinjaTrader_Jesse's Avatar
 
Join Date: Mar 2014
Location: Denver, CO
Posts: 4,785
Thanks: 30
Thanked 1,216 times in 1,137 posts
Default

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.
NinjaTrader_Jesse is offline  
Reply With Quote
Old 01-16-2018, 05:46 AM   #4
sampras010
Member
 
Join Date: Mar 2016
Posts: 43
Thanks: 6
Thanked 0 times in 0 posts
Default

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 at 08:50 PM.
sampras010 is offline  
Reply With Quote
Old 01-18-2018, 02:47 AM   #5
sampras010
Member
 
Join Date: Mar 2016
Posts: 43
Thanks: 6
Thanked 0 times in 0 posts
Default

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?
sampras010 is offline  
Reply With Quote
Old 01-19-2018, 08:23 AM   #6
NinjaTrader_Jesse
NinjaTrader Customer Service
 
NinjaTrader_Jesse's Avatar
 
Join Date: Mar 2014
Location: Denver, CO
Posts: 4,785
Thanks: 30
Thanked 1,216 times in 1,137 posts
Default

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.
NinjaTrader_Jesse is offline  
Reply With Quote
The following user says thank you to NinjaTrader_Jesse for this post:
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Multi Instrument Time Delay Redmoon22 Strategy Development 1 05-26-2015 02:55 PM
Multi instrument entry/exit delay Stoop General Development 13 06-03-2014 07:32 AM
How to use different session templates in multi-timeframe/multi-instrument strategy? bourbonnais Platform Technical Support 9 12-10-2013 05:48 PM
multi instrument / multi timeframe strategy - Round2TickSize drolles Platform Technical Support 3 08-11-2011 05:21 PM
Multi-Instrument Multi-Entry Strategy: Getting EntryOrder Info AntiMatter Strategy Development 11 06-22-2011 12:01 PM


All times are GMT -6. The time now is 05:48 AM.

Futures, foreign currency and options trading contains substantial risk and is not for every investor. An investor could potentially lose all or more than the initial investment. Risk capital is money that can be lost without jeopardizing ones financial security or lifestyle. Only risk capital should be used for trading and only those with sufficient risk capital should consider trading. Past performance is not necessarily indicative of future results. View Full Risk Disclosure.

CFTC Rules 4.41 - Hypothetical or Simulated performance results have certain limitations, unlike an actual performance record, simulated results do not represent actual trading. Also, since the trades have not been executed, the results may have under-or-over compensated for the impact, if any, of certain market factors, such as lack of liquidity. Simulated trading programs in general are also subject to the fact that they are designed with the benefit of hindsight. No representation is being made that any account will or is likely to achieve profit or losses similar to those shown.

This website is hosted and operated by NinjaTrader, LLC (“NT”), a software development company which owns and supports all proprietary technology relating to and including the NinjaTrader trading platform. NT is an affiliated company to NinjaTrader Brokerage (“NTB”), which is a NFA registered introducing broker (NFA #0339976) providing brokerage services to traders of futures and foreign exchange products. This website is intended for educational and informational purposes only and should not be viewed as a solicitation or recommendation of any product, service or trading strategy. No offer or solicitation to buy or sell securities, securities derivative or futures products of any kind, or any type of trading or investment advice, recommendation or strategy, is made, given, or in any manner endorsed by any NT affiliate and the information made available on this Web site is not an offer or solicitation of any kind. Specific questions related to a brokerage account should be sent to your broker directly. The content and opinions expressed on this website are those of the authors and do not necessarily reflect the official policy or position of NT or any of its affiliates. 

Vendors along with their websites, products and services, collectively referred to as (“Vendor Content”), are independent persons or companies that are in no manner affiliated with NT or any if its affiliates. NT or any of its affiliates are not responsible for, do not approve, recommend or endorse any Vendor Content referenced on this website and it’s your sole responsibility to evaluate Vendor Content. Please be aware that any performance information provided by a vendor should be considered hypothetical and must contain the disclosures required by NFA Rule 2-29(c). If you are interested in learning more about, or investigating the quality of, any such Vendor Content you must contact the vendor, provider or seller of such Vendor Content. No person employed by, or associated with, NT or any of its affiliates is authorized to provide any information about any such Vendor Content.