Hi fellow coders,
One problem I run into alot when I want to program a system is that I often don’t know which bar to use.
Let’s say I use the 1 hour timeframe and a time session of 08-22. (intraday system) If I want to compare the last candlestick of yesterday’s close (within my time session) with today’s open (within my time session).
What close[X] and open[X] do I use then? Is the open/close function adapting to my time session that i declared above or is it using the 24hour that comes with an 1hour timeframe view?
Hope you understand my question since it confuses me alot 🙂
You can use Dclose() and Dopen(), 0 is the cirrent one, 1 is the previous day:
YesterdayClose = Dclose(1)
TodayOpen = Dopen(0)
If i do an example of the above,
- will Dclose(1) return the last bar of the tsession @ 22:00 or the bar at 24:00 ?
2. will Dopen(0) return the first bar of the tsession @09:00 or the bar at 01:00 ?
ma20 = average[20]
ma200 = average[200]
tsession = time > 080000 and time < 220000
if tsession then
yclose = Dclose(1)
topen = Dopen(0)
if not longonmarket and topen < yclose and ma20 > ma200 and time=090000 then
buy 1 contract at market
endif
if longonmarket and topen > yclose then
sell 1 contract at market
endif
endif
Dopen and Dclose returns the default and official price of the market.