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.
Simulation: trade on open bar price
- TJ
- Posts: 7775
- Joined: Aug 29 2006
- Location: Global Citizen
- Has thanked: 1036 times
- Been thanked: 2233 times
It is logically impossible to buy at current bar open.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.
- furytrader
- Posts: 354
- Joined: Jul 30 2010
- Location: Chicago, IL
- Has thanked: 155 times
- Been thanked: 217 times
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:
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.
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
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.
- furytrader
- Posts: 354
- Joined: Jul 30 2010
- Location: Chicago, IL
- Has thanked: 155 times
- Been thanked: 217 times
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