NinjaTrader Support Forum  
X

Attention!

This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com


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 01-08-2012, 12:45 AM   #1
Asing
Member
 
Join Date: Jul 2010
Posts: 55
Thanks: 0
Thanked 0 times in 0 posts
Default Simple backtest not working

I have created a simple strategy from the wizard using a channel indicator that buys on crossing above and sells when crossing below. I have set the strategy on a AAPL daily chart and I am not getting any signals. Is there something wrong with the way the wizard set up the code:
private int lengthMA = 10; // Default setting for LengthMA
private int lengthATR = 10; // Default setting for LengthATR
private double offset = 1; // Default setting for Offset
// User defined variables (add any user defined variables below)
#endregion

/// <summary>
/// This method is used to configure the strategy and is called once before any strategy method is called.
/// </summary>
protected override void Initialize()
{
Add(ddKeltnerChannel(LengthATR, Offset, LengthMA));
Add(ddKeltnerChannel(LengthATR, Offset, LengthMA));

CalculateOnBarClose = true;
}

/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Condition set 1
if (CrossAbove(Close, ddKeltnerChannel(LengthATR, Offset, LengthMA).Upper, 1))
{
EnterLongStop(DefaultQuantity, 0, "");
}

// Condition set 2
if (CrossBelow(Close, ddKeltnerChannel(LengthATR, Offset, LengthMA).Lower, 1))
{
EnterShortStop(DefaultQuantity, 0, "");
}
}

I have a more complex intraday strategy that is also not producing any back-tested results all of the sudden. It used to work fine. What could the problem be?
Asing is offline  
Reply With Quote
Old 01-08-2012, 03:15 PM   #2
NinjaTrader_AdamP
NinjaTrader Customer Service
 
NinjaTrader_AdamP's Avatar
 
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
Default

Asing,

I am happy to assist you.

You are using "EnterShortStop" and "EnterLongStop". I would suggest using "EnterLong" or "EnterShort" instead.

I am not familiar with the ddKeltnerChannel indicator so I cannot comment much further. Is it the same as the default one that comes with NinjaTrader?

Please let me know if I may assist further.
NinjaTrader_AdamP is offline  
Reply With Quote
Old 01-08-2012, 06:27 PM   #3
Asing
Member
 
Join Date: Jul 2010
Posts: 55
Thanks: 0
Thanked 0 times in 0 posts
Default

hi Adam, the dd channel is slightly modified, but I actually am working with the NT keltnerChannel and neither is producing signals. I also have a proprietary code that uses intraday bars and it was working until recently. I am trying to do historical backtests and i am not getting any signals at all from any of these strategies.
Asing is offline  
Reply With Quote
Old 01-08-2012, 06:30 PM   #4
NinjaTrader_AdamP
NinjaTrader Customer Service
 
NinjaTrader_AdamP's Avatar
 
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
Default

Asing,

Are you wanting to enter market orders on these signals?

If you could, please post your strategy here. It is located in My Documents / NinjaTrader 7 / bin / custom / strategy.

I look forward to assisting you in resolving your issue.
NinjaTrader_AdamP is offline  
Reply With Quote
Old 01-08-2012, 06:49 PM   #5
Asing
Member
 
Join Date: Jul 2010
Posts: 55
Thanks: 0
Thanked 0 times in 0 posts
Default

hi Adam, I changed the entries from stops to just vanilla entry and now I am getting signals, My question is how is this executed in real time, as market orders? "Enter Long", Enter Short"
Asing is offline  
Reply With Quote
Old 01-08-2012, 06:51 PM   #6
NinjaTrader_AdamP
NinjaTrader Customer Service
 
NinjaTrader_AdamP's Avatar
 
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
Default

Asing,

Yes, these are market orders.

I am happy you have resolved your issue. Please let me know if you require additional assistance.
NinjaTrader_AdamP is offline  
Reply With Quote
Old 01-08-2012, 06:54 PM   #7
Asing
Member
 
Join Date: Jul 2010
Posts: 55
Thanks: 0
Thanked 0 times in 0 posts
Default

Just a question as to how these entries are executed in real time. Enter long is a market order that gets executed on the next bar's open after a signal is generated from the closing of the previous bar?
Asing is offline  
Reply With Quote
Old 01-08-2012, 07:31 PM   #8
Asing
Member
 
Join Date: Jul 2010
Posts: 55
Thanks: 0
Thanked 0 times in 0 posts
Default

The problem that I have now is hat the strategy buys and exits on the same bar. It is the strategy that was posted earlier in this chain
Asing is offline  
Reply With Quote
Old 01-08-2012, 10:16 PM   #9
Asing
Member
 
Join Date: Jul 2010
Posts: 55
Thanks: 0
Thanked 0 times in 0 posts
Default

I am wondering if this is related to time zone as this has caused all kinds of problems in the past with charts and strategies . I am trading from Asia time zone, but I am using a a day bar for this backtest and I did not think it would matter, Can you think of any other reason why the strategy would enter and exit at the open of the same bar?
Asing is offline  
Reply With Quote
Old 01-08-2012, 10:53 PM   #10
Asing
Member
 
Join Date: Jul 2010
Posts: 55
Thanks: 0
Thanked 0 times in 0 posts
Default

If I use the sample MA strategy provided by NT the same thing happens whether with daily or intraday data. Enter and exit on the open of same bar.
Asing is offline  
Reply With Quote
Old 01-09-2012, 07:23 AM   #11
NinjaTrader_AdamP
NinjaTrader Customer Service
 
NinjaTrader_AdamP's Avatar
 
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
Default

Asing,

Quote:
Just a question as to how these entries are executed in real time. Enter long is a market order that gets executed on the next bar's open after a signal is generated from the closing of the previous bar?
This depends on what CalculateOnBarClose is set to. If its false, it will submit an order intra-bar and then get filled shortly thereafter. If its set to true then it will be on the open of the next bar since a bar just closed prior. Please be aware that in backtesting COBC = true effectively.

Quote:
The problem that I have now is hat the strategy buys and exits on the same bar. It is the strategy that was posted earlier in this chain

I am wondering if this is related to time zone as this has caused all kinds of problems in the past with charts and strategies . I am trading from Asia time zone, but I am using a a day bar for this backtest and I did not think it would matter, Can you think of any other reason why the strategy would enter and exit at the open of the same bar?

If I use the sample MA strategy provided by NT the same thing happens whether with daily or intraday data. Enter and exit on the open of same bar.
Are you using EnterLong() and EnterShort() now or still using the stop orders? If you recently added a stop-loss or take-profit this could occur.

I look forward to assisting you.
Last edited by NinjaTrader_AdamP; 01-10-2012 at 07:48 AM.
NinjaTrader_AdamP is offline  
Reply With Quote
Old 01-09-2012, 04:07 PM   #12
Asing
Member
 
Join Date: Jul 2010
Posts: 55
Thanks: 0
Thanked 0 times in 0 posts
Default

Hi Adam, I am only using the Enter Long and Enter Short. And as I said, as a test I used the sample MA strategy provided by NT on an AAPL daily chart and had the same problem of enter and exit on the same daily bar at the same price
Asing is offline  
Reply With Quote
Old 01-10-2012, 07:02 AM   #13
NinjaTrader_AdamP
NinjaTrader Customer Service
 
NinjaTrader_AdamP's Avatar
 
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
Default

Asing,

Please be sure that in the strategy analyzer properties, you are setting the "Time in force" property to "GTC" not "Day".

Please let me know if I may assist further.
NinjaTrader_AdamP is offline  
Reply With Quote
Old 01-10-2012, 07:16 AM   #14
Asing
Member
 
Join Date: Jul 2010
Posts: 55
Thanks: 0
Thanked 0 times in 0 posts
Default

Yes, it has always been set to GTC.
Asing is offline  
Reply With Quote
Old 01-10-2012, 07:57 AM   #15
NinjaTrader_AdamP
NinjaTrader Customer Service
 
NinjaTrader_AdamP's Avatar
 
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
Default

Asing,

What session template are you using? Could you possibly take a screen shot of all of your settings you have for your back test in the Strategy Analyzer? Could you also please take a screen shot of the chart showing the orders?

http://www.wikihow.com/Take-a-Screen...rosoft-Windows

I cannot reproduce your issue on my end with SampleMACrossOver, ExitOnClose = true, Time in Force = GTC, on the ES being back-tested over the last 2 months of data. I get trades over multiple days.

I look forward to helping you resolve your issue.
Last edited by NinjaTrader_AdamP; 01-10-2012 at 08:07 AM.
NinjaTrader_AdamP 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
Problems getting a simple strat working mikeklein ATM Strategies (Discretionary Trading) 6 04-18-2011 02:38 PM
Simple Indicator Not Working tradinginzen Indicator Development 7 11-08-2010 08:54 AM
What is going on here? Simple things not working. lookOutBelow Automated Trading 6 07-26-2010 07:55 AM
Simple strategy on SRS - backtest/Wizard Dan Leontieff Strategy Development 5 03-03-2009 11:43 AM
Starting Simple - Not working GoBoks General Programming 5 10-20-2007 09:59 PM


All times are GMT -6. The time now is 03:55 AM.