PDA

View Full Version : Re: How to buy the open and sell the close


JayNice
07-07-2009, 10:52 AM
Hello,
I new to the forum and NinjaTrader. I'm trying to create a strategy that simply buys at the daily open and sells at that same daily bar's close. I'm aware that "EnterLong()" executes a market order that buys at the following day's opening price, but I don't know how to sell at that same bar's closing price. If I use "ExitLong" it exits the long position at the "next" day's open and not at the same day's closing price.

NinjaTrader_Austin
07-07-2009, 11:03 AM
JayNice, I've already responded in your other thread here (http://www.ninjatrader-support2.com/vb/showthread.php?t=18558). If you have another question, just ask.

JayNice
07-07-2009, 11:36 AM
I want to exit at the close of the same day the order was entered. If I entered a long position 2 wks ago with no particular sell conditions "ExitOnClose=true" would liquidate at "today's" close which would be 2 wks later. I want to liquidate the position at the close of the same day the order was executed...

NinjaTrader_Austin
07-07-2009, 12:34 PM
I'm not sure we're on the same page. What type of charts are you using? If you're running this on Daily bars, ExitOnClose cancels all open orders and closes positions before the day ends.

JayNice
07-07-2009, 12:39 PM
I'm running this in Strategy Analyzer. All I want to do is back test a strategy that buys at the open and sells at the close of the "same bar". It makes no difference what the buy and sell conditions are. Again, the only thing I'm interested in is buying at open and selling at the close of the same bar.

NinjaTrader_Austin
07-07-2009, 01:04 PM
JayNice, you can try adding detail to your strategy and backtesting it with intraday granularity (http://www.ninjatrader-support2.com/vb/showthread.php?t=6652).

JayNice
07-07-2009, 01:04 PM
Here's the code that I'm running in Strategy Analzyer. When this code is ran it goes long at the opening price of the first bar that meets the criteria of condition statement, then it exits the long position at the final day of the price series. I want to exit at the close of the same day that the long position was established.

protected override void OnBarUpdate()
{
// NOTE: I'm using daily price when I run this in Strategy Analyzer.
// If today's close > perious days high buy tomorrow at the market.
// I want to exit at the close of the same bar that the trade was entered.

if(Close[0]>High[1])
{
EnterLong();
}

}

ps. I have "ExitOnClose=true" within the Initialize() method...

NinjaTrader_Austin
07-07-2009, 01:06 PM
We just posted at the same time, please see my post #6.

JayNice
07-07-2009, 01:08 PM
yeah sure, your a world of help! thanks for everything, typical tech support!!!!!