![]() |
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
|
|||||||
| Strategy Development Support for the development of custom automated trading strategies using NinjaScript. |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Junior Member
Join Date: May 2010
Posts: 4
Thanks: 0
Thanked 0 times in 0 posts
|
Hello everybody,
I need to access Positon.AvgPrice, Position.Quantity, etc. in such a scenario: 1. I open a position using ChartTrader or Super DOM. 2. Then I start my Ninja Script. 3. My Script obtains Positon.AvgPrice, and Position.Quantity and Prints them. The problem is that such a scenario provides only zeros as Position values. At the same time an instance of Position class do contains proper values ONLY if the position was created by the script itself!!! My script below confirmed this. Is there any way to access the opened position info within a script, that has been started AFTER the position was opened manually? Which Class or Method has access there? Thank you in advance. public class ShowPosition : Strategy { protected override void Initialize() { ClearOutputWindow(); CalculateOnBarClose = true; //false; Add("MSFT", PeriodType.Minute, 5); } private void PrintPositionInfo( int PosNumber ) { Print(" "); Print("CurrentBar = " + CurrentBar); Print( "Position# " + PosNumber ); Print("Position.AvgPrice=" + Position.AvgPrice); Print("Position.Quantity=" + Position.Quantity); Print("Position.MarketPosition=" + Position.MarketPosition); double PL = Position.GetProfitLoss(Close[0],0); // If not flat print our unrealized PnL if (Position.MarketPosition != MarketPosition.Flat) Print("Open PnL: " + Position.GetProfitLoss(Close[0], PerformanceUnit.Points)); } private void GoLong() { Print("CurrentBar=" + CurrentBar); if (CurrentBar == 30) { Print(""); Print("Inside EnterLong(100)"); EnterLong(100); PrintPositionInfo(0); } // Exits position if (CurrentBar == 35) { Print(""); Print("Inside ExitLong(50)"); ExitLong(50); PrintPositionInfo(0); } } protected override void OnBarUpdate() { GoLong(); } |
|
|
|
| Tags |
| position acceess programm |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| ADX indicator not providing public access to data | RandyT | Automated Trading | 8 | 06-02-2009 03:02 PM |
| How to access the ExitPrice of the last position? | Joerg | Strategy Development | 3 | 05-31-2009 11:40 AM |
| Access to STOP1 and TARGET1 values in script | snaphook | ATM Strategies (Discretionary Trading) | 1 | 04-14-2009 09:20 AM |
| How do I close a position established via ninja script | suitguy1 | Automated Trading | 1 | 07-29-2008 02:31 PM |
| How to access daily data series from an indicator running on intraday charts? | clearpicks | Indicator Development | 3 | 04-21-2008 06:57 AM |