Simulation: trade on open bar price

Questions about MultiCharts and user contributed studies.
nlaporte
Posts: 21
Joined: 16 Feb 2011
Location: Switzerland
Has thanked: 1 time
Been thanked: 1 time

Simulation: trade on open bar price

Postby nlaporte » 14 Jun 2011

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.

User avatar
TJ
Posts: 6550
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 965 times
Been thanked: 1892 times

Re: Simulation: trade on open bar price

Postby TJ » 14 Jun 2011

nlaporte wrote: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.
These users thanked the author TJ for the post:
Stan Bokov

sptrader
Posts: 628
Joined: 09 Apr 2010
Location: Colorado
Has thanked: 394 times
Been thanked: 232 times
Contact:

Re: Simulation: trade on open bar price

Postby sptrader » 14 Jun 2011

He could buy at the "open price" on a stop or limit. It just wouldn't fill on that bar.

User avatar
furytrader
Posts: 353
Joined: 30 Jul 2010
Location: Chicago, IL
Has thanked: 154 times
Been thanked: 215 times

Re: Simulation: trade on open bar price

Postby furytrader » 15 Jun 2011

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.

User avatar
furytrader
Posts: 353
Joined: 30 Jul 2010
Location: Chicago, IL
Has thanked: 154 times
Been thanked: 215 times

Re: Simulation: trade on open bar price

Postby furytrader » 15 Jun 2011

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


nlaporte
Posts: 21
Joined: 16 Feb 2011
Location: Switzerland
Has thanked: 1 time
Been thanked: 1 time

Re: Simulation: trade on open bar price

Postby nlaporte » 16 Jun 2011

Thanks for the help
Best,

N.


Return to “MultiCharts”