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 > General Programming

General Programming General NinjaScript programming questions.

Reply
 
Thread Tools Display Modes
Old 05-08-2009, 12:32 PM   #1
tomleeson
Member
 
Join Date: Apr 2009
Posts: 45
Thanks: 0
Thanked 0 times in 0 posts
Default how can you compare current bar price to the crossover value of the EMA/SMA

Im am experimenting with crossovers:
if (CrossAbove(EMA(Fast), SMA(Slow),1))
//if the current price is <= crossvalue
EnterLong("EMASMA");

elseif (CrossBelow(EMA(Fast), SMA(Slow),1))
//if the current price is >= crossvalue)
EnterShort("EMASMA");


I am stuck with the pseudo code in green
any ideas greatly appreciated
tomleeson is offline  
Reply With Quote
Old 05-08-2009, 12:47 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 need to determine what you consider is the cross value. Then just compare it to Close[0]. Close[0] on an unclosed bar is the latest price.
NinjaTrader_Josh is offline  
Reply With Quote
Old 05-08-2009, 12:49 PM   #3
tomleeson
Member
 
Join Date: Apr 2009
Posts: 45
Thanks: 0
Thanked 0 times in 0 posts
Red face correction

when the crossover occurs - the trade is at market and typically entered above the cross over for a long or below ot for a short - soometimes too much ---
so i want to try to control the entry range - maybe by putting a limit entry on lower/higher as appropiate with a trailing stop --- thats what i am building up to :-)

Last edited by tomleeson; 05-08-2009 at 01:00 PM. Reason: post analysis of posting !
tomleeson is offline  
Reply With Quote
Old 05-08-2009, 01:08 PM   #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

tomleeson,

Submit your limit order at a limit price of Close[0] +/- a few ticks to get you the order in at the cross. You need to do a few ticks because if you are exactly at Close[0] and the price moves away from you you could potentially end up submitting at an invalid price and get your order rejected.

Ultimately though slippage is part of electronic trading and you will have to just compensate for it in your system.
NinjaTrader_Josh is offline  
Reply With Quote
Old 05-08-2009, 01:11 PM   #5
tomleeson
Member
 
Join Date: Apr 2009
Posts: 45
Thanks: 0
Thanked 0 times in 0 posts
Default

Thanks Josh - i thouhgt i might be able to do it by getting it on really quick in the same bar - but this was not possible:
if (CrossAbove(EMA(Fast), SMA(Slow),0))
EnterLong(
"EMASMA");
elseif (CrossBelow(EMA(Fast), SMA(Slow), 0))
EnterShort(
"EMASMA");

So yes limits would be good - but then they might not be hit - but as you point out you cant get a quote before going to market ans expect it to wait!!!
Last edited by tomleeson; 05-08-2009 at 01:13 PM.
tomleeson is offline  
Reply With Quote
Old 05-08-2009, 01:15 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

Right. Your best bet may be to stick with market orders.
NinjaTrader_Josh is offline  
Reply With Quote
Old 05-08-2009, 01:18 PM   #7
tomleeson
Member
 
Join Date: Apr 2009
Posts: 45
Thanks: 0
Thanked 0 times in 0 posts
Default

thank you for your help Josh
tomleeson 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
Backtest Trading at the Closing Price on the Current Bar Anagoge Strategy Analyzer 13 08-25-2010 03:14 AM
How to buy at the closing price on current bar? klchoi123 Strategy Analyzer 65 08-03-2010 06:49 AM
EMA Crossover Rollins NinjaScript File Sharing Discussion 24 07-15-2009 10:58 AM
SMA crossover using NT script faithpips Indicator Development 6 05-01-2009 03:53 PM
Multi Time frame Ema Price Crossover??? linzvb Strategy Development 6 03-07-2008 07:37 AM


All times are GMT -6. The time now is 02:53 PM.