![]() |
|
|||||||
| Strategy Development Support for the development of custom automated trading strategies using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Junior Member
Join Date: Nov 2008
Posts: 9
Thanks: 0
Thanked 0 times in 0 posts
|
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"); } |
|
|
|
|
|
#2 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
Please be more specific as to what errors you are getting. Thank you.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Junior Member
Join Date: Nov 2008
Posts: 9
Thanks: 0
Thanked 0 times in 0 posts
|
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 |
|
|
|
|
|
#4 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
Live? Sim? What brokerage connection are you using?
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Junior Member
Join Date: Nov 2008
Posts: 9
Thanks: 0
Thanked 0 times in 0 posts
|
Live. TDAmeritrade.
|
|
|
|
|
|
#6 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
For TDA, you may need to explicitly exit and then enter with ExitLong() and then EnterShort().
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#7 |
|
Junior Member
Join Date: Nov 2008
Posts: 9
Thanks: 0
Thanked 0 times in 0 posts
|
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()?
|
|
|
|
|
|
#8 |
|
Junior Member
Join Date: Nov 2008
Posts: 9
Thanks: 0
Thanked 0 times in 0 posts
|
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"); } } |
|
|
|
|
|
#9 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
An Exit order is ignored if no position is previously held. There should be no problems there.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#10 |
|
Junior Member
Join Date: Nov 2008
Posts: 9
Thanks: 0
Thanked 0 times in 0 posts
|
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.
|
|
|
|
|
|
#11 |
|
NinjaTrader Customer Service
Join Date: May 2008
Location: Denver, CO
Posts: 3,157
Thanks: 0
Thanked 3 times in 3 posts
|
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.
Ben
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
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 |