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 10-08-2009, 02:28 AM   #1
verge
Member
 
Join Date: Nov 2006
Location: , ,
Posts: 88
Thanks: 2
Thanked 0 times in 0 posts
Default Storing data when position is opened

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
verge is offline  
Reply With Quote
Old 10-08-2009, 05:25 AM   #2
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,414
Thanks: 252
Thanked 978 times in 961 posts
Default

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
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 10-08-2009, 08:30 AM   #3
verge
Member
 
Join Date: Nov 2006
Location: , ,
Posts: 88
Thanks: 2
Thanked 0 times in 0 posts
Default Some additional information

Quote:
Originally Posted by NinjaTrader_Bertrand View Post
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
I did not give you enough information. My entry condition is not valid for one bar only - but a number of consecutive bars. A easy way to explain it would be the condition if (High[0] > High[1]) - it could be true for a number of bars. I will enter on the bar where the condition becomes true - but cannot save the close[1] in a variable because on the next bar (when the condition is still true) it will be updated - and I don't want it to update.

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
verge is offline  
Reply With Quote
Old 10-08-2009, 08:41 AM   #4
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,414
Thanks: 252
Thanked 978 times in 961 posts
Default

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]; 
            }
    } 
}
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 10-08-2009, 09:20 AM   #5
verge
Member
 
Join Date: Nov 2006
Location: , ,
Posts: 88
Thanks: 2
Thanked 0 times in 0 posts
Default Thank you

Thank you Bertrand

Verge
verge 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
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


All times are GMT -6. The time now is 09:02 PM.