Go Back   NinjaTrader Support Forum > NinjaTrader 7 > Strategy Development

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

Reply
 
Thread Tools Display Modes
Old 04-20-2012, 03:01 PM   #1
ds1111
Member
 
Join Date: Sep 2011
Location: Chicago
Posts: 78
Thanks: 9
Thanked 8 times in 8 posts
Default Enter order delayed 1 bar on range bars strategy

I created a custom indicator and now I’m trying to write a strategy to test it.
The indicator runs on range bars (6 range or 4 range), and once a certain condition is achieved, will print a dot in the bar. I will enter at the opening of the following bar. This is a pseudo code:

CUSTOM INDICATOR:
If (condition) and FirstTickOfBar
{
DrawDot ( bar[1]);
BullIndication.Set(true);
}

Then in my strategy I do the following:
Initialize()
{
CalculateOnBarClose = false;
CustomIndicator = customIndicator( parameters…);
Add(CustomIndicator);
}
OnBarUpdate()
{
If (CustomIndicator.BullIndication[0])
{
EnterLong(“LONG”);
}
}

The problem I’m having is that the strategy is entering 1 bar delayed. I was supposed to enter at the close of the bar with the DOT, and instead it’s sending the EnterLong signal a bar after that, which produces very wrong results to the entire scalping strategy since it’s too late.
Anybody knows how to solve this problem and oblige my strategy to issue the “EnterLong” at the close of the bar with the dot?
Thanks!
ds1111 is offline  
Reply With Quote
Old 04-20-2012, 03:17 PM   #2
NinjaTrader_Matthew
NinjaTrader Product Management
 
NinjaTrader_Matthew's Avatar
 
Join Date: Apr 2010
Location: Denver, CO, USA
Posts: 6,959
Thanks: 268
Thanked 1,331 times in 1,132 posts
Default

Hello,

Are you seeing this in historical back testing, or do you also see the delay in processing in real-time?

If you put the DrawDot function on the strategy itself when the condition is true, does it plot where you would expect, or is this also a bar behind?
NinjaTrader_Matthew is online now  
Reply With Quote
Old 04-20-2012, 04:10 PM   #3
ds1111
Member
 
Join Date: Sep 2011
Location: Chicago
Posts: 78
Thanks: 9
Thanked 8 times in 8 posts
Default

Historical backtesting for the last 3 months using the strategy analyzer.

I haven't run the strategy real time.
ds1111 is offline  
Reply With Quote
Old 04-21-2012, 06:29 AM   #4
koganam
Vendor
 
Join Date: Feb 2008
Location: http://omegasigmaindicators.com
Posts: 6,912
Thanks: 44
Thanked 2,807 times in 2,292 posts
Default

Quote:
Originally Posted by ds1111 View Post
I created a custom indicator and now I’m trying to write a strategy to test it.
The indicator runs on range bars (6 range or 4 range), and once a certain condition is achieved, will print a dot in the bar. I will enter at the opening of the following bar. This is a pseudo code:

CUSTOM INDICATOR:
If (condition) and FirstTickOfBar
{
DrawDot ( bar[1]);
BullIndication.Set(true);
}

Then in my strategy I do the following:
Initialize()
{
CalculateOnBarClose = false;
CustomIndicator = customIndicator( parameters…);
Add(CustomIndicator);
}
OnBarUpdate()
{
If (CustomIndicator.BullIndication[0])
{
EnterLong(“LONG”);
}
}

The problem I’m having is that the strategy is entering 1 bar delayed. I was supposed to enter at the close of the bar with the DOT, and instead it’s sending the EnterLong signal a bar after that, which produces very wrong results to the entire scalping strategy since it’s too late.
Anybody knows how to solve this problem and oblige my strategy to issue the “EnterLong” at the close of the bar with the dot?
Thanks!
What is the COBC setting for the indicator that the strategy is calling?
koganam is offline  
Reply With Quote
Old 04-21-2012, 05:05 PM   #5
ds1111
Member
 
Join Date: Sep 2011
Location: Chicago
Posts: 78
Thanks: 9
Thanked 8 times in 8 posts
Default

Both strategy and indicator: COBC = false;
ds1111 is offline  
Reply With Quote
Old 04-21-2012, 05:40 PM   #6
koganam
Vendor
 
Join Date: Feb 2008
Location: http://omegasigmaindicators.com
Posts: 6,912
Thanks: 44
Thanked 2,807 times in 2,292 posts
Default

Quote:
Originally Posted by ds1111 View Post
Both strategy and indicator: COBC = false;
That may be the problem .I see that you are using a named instance of the indicator in your strategy. Explicitly set the COBC property on that instance.
koganam is offline  
Reply With Quote
Old 04-23-2012, 12:24 PM   #7
ds1111
Member
 
Join Date: Sep 2011
Location: Chicago
Posts: 78
Thanks: 9
Thanked 8 times in 8 posts
Default

Ok... this is what I did in my strategy code:

Initialize()
{
CalculateOnBarClose = false;
CustomIndicator = customIndicator( parameters…);
Add(CustomIndicator);
CustomIndicator.CalculateOnBarClose = false;
}

Still I didn't see any difference in the behavior when I run the strategy. See picture attached. I'm still delayed 1 bar.

PS: btw, my indicator is a multi-timeframe strategy. That's why I'm using FirstTickOfBar in the indicator code to print the entry dots. Not sure if there is anything to do with this problem (and I believe it doesn't), but just would like to add this info out there.
Attached Images
File Type: png 2012-04-23_1310_Bar_Delay.png (18.3 KB, 9 views)
Last edited by ds1111; 04-23-2012 at 12:31 PM.
ds1111 is offline  
Reply With Quote
Old 04-23-2012, 12:53 PM   #8
NinjaTrader_Matthew
NinjaTrader Product Management
 
NinjaTrader_Matthew's Avatar
 
Join Date: Apr 2010
Location: Denver, CO, USA
Posts: 6,959
Thanks: 268
Thanked 1,331 times in 1,132 posts
Default

Hello,

The added series is likley a factor here.

Can you please clarify what interval the strategy runs on and which interval you have Add() to the strategy? 6 range or 4 range?

Under what BarsInProgress are you submitting the order? BarsInProgress == 0?

If you're not familiar with BIP, please take a look at the following link under 'How Bar Data is Referenced' and True Event Driven OnBarUpdate() Method

http://www.ninjatrader.com/support/h...nstruments.htm
NinjaTrader_Matthew is online now  
Reply With Quote
Old 04-23-2012, 04:30 PM   #9
ds1111
Member
 
Join Date: Sep 2011
Location: Chicago
Posts: 78
Thanks: 9
Thanked 8 times in 8 posts
Default

Just the indicator is using multitime frame, not the strategy.

I use a higher timeframe with 8 range bars to do some calculations, but the indicator runs on 6 range bars. All the logic that will trigger the 'dot' printing (and an entry) is processed in BIP = 0. As said, I use BIP = 1 just for some basic calculations, the results is passed to the code under BIP = 0.

Thanks for any help... I'm really puzzled by this... maybe the solution is to remove the entire higher time frame code to check if it's what is causing the problem.
ds1111 is offline  
Reply With Quote
Old 04-24-2012, 07:25 AM   #10
NinjaTrader_Matthew
NinjaTrader Product Management
 
NinjaTrader_Matthew's Avatar
 
Join Date: Apr 2010
Location: Denver, CO, USA
Posts: 6,959
Thanks: 268
Thanked 1,331 times in 1,132 posts
Default

Hello,

Thanks for the clarification - unfortunately there is not enough information here to know exactly what is occuring. I can only recommend that you do remove the higher time frame and continue to debug the strategy.

If you have not yet, please review our forum post for some ideas on debugging your custom NinjaScript code:

http://www.ninjatrader.com/support/f...ead.php?t=3418
NinjaTrader_Matthew is online now  
Reply With Quote
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
Range bars, strategy and close on bar coolmoss General Development 5 03-05-2012 01:04 PM
How to enter a limit order at the opening of the next bar TheEminiTrader Strategy Development 11 04-29-2011 02:42 PM
Highest Bar in an earlier range of bars Light General Development 6 01-26-2010 02:28 PM
Enter limit order but convert it to market order end of bar maxpi Strategy Development 3 05-07-2009 05:57 PM
Order Delayed by a Bar Trade1953 Platform Technical Support 2 01-31-2009 01:50 PM


All times are GMT -6. The time now is 04:00 PM.

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. Visit the CFTC resources for education regarding the industry and signs of fraud.