![]() |
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 2009
Posts: 1
Thanks: 0
Thanked 0 times in 0 posts
|
I'm trying to get more familiar with NinjaScript and I was trying to write a simple strategy that looked at yesterday's close and today's open.
I've imported end of day data into NinjaTrader, and with the code below, am not getting the results I expected. Code:
protected override void Initialize()
{
CalculateOnBarClose = true;
ExitOnClose = true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Condition set 1
// Is Close[-1] yesterday's open? Is Open[0] today's open?
if (Open[0] < Close[-1])
{
EnterLong(DefaultQuantity, "MyBuy");
}
}
When I look at the chart in the Backtest summary, it seems that I buy at today's open and sell at tomorrow's open. How can I ensure to buy at today's open and sell at today's close? |
|
|
|
|
|
#2 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
el_spudo,
You are using the [] indexes wrong. 0 refers to the most recent bar, 1 refers to the previous bar. To get yesterday's values you want to do [1] provided you are using daily charts.
Josh
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| EOD Data | jjben | Miscellaneous Support | 0 | 10-10-2008 07:35 PM |
| Charting high/low/close and open/close widths | gluebunny | Charting | 11 | 09-29-2008 10:47 AM |
| How do i use NT to open my Metastocks EOD? | Greenmoney21 | Miscellaneous Support | 4 | 05-25-2008 09:04 PM |
| Comparing Close to SMA value failing - why? | Iggy22 | General Programming | 2 | 04-19-2008 12:47 AM |
| Import EOD Data | rabruno | Charting | 1 | 10-17-2007 08:07 AM |