Go Back   NinjaTrader Support Forum > NinjaScript Development Support > 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: 69
Thanks: 8
Thanked 6 times in 6 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 Customer Service
 
NinjaTrader_Matthew's Avatar
 
Join Date: Apr 2010
Location: Denver, CO, USA
Posts: 5,722
Thanks: 189
Thanked 778 times in 744 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 offline  
Reply With Quote
Old 04-20-2012, 04:10 PM   #3
ds1111
Member
 
Join Date: Sep 2011
Location: Chicago
Posts: 69
Thanks: 8
Thanked 6 times in 6 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
Senior Member
 
Join Date: Feb 2008
Location: http://omegasigmaindicators.com
Posts: 4,651
Thanks: 31
Thanked 1,929 times in 1,575 posts
Send a message via Skype™ to koganam
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: 69
Thanks: 8
Thanked 6 times in 6 posts
Default

Both strategy and indicator: COBC = false;
ds1111 is offline  
Reply With Quote
Old 04-21-2012, 05:40 PM   #6
koganam
Senior Member
 
Join Date: Feb 2008
Location: http://omegasigmaindicators.com
Posts: 4,651
Thanks: 31
Thanked 1,929 times in 1,575 posts
Send a message via Skype™ to koganam
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: 69
Thanks: 8
Thanked 6 times in 6 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 Customer Service
 
NinjaTrader_Matthew's Avatar
 
Join Date: Apr 2010
Location: Denver, CO, USA
Posts: 5,722
Thanks: 189
Thanked 778 times in 744 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 offline  
Reply With Quote
Old 04-23-2012, 04:30 PM   #9
ds1111
Member
 
Join Date: Sep 2011
Location: Chicago
Posts: 69
Thanks: 8
Thanked 6 times in 6 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 Customer Service
 
NinjaTrader_Matthew's Avatar
 
Join Date: Apr 2010
Location: Denver, CO, USA
Posts: 5,722
Thanks: 189
Thanked 778 times in 744 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 offline  
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 Programming 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 Programming 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 Automated Trading 2 01-31-2009 01:50 PM


All times are GMT -6. The time now is 01:48 PM.

FULL RISK DISCLOSURE: Futures 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.