![]() |
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 |
|
Member
Join Date: Nov 2006
Location: , ,
Posts: 88
Thanks: 2
Thanked 0 times in 0 posts
|
Hi
I want to store the low of the previous when a long position is opened. What is the best way to do this? I know how to use variables - and how the find the close of the bar - and therefore do not help with that. What I need help with something like: if (long position was just opened) closevar = Close[1] what is the condition I must use for "long position was just opened). This condition would only be true for the bar on which the position was opened - and not for the next bar although the long position would still be open. Verge |
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,414
Thanks: 252
Thanked 978 times in 961 posts
|
verge, there are several ways to do this - easiest would be to just save the close value to a variable at the time your entry condition evaluates to true, if you place for example a limit or stop order that would last for same bars until filled and you wanted to get the close of the bar the order was filled on, then work with the IOrder objects to access the orderstate change to OrderState.Filled - http://www.ninjatrader-support.com/H...V6/IOrder.html
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#3 | |
|
Member
Join Date: Nov 2006
Location: , ,
Posts: 88
Thanks: 2
Thanked 0 times in 0 posts
|
Quote:
Thank you for suggesting IOrder - I had a look at it. It is a pity that it does not have a "bar on which fill occurred" property included. I will try and code something that saves the bar number on which the property filled changed. Working with IOrders are still a bit difficult for me - still learning (will never stop) - can you give me a code snippet or a reference example to look at please Verge |
|
|
|
|
|
|
#4 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,414
Thanks: 252
Thanked 978 times in 961 posts
|
Thanks for the info, you can check into this sample for working with IOrder objects - http://www.ninjatrader-support2.com/...ead.php?t=7499
Here's a snippet - Code:
private IOrder entryOrder = null;
private double myClose;
protected override void OnBarUpdate()
{
if (entryOrder == null && Close[0] > Open[0])
entryOrder = EnterLong();
}
protected override void OnOrderUpdate(IOrder order)
{
if (entryOrder != null && entryOrder.Token == order.Token)
{
if (order.OrderState == OrderState.Filled)
{
entryOrder = null;
myClose = Close[0];
}
}
}
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Member
Join Date: Nov 2006
Location: , ,
Posts: 88
Thanks: 2
Thanked 0 times in 0 posts
|
Thank you Bertrand
Verge |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| simple question how to close one position when more is opened | nicknamed | ATM Strategies (Discretionary Trading) | 1 | 07-27-2009 03:01 AM |
| Storing Real Time Bar Data and Performance | drob9876 | Miscellaneous Support | 1 | 04-01-2009 09:18 AM |
| Storing real time bar data | monpere | Charting | 5 | 06-24-2008 07:02 PM |
| I have opened position I cannot close | maxima | Miscellaneous Support | 6 | 06-10-2008 02:36 AM |
| Help with storing market data | max1ci6 | Miscellaneous Support | 9 | 02-27-2007 12:55 AM |