NinjaTrader Support Forum  

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 05-11-2009, 09:52 AM   #1
philrx300
Junior Member
 
Join Date: Nov 2008
Posts: 9
Thanks: 0
Thanked 0 times in 0 posts
Default EMA Cross Strategy

I seem to get an error when I run a strategy and It buys let's say, 100 shares when the EMA's cross.
Then at a point (when the EMA's cross again) it should sell the 100 shares and short 100 shares.

That's where I get the error. It will close the first position and not open
the new one. See below code. Is this not correct? It works great in
back test mode, but for some reason I get errors when it is live and
the strategy stops.

// Condition set 1
if (CrossAbove(EMA(Fast), EMA(Slow), 1))
{
EnterLong(Shares, "EMA System Long");
PlaySound(@"C:\Program Files\NinjaTrader 6.5\sounds\Alert4.wav");
}
else if (CrossBelow(EMA(Fast), EMA(Slow), 1))
{
EnterShort(Shares, "EMA System Short");
PlaySound(@"C:\Program Files\NinjaTrader
6.5\sounds\Alert4.wav");
}
philrx300 is offline  
Reply With Quote
Old 05-11-2009, 09:59 AM   #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

Please be more specific as to what errors you are getting. Thank you.
NinjaTrader_Josh is offline  
Reply With Quote
Old 05-11-2009, 10:47 AM   #3
philrx300
Junior Member
 
Join Date: Nov 2008
Posts: 9
Thanks: 0
Thanked 0 times in 0 posts
Default

Strategy ‘SRSSYSTEM’ submitted an order that generated the following error ‘OrderRejected’. Strategy has sent cancel requests, attempted to close the position and terminated itsef.


Multiple open sell/buy cover orders in this security may result in an oversold/overbought position in your account. Affecte4d Order BuyToCover 100 Market
philrx300 is offline  
Reply With Quote
Old 05-11-2009, 11:00 AM   #4
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

Live? Sim? What brokerage connection are you using?
NinjaTrader_Josh is offline  
Reply With Quote
Old 05-11-2009, 12:57 PM   #5
philrx300
Junior Member
 
Join Date: Nov 2008
Posts: 9
Thanks: 0
Thanked 0 times in 0 posts
Default

Live. TDAmeritrade.
philrx300 is offline  
Reply With Quote
Old 05-11-2009, 01:03 PM   #6
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

For TDA, you may need to explicitly exit and then enter with ExitLong() and then EnterShort().
NinjaTrader_Josh is offline  
Reply With Quote
Old 05-11-2009, 02:07 PM   #7
philrx300
Junior Member
 
Join Date: Nov 2008
Posts: 9
Thanks: 0
Thanked 0 times in 0 posts
Default

I was thinking that, but how do I handle if I don't have any shares... like for the first trade of the day? Can you help me? Would I just add ExitLong() before the EnterShort()?
philrx300 is offline  
Reply With Quote
Old 05-11-2009, 02:35 PM   #8
philrx300
Junior Member
 
Join Date: Nov 2008
Posts: 9
Thanks: 0
Thanked 0 times in 0 posts
Default

Here's what I have now:

// Condition set 1
if (CrossAbove(EMA(Fast), EMA(Slow), 1))
{
ExitShort("Exit Short", "EMA System Short");
EnterLong(Shares, "EMA System Long");
PlaySound(@"C:\Program Files\NinjaTrader 6.5\sounds\Alert4.wav");
}
else if (CrossBelow(EMA(Fast), EMA(Slow), 1))
{
ExitLong("Exit Long", "EMA System Long");
EnterShort(Shares, "EMA System Short");
PlaySound(@"C:\Program Files\NinjaTrader 6.5\sounds\Alert4.wav");
}
}
philrx300 is offline  
Reply With Quote
Old 05-11-2009, 02:42 PM   #9
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

An Exit order is ignored if no position is previously held. There should be no problems there.
NinjaTrader_Josh is offline  
Reply With Quote
Old 06-12-2009, 09:17 PM   #10
philrx300
Junior Member
 
Join Date: Nov 2008
Posts: 9
Thanks: 0
Thanked 0 times in 0 posts
Default

I get an error on NINJA but it does execute. A pop up boxes pops up and I click everything is ok. Seems like the ExitLong() is messing things up if there is no position open.
philrx300 is offline  
Reply With Quote
Old 06-14-2009, 11:34 AM   #11
NinjaTrader_Ben
NinjaTrader Customer Service
 
NinjaTrader_Ben's Avatar
 
Join Date: May 2008
Location: Denver, CO
Posts: 3,157
Thanks: 0
Thanked 3 times in 3 posts
Default

Hello,

Josh's post is correct. However provide us with a screen shot of your error and/or send us your log and trade files from Help>Mail to support and reference this thread link.
NinjaTrader_Ben 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
EMA cross Question Ninja Learner Strategy Development 23 05-28-2009 07:13 AM
EMA Combo Strategy fy260498 NinjaScript File Sharing Discussion 1 10-24-2008 05:14 PM
SMA Cross strategy dmc3415 General Programming 1 10-09-2008 03:10 PM
Using the Strategizer how do I write the entry EMA & exit using another EMA gygraham Strategy Development 1 02-05-2008 01:48 PM
MTF Ema Cross buderim Market Analyzer 1 10-17-2007 04:17 AM


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