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 06-27-2012, 08:45 AM   #1
solondon
Junior Member
 
Join Date: Sep 2011
Posts: 14
Thanks: 1
Thanked 1 time in 1 post
Default Position.AvgPrice querie

Im starting to feel like im going to have a lot of questions, any help appreciated. Have the following procedure called from OnBarUpdate()


private void GoLong()
{

EnterLong("target1");

Print(Time[0].ToString()+ " Position.AvgPrice:" + Position.AvgPrice.ToString());

If i enter as above in my EOD strategy Position.AvgPrice is returning 0

I need to work out if the entry price - yesterdays low is greater than 100 and set my initial stop accordingly

Cheers,
Jlo
solondon is offline  
Reply With Quote
Old 06-27-2012, 08:50 AM   #2
NinjaTrader_RyanM
NinjaTrader Customer Service
 
NinjaTrader_RyanM's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
Default

Hi Jlo,

This will return 0 when not in a position. When you access it at the same time you submit the order, it won't have a chance to be filled yet. Better would be to move it to OnBarUpdate() and check it when you are not flat.

if (Position.MarketPosition != MarketPosition.Flat)
Print(Time[0].ToString()+ " Position.AvgPrice:" + Position.AvgPrice.ToString());
NinjaTrader_RyanM is offline  
Reply With Quote
Old 06-27-2012, 10:29 AM   #3
solondon
Junior Member
 
Join Date: Sep 2011
Posts: 14
Thanks: 1
Thanked 1 time in 1 post
Default

does that mean that on an end of day strategy i could not set the stop until the following day ie. onbarupdate re-occurs?

thanks for the reply
solondon is offline  
Reply With Quote
Old 06-27-2012, 10:35 AM   #4
NinjaTrader_RyanM
NinjaTrader Customer Service
 
NinjaTrader_RyanM's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
Default

It's possible but requires advanced handling. If you need to base any calculations on position average price but cannot wait until the next bar update, then you can work in our advanced framework with IOrders. OnExecution() handler is used for monitoring for order fills.
http://www.ninjatrader.com/support/h...nexecution.htm
NinjaTrader_RyanM is offline  
Reply With Quote
Old 06-28-2012, 03:17 AM   #5
solondon
Junior Member
 
Join Date: Sep 2011
Posts: 14
Thanks: 1
Thanked 1 time in 1 post
Default

ok thanks, another question if you have the time

How do i tell what the current stop value is for a position ie. I set

SetStopLoss("L1", CalculationMode.Price,tmpStop,false);

can I look back at this value later on or do i need to store it via a variable

Regards,
JLo
solondon is offline  
Reply With Quote
Old 06-28-2012, 07:11 AM   #6
NinjaTrader_RyanM
NinjaTrader Customer Service
 
NinjaTrader_RyanM's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
Default

Yes, you can access the price of these orders. The technique is shown in this reference sample:
http://www.ninjatrader.com/support/f...ead.php?t=5790
NinjaTrader_RyanM 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
Position.AvgPrice Trader.Jon Strategy Development 4 03-21-2011 08:13 AM
Clarification on Position.AvgPrice and Position.MarketPosition skyholder84 Automated Trading 1 12-26-2010 09:55 AM
Position.Avgprice james377 ATM Strategies (Discretionary Trading) 1 11-01-2010 04:24 PM
Position.AvgPrice Faspomy Strategy Development 7 02-16-2010 10:52 AM
Position.AvgPrice MrBaffalo Strategy Development 1 05-16-2007 09:01 AM


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