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 03-21-2011, 01:49 AM   #1
Trader.Jon
Senior Member
 
Join Date: Dec 2008
Posts: 338
Thanks: 0
Thanked 0 times in 0 posts
Question Position.AvgPrice

Greets,

I am trying to 'capture' the price of the entry, when the order is placed, for further use.

Code:
privatedouble MyEnterP125 = 0;
 
protectedoverridevoid OnBarUpdate()
{ sThisPrice.Set(Position.AvgPrice);
 
{ if ( (Position.MarketPosition == MarketPosition.Flat) && (timeSeries[0] >= 1) )
// Try to go LONG
{ if ( WatchToGoLong == 1 )
.................
if ((iOrderL5 == null || Historical) && iQuantity5 != 0)
{ iOrderL5 = EnterLong(0, iQuantity5, sENTRY5L);
MyEnterP125 = sThisPrice[0];
Print("Entry Price PT125 "+MyEnterP125);
}
 
I also had tried

MyEnterP125 = Position.AvgPrice;

(without using the DataSeries.Set etc) ... everything compiles but I only get '0'
(as in MyEnterP125 = 0; ) at the print during the strategy run on whatever attempt that does compile ...

Obviously missing something ...

Any assist is appreciated!

Thanks,
Jon
Last edited by Trader.Jon; 03-21-2011 at 01:52 AM.
Trader.Jon is offline  
Reply With Quote
Old 03-21-2011, 02:52 AM   #2
koganam
Senior Member
 
Join Date: Feb 2008
Location: Durham, North Carolina, USA
Posts: 3,356
Thanks: 24
Thanked 1,304 times in 1,067 posts
Send a message via Skype™ to koganam
Default

Your brackets look funny. Are you sure that you have posted the correct code?
koganam is offline  
Reply With Quote
Old 03-21-2011, 03:50 AM   #3
Baruch
Senior Member
 
Join Date: Mar 2009
Posts: 442
Thanks: 0
Thanked 25 times in 16 posts
Default

Quote:
MyEnterP125 = Position.AvgPrice
This instruction is correct, but you cannot execute it in OnBarUpdate()
immediately after executing an Enter..().
You can place it in OnExecution() or query it on the next bar.

Baruch
Baruch is offline  
Reply With Quote
Old 03-21-2011, 08:11 AM   #4
Trader.Jon
Senior Member
 
Join Date: Dec 2008
Posts: 338
Thanks: 0
Thanked 0 times in 0 posts
Default

Quote:
Originally Posted by koganam View Post
Your brackets look funny. Are you sure that you have posted the correct code?
I only posted the relevant portions for clarity and not all the brackets were carried forward.

Thanks for the feedback.

Jon
Trader.Jon is offline  
Reply With Quote
Old 03-21-2011, 08:13 AM   #5
Trader.Jon
Senior Member
 
Join Date: Dec 2008
Posts: 338
Thanks: 0
Thanked 0 times in 0 posts
Default

Quote:
Originally Posted by Baruch View Post
This instruction is correct, but you cannot execute it in OnBarUpdate()
immediately after executing an Enter..().
You can place it in OnExecution() or query it on the next bar.

Baruch
Baruch,

Thanks, I will give that a try.

Jon
Trader.Jon 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
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 Real Value daven Automated Trading 1 10-30-2008 09:31 AM
Position.AvgPrice MrBaffalo Strategy Development 1 05-16-2007 09:01 AM


All times are GMT -6. The time now is 08:32 AM.