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 10-30-2009, 02:32 PM   #1
paschall
Junior Member
 
Join Date: Dec 2008
Posts: 25
Thanks: 0
Thanked 0 times in 0 posts
Default strategy executes trade when conditions are wrong

I am having a puzzling time figuring out some NT performance errors. I have a simple strategy that enters a LONG trade when several indicators are all moving UP. The reverse is true for SHORT trades. However, I am finding several instances where NT executes a LONG trade when the SMA is actually going DOWN. Yikes! I have attached a screen shot to illustrate. The gold line is the SMA of price. It is clearly going DOWN, but NT executes a LONG trade. Here is the code from the strategy:

protected override void OnBarUpdate()
{...
double sma1 = SMA(Close, periodMovingAverage)[1];
double sma0 = SMA(Close, periodMovingAverage)[0];
...
bool HigherSMA = false;
...
if(sma0 > sma1)
HigherSMA = true;
...
If(HigherSMA)
{EnterLongLimit(...)}

Any ideas why NT enters a LONG trade when the condition is visibly not met? I have confirmed the action by manually observing the SMA values in the data box. SMA is definitely going down, not up.

Thanks for your feedback,
D
Attached Images
File Type: jpg SMA_going_down.jpg (80.4 KB, 3 views)
paschall is offline  
Reply With Quote
Old 10-30-2009, 03:02 PM   #2
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

You should print the values of your bools each step of the way and isolate what is happening under the hood.

Print(HigherSMA);
NinjaTrader_Josh 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
getting out of a trade going the wrong way paschall Strategy Development 1 09-14-2009 12:47 AM
Strategy: Using Rising and Falling conditions in the Strategy Wizard NinjaTrader_Josh Reference Samples 0 08-05-2009 01:43 PM
Strategy conditions jthom ATM Strategies (Discretionary Trading) 20 06-11-2009 12:54 PM
Strategy executes differntly backtest vs live latkinso Strategy Development 7 05-19-2008 07:13 AM
Strategy: Halting a Strategy Once User Defined Conditions Are Met NinjaTrader_Josh Reference Samples 0 01-04-2008 12:09 AM


All times are GMT -6. The time now is 11:28 AM.