Page 1 of 1

Simulation: trade on open bar price

Posted: Jun 14 2011
by nlaporte
Dear all,

Any idea how I can turn the following into an EL code?
If "current bar open > last bar close" then "buy at current bar open"
Trivial but I cant figure it out.
Thank you very much,
Best,

N.

Re: Simulation: trade on open bar price

Posted: Jun 14 2011
by TJ
Dear all,

Any idea how I can turn the following into an EL code?
If "current bar open > last bar close" then "buy at current bar open"
Trivial but I cant figure it out.
Thank you very much,
Best,

N.
It is logically impossible to buy at current bar open.

Re: Simulation: trade on open bar price

Posted: Jun 14 2011
by sptrader
He could buy at the "open price" on a stop or limit. It just wouldn't fill on that bar.

Re: Simulation: trade on open bar price

Posted: Jun 15 2011
by furytrader
I think this can be simulated on an intraday chart by using intrabarordergeneration. For example, assuming that you're looking at a 5 minute bar of the e-Mini S&P 500 in Chicago (so the first bar of the day session has a timestamp of 8:35 am), you'd use something like:

Code: Select all


[intrabarordergeneration=true];

If Time = 835 and Open > CloseD(1) Then Buy Next Bar At Market;
SetExitOnClose; // Just to make sure you get out at the end of the day
When I put this on a 5 minute chart, and confirm that intrabarordergeneration is set to "on" in the strategy's properties, this shows me getting in at the open.

Technically, this code would wait for the market to first post a tick at the open in order to get into the trade, so you're not getting in precisely at the open (really the first tick after the market opens) but then again, a trader would also have to verify whether their criteria for entry is met before getting into the market.

Re: Simulation: trade on open bar price

Posted: Jun 15 2011
by furytrader
Also, if you are testing using daily bars and you wanted to buy at the open when the open is greater than the previous day's close, you can use the following code:

Code: Select all


value1 = Open of Tomorrow;
If Value1 > Close Then Buy Tomorrow At Market;

SetExitOnClose; // This is just to exit the trade at the end of the day so new ones may be entered

Re: Simulation: trade on open bar price

Posted: Jun 16 2011
by nlaporte
Thanks for the help
Best,

N.