NinjaTrader Support Forum  

Go Back   NinjaTrader Support Forum > NinjaScript Development Support > General Programming

General Programming General NinjaScript programming questions.

Reply
 
Thread Tools Display Modes
Old 08-09-2010, 06:40 AM   #1
symphys
Senior Member
 
Join Date: Feb 2010
Posts: 190
Thanks: 0
Thanked 0 times in 0 posts
Question StopBuy and StopSell

Sometimes especially in very volatile markets my strategy produces an error because I'm using StopBuy and StopSell orders and the market is already passed these.

So I use the GetCurrentAsk and GetCurrentBid functions in the way posted afterwards. Would this be the correct way to do it?

Code:
if (GetCurrentAsk() < entry) StopBuy();
if (GetCurrentBid() > entry) StopSell();

Thanks!
symphys is offline  
Reply With Quote
Old 08-09-2010, 07:18 AM   #2
NinjaTrader_Tim
NinjaTrader Customer Service
 
NinjaTrader_Tim's Avatar
 
Join Date: Nov 2009
Location: Denver, CO
Posts: 1,424
Thanks: 0
Thanked 3 times in 3 posts
Default

Hi symphys,

I'm not sure what the value for "entry" is, however you could also simply use GetCurrentAsk() in EnterLongStop(double stopPrice), for example.
NinjaTrader_Tim is offline  
Reply With Quote
Old 08-09-2010, 08:19 AM   #3
symphys
Senior Member
 
Join Date: Feb 2010
Posts: 190
Thanks: 0
Thanked 0 times in 0 posts
Default

Thanks for your answer.
While entry is a value anywhere above/below the current market price I just want to make sure that the Stop orders can be send.

So I guess I just want to know what the least minimum price is when the strategy enters a long/short stop position?

Testing in DOM with Ask 1,4898, Bid 1,4896 I can enter both sides long/short at bid price. This would mean my code is wrong and I would only need to check my entry against GetCurrentBid.
symphys is offline  
Reply With Quote
Old 08-09-2010, 08:30 AM   #4
NinjaTrader_Tim
NinjaTrader Customer Service
 
NinjaTrader_Tim's Avatar
 
Join Date: Nov 2009
Location: Denver, CO
Posts: 1,424
Thanks: 0
Thanked 3 times in 3 posts
Default

Hi symphys,

The minimum price would technically be the current bid or ask, of course whether you get filled at that price is out of your control, and the market could obviously move up or down, getting a better fill. However, if you use GetCurrentAsk() when entering long, you'd get a price very close to the current price traded.

You can attempt to enter the market at any price you want, however, using a EnterLongStop() should only let you submit at a price above the market, otherwise you would get an error or be filled immediately at the market price.
NinjaTrader_Tim 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


All times are GMT -6. The time now is 04:26 PM.