Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
date-time in SC Spreadsheet Study for backtesting - simple buy/sell rules Q
Hi, I'm trying to make a simple trading rule in the Spreadsheet System for Trading. Basically, in a sheet with 60-min bars, I want to buy at the ask at the top of every hour starting at 15:00:00 and ending at 21:00:00, and likewise sell at the bid at the bottom of each hour, starting 15:59:59 and ending at 21:59:59. My first inkling of an idea was to use an =IF() statement for columns K & L ('Buy Entry' & 'Buy Exit (Sell)'), going off of SC's documentation for the TIME() function, like this for example of a Buy Entry in K3:
I'm confused as to what to put in subsequent rows, and even this one, since the time stamp in column A will be changing and I'm making an explicit time range in the example.
A simpler approach *if backtesting wasn't planned* seems to just be a compound conditional statement using the NOW() date-time function, but that function is truly 'now' and has no linkage to a historical clock loop cycle, according to Sierra staff (I'm paraphrasing).
Any idea on cracking this riddle? I've been doing some intermediate-level strategy writing with the spreadsheets, but nothing with time logic like this.
Can you help answer these questions from other members on NexusFi?
There is no way to enter/exit at specific times of day. This is because the chart's time only advances when there is a chart update. You can observe this in J41. The same is true if you use the NOW() function.
The best you can do is bracket a time window that is wide enough so that a chart update occurs between it. In a slow market, this window would need to be wider than in a fast market.
However, since you want to enter at the open of a 60min bar and exit at its close, you can avoid the time window. Try this:
For exits:
- Use a formula like this in L3:
=AND(MROUND(FRACTIME(A3),1/86400)>=TIMEVALUE("15:00:00"),MROUND(FRACTIME(A3),1/86400)<=TIMEVALUE("21:00:00"))
This removes the floating point errors from the timestamp by rounding it to 1 second, and places a 1 in seven consecutive rows at 15:00 to 21:00.
(You don't need to use the IF function if the result is boolean.)
For entries:
- Use a formula like this in K3:
=AND(L3,$J$8=0)
This places a 1 in the same rows as the exits and waits until you are flat to enter.
Use the spreadsheet study settings in the attached.
Since entries are intrabar, they occur at the open, and exits then occur at close of bar.