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 05-02-2009, 12:31 PM   #1
el_spudo
Junior Member
 
Join Date: May 2009
Posts: 1
Thanks: 0
Thanked 0 times in 0 posts
Default Comparing today's open to yesterday's close on EOD data

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?
el_spudo is offline  
Reply With Quote
Old 05-02-2009, 03:20 PM   #2
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

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.
NinjaTrader_Josh 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
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


All times are GMT -6. The time now is 12:11 AM.