Login Page - Create Account

Support Board


Date/Time: Sat, 27 Apr 2024 10:23:51 +0000



[Programming Help] - Automated Trading

View Count: 4190

[2019-01-02 00:12:02]
User575872 - Posts: 59
Hello, I have been a customer of Sierrachart since December and I am very satisfied with the software. I am currently experimenting with spreadsheet-auto-trading. My question: Is it possible to trigger an order at a certain time? I did not get any further with the "time-line" study. I am also not an excel professional ....

Thank you for an answer.
regards
[2019-01-02 16:43:44]
John - SC Support - Posts: 31159
There are some examples of how to use Dates and Times related to Spreadsheet Trading here:
Spreadsheet Example Formulas and Usage: Trading Formulas

We are unable to help beyond pointing you to this documentation, therefore we have marked this thread as Programming Help. There are other users that may be able to help you further with your questions.
For the most reliable, advanced, and zero cost futures order routing, use the Teton service:
Sierra Chart Teton Futures Order Routing
[2019-01-02 18:19:59]
Sawtooth - Posts: 3976
Is it possible to trigger an order at a certain time?

Yes, if you are using the Spreadsheet System for Trading study.

You would need to use the FRACTIME and NOW() functions and compare it to a time value window, like in these examples:
=AND(FRACTIME(NOW())>=TIMEVALUE("09:30:00"),FRACTIME(NOW())<TIMEVALUE("09:30:02"))
=AND(FRACTIME(NOW())>=$J$75,FRACTIME(NOW())<$J$75+2/86400)

You may need to make the time window wider than 2 seconds.

J75 is the chart's Session Start Time.
2/86400 is equal to 2 seconds of Serial Date Time Value.


These formulas would go in row 3 of columns K or M. Other entry conditions could be included.

These are the available spreadsheet functions:
Spreadsheet Functions
[2019-01-03 10:20:43]
User575872 - Posts: 59
Hello, thank you very much for the tips! I tried it out right away, the system also responded but put a buy entry on every bar. Is there another clue? Sorry, I'm a newcomer to Excel and looking for ways to handle automatic trading...
Date Time Of Last Edit: 2019-01-03 10:20:57
[2019-01-03 14:35:05]
Sawtooth - Posts: 3976
To limit the visual to only the entry bar, add a reference to row 3, like this:

=AND(FRACTIME(NOW())>=TIMEVALUE("09:30:00"),FRACTIME(NOW())<TIMEVALUE("09:30:02"),ROW()=3)
[2019-01-04 19:17:10]
User575872 - Posts: 59
=AND(FRACTIME(NOW())>=TIMEVALUE("09:30:00"),FRACTIME(NOW())<TIMEVALUE("09:30:02"))
=AND(FRACTIME(NOW())>=$J$75,FRACTIME(NOW())<$J$75+2/86400)=AND(FRACTIME(NOW())>=TIMEVALUE("09:30:00"),FRACTIME(NOW())<TIMEVALUE("09:30:02"),ROW()=3)
=ID0.SG4@3:ID0.SG4@4

Hi, what's wrong with this command? I put it in row K 3. The system should make a long entry at time 9:30. The long entry is coming, but not on the current chart value and not at the scheduled time …..
[2019-01-04 22:49:38]
Sawtooth - Posts: 3976
I gave two examples in post #3. Use one or the other.

The two examples assume you want to enter exactly at 09:30:00, and in order to do that, use these spreadsheet study settings:
- 'Signal Only On Bar Close' set to No
- 'Signal Only Once Per Bar' set to Yes.
This will allow only the first intrabar entry signal to occur.

If you are placing a Limit or Stop entry order, use a formula in cell J22 that returns the price, and set the correct order type in cell J71.
[2019-01-06 14:24:35]
User575872 - Posts: 59
I set:
'Signal Only Once Per Bar' to Yes.
'Signal Only On Bar Close' to No

I put:
=AND(FRACTIME(NOW())>=TIMEVALUE("09:30:00"),FRACTIME(NOW())<TIMEVALUE("09:30:02")) in cell K3

In cell J22 a "0" ( I think it means the actual contract-price)
In cell J71 a "S" for Stop Buy
In cell J75 a "09:00:00"

However, no order is triggered in the replay mode. Where is my mistake? ... or maybe ... are my mistakes? :-)
[2019-01-06 14:51:22]
Sawtooth - Posts: 3976
You can't use the NOW() function in replay because now is now, not a time in the past.

Use this instead:
=AND(FRACTIME($J$41)>=TIMEVALUE("09:30:00"),FRACTIME($J$41)<TIMEVALUE("09:30:02"))

J41 updates at each chart update, which is not necessarily as frequent as NOW(). This may cause entries to be slightly late, so you may need to widen the time window beyond 2 seconds.
[2019-01-06 19:04:39]
User575872 - Posts: 59
Thank you, it works and I can start working. I'm just looking for a way to enter multiple times in the system.
It's all pretty complex and my little Excel skills are complemented by my bad English ....
But it is very interesting and I just have to take small steps.
[2019-01-08 18:33:37]
User575872 - Posts: 59
Sorry, I do not find the answers I'm looking for in the documentation. For example, I would like to enter more time values in the formula below, for example: ("10:00:00"). If I do that and separate them with a comma or semicolon an error message appears. Or: If I copy the formula from cell k2 (buy entry) in cell O2 for example it doesn´t work too. What can I do?

=AND(FRACTIME($J$41)>=TIMEVALUE("09:00:00"),FRACTIME($J$41)<TIMEVALUE("09:00:06"))
[2019-01-08 19:15:00]
Sawtooth - Posts: 3976
Combine them with the OR function:

=OR(AND(FRACTIME($J$41)>=TIMEVALUE("09:00:00"),FRACTIME($J$41)<TIMEVALUE("09:00:06")),AND(FRACTIME($J$41)>=TIMEVALUE("10:00:00"),FRACTIME($J$41)<TIMEVALUE("10:00:06")))

In the Spreadsheet System for Trading study, only columns K-N are entry/exit columns. Other Formulas Columns O-Z...BR are for intermediate calculations, or other uses.

When you copy/paste a formula from one cell to another, the references will auto-compensate for the move, unless the references are made absolute with a preceding $. So to avoid this auto-compensation, you'll need to double click in the source cell, highlight the formula, Ctrl-C, double click in the destination cell, Ctrl-V.
Date Time Of Last Edit: 2019-01-09 19:30:55
[2019-01-08 20:09:01]
User575872 - Posts: 59
Fine! That helps me a lot! Thank you
[2019-01-09 19:14:16]
User575872 - Posts: 59
=OR(AND(FRACTIME($J$41)>=TIMEVALUE("09:00:00"),FRACTIME($J$41)<TIMEVALUE("09:00:06")),
=AND(FRACTIME($J$41)>=TIMEVALUE("10:00:00"),FRACTIME($J$41)<TIMEVALUE("10:00:06")))

Too soon looked forward to. If I use these formulas the error message "Syntax" comes.
[2019-01-09 19:32:49]
Sawtooth - Posts: 3976
Sorry.
Try again, using the edited formula in post #12.
[2019-01-11 09:15:29]
User575872 - Posts: 59
Well, thank you, the triggering works for the second time. My idea then simply copy that for the third and other time values, does not work. What do I have to adjust for it?

=OR(AND(FRACTIME($J$41)>=TIMEVALUE("09:00:00"),FRACTIME($J$41)<TIMEVALUE("09:00:06")),AND(FRACTIME($J$41)>=TIMEVALUE("10:00:00"),FRACTIME($J$41)<TIMEVALUE("10:00:06")),AND(FRACTIME($J$41)>=TIMEVALUE("11:00:00"),FRACTIME($J$41)<TIMEVALUE("11:00:06")))
[2019-01-11 15:59:37]
Sawtooth - Posts: 3976
The formula in post #16 does not return any errors for me. What is not working for you?

If you have many entry times, you could organize them in column H, then reference them in K3, like this:

H1:
=AND(FRACTIME(J41)>=TIMEVALUE("09:00:00"),FRACTIME(J41)<TIMEVALUE("09:00:06"))
H2:
=AND(FRACTIME(J41)>=TIMEVALUE("10:00:00"),FRACTIME(J41)<TIMEVALUE("10:00:06"))
H3:
=AND(FRACTIME(J41)>=TIMEVALUE("11:00:00"),FRACTIME(J41)<TIMEVALUE("11:00:06"))
K3:
=OR($H$1,$H$2,$H$3)
[2019-01-14 15:31:28]
User575872 - Posts: 59
The formulas in post # 17 work great. Many Thanks!
I still have two questions ...
Can I automatically cancel an active order after a certain period of time? So, for example after 30 minutes without fill?

Second question: Is it possible to trigger an order via volume? For example: If the volume of the current bar is twice the average of the last ten bars, then trigger an order.
[2019-01-14 17:30:24]
Sawtooth - Posts: 3976
1. Yes. There is an example on this page:
Spreadsheet Example Formulas and Usage

2. Yes. The entry formulas in K3/M3 can contain any set of conditions. Volume is in column F, or you can add the Volume study. You can base a moving average study on either, or you can create a moving average formula on the spreadsheet; see above link for an example. Then write a formula to compare the current volume to the average volume.
[2019-01-15 08:49:08]
User575872 - Posts: 59
I found this but moved H4 to H10 (because H4 is already occupied by my time commands). The order is briefly activated and then disappears immediately. Where is my mistake?

Cell Y3: =IF(AND (K5 = 0, K4), FRACTIME(A3), Y4)
This formula returns the closing timestamp of a Buy Entry signal in Column K.

Cell Z3: =IF(AND(M5 = 0, M4), FRACTIME(A3), Z4)
This formula returns the closing timestamp of a Sell Entry signal in Column M.

Cell H4: 3
This is the number of minutes to wait before canceling an unfilled working order.

Cell J27: =OR(AND(J4 > 0, FRACTIME(J41) - Y3 >= H4 / 1440), AND(J4 < 0, FRACTIME(J41) - Z3 >= H4 / 1440))
This formula will cancel an unfilled working order 3 minutes after the close of the entry bar. If bars are not time-based, it can occur intrabar.
[2019-01-15 16:04:19]
Sawtooth - Posts: 3976
It is assumed that entries are Limit or Stop, and that cells J71/J73 are set correctly, and that cells J22/J24 contain a formula that returns the entry price.
[2019-01-16 08:59:40]
User575872 - Posts: 59
Yes I set J71/J73 on S and use a formula (=E3+0.03) for J22/J24 to get a offset. It works in the sense that all orders are actually canceled except the one filled.

I wonder why in these formulas of K5 and K4 is the speech and not by K3

Cell Y3: =IF(AND (K5 = 0, K4), FRACTIME(A3), Y4)
This formula returns the closing timestamp of a Buy Entry signal in Column K.

Cell Z3: =IF(AND(M5 = 0, M4), FRACTIME(A3), Z4)
This formula returns the closing timestamp of a Sell Entry signal in Column M.


Sorry I have another question:
How can I say that I want to trigger an order depending on yesterday's high and low?
[2019-01-16 09:09:44]
User575872 - Posts: 59
Additional problem to post # 21: Really all unfilled orders will be canceled, including the stop order and limit order from the (filled) bracket order ...hmmm…. I ihink thats my problem … :-)
[2019-01-16 14:23:28]
Sawtooth - Posts: 3976
I wonder why in these formulas of K5 and K4 is the speech and not by K3
The formulas assume that entries are at close of bar, so it finds the opening timestamp of the next bar.

How can I say that I want to trigger an order depending on yesterday's high and low?
It would be possible to calculate the H/L using a few Formula Columns, or you could add the Daily OHLC study and reference its outputs.

Really all unfilled orders will be canceled, including the stop order and limit order from the (filled) bracket order
Use cell J78 instead of J27.
[2019-01-22 14:44:31]
User575872 - Posts: 59
Thank you very much, I have a very good basis for experimenting. But the structure is not so clear to me that I can help myself completely.

Some things work very well, others do not. For example, the command for Cell J89 "Cancel order at 11:00:00" does not work for me at all.

Also different entries (post # 17) are not executed. I enlarged the list to seven times. The following happens: Time entries 1 and 2 are executed, 3 and 4 are not, 5, 6 and 7 are executed again. Here too, canceling the non-executed orders does not work (via: Cell J27: = OR (AND (J4> 0, FRACTIME (J41) - Y3> = H4 / 1440), AND (J4 <0, FRACTIME (J41) - Z3 > = H4 / 1440)).
   
Another timed entry question: Is there a formula for regular entry, for example every ten minutes?

For my question from post # 18 ("Second question: Is it possible to trigger an order via volume?") I found the following formula: = AVERAGE (SG1 [0: -10)]> 100
But I do not know how to assign this formula to the volume.

To post a message in this thread, you need to log in with your Sierra Chart account:

Login

Login Page - Create Account