Login Page - Create Account

Support Board


Date/Time: Thu, 25 Apr 2024 05:04:14 +0000



[User Discussion] - Spreadsheet System for Trading - Flatten Positions And Cancel Orders At Set Time

View Count: 2462

[2019-08-21 21:36:09]
User695518 - Posts: 50
Hello,

I am currently using the Spreadsheet System for Trading study. I have my spreadsheet study system set with the following:

Allow Trading Only During Time Range (read/write):  TRUE
Start Time For Allowed Time Range (read/write):  07:30:00
End Time For Allowed Time Range (read/write):  13:00:00


I also have the following set:

Flatten Positions And Cancel Orders At Set Time (read/write):  TRUE
Time For Flatten Positions And Cancel Orders (read/write):  13:05:00


My desire is to ensure that at 13:05:00 all positions are flattened and any outstanding orders are cancelled.

However, it appears that the Flatten Positions And Cancel Orders At Set Time only works within the time frame set within Allow Trading Only During Time Range. This is not ideal.

What happens if I set End Time For Allowed Time Range to 13:00:00 and Time For Flatten Positions And Cancel Orders to 13:00:00 and somehow a new order is triggered milliseconds after the flatten?

I would much rather that Flatten Positions And Cancel Orders At Set Time did not take Allow Trading Only During Time Range into account, so that I could stop automated trading at 13:00:00 and flatten all positions at 13:05:00, as an example.

As it stands, this issue could put automated traders in a very precarious position, where they think they are ending the day flat, but they are not!

Thanks!
[2019-08-22 03:56:33]
Sierra Chart Engineering - Posts: 104368
You just have to use a later time for this: End Time For Allowed Time Range (read/write):
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
[2019-08-22 13:16:19]
Sawtooth - Posts: 3976
You have more flexibility if you use J28 and J29 instead of J85-J89:

J28:
=AND(J8=0,OR(FRACTIME(J41)<TIMEVALUE("07:30:00"),FRACTIME(J41)>TIMEVALUE("13:00:00")))
This sets a time window for entries and exits, and allows exits after the time window.

J29:
=FRACTIME(J41)>=TIMEVALUE("13:05:00")
[2019-08-22 13:33:57]
User695518 - Posts: 50
tomgilb,

Let me say, you are absolutely amazing. I don't know what the SC user base would do without you... After I made this post, I actually found another post you replied to: Daily Loss Limit in Spreadsheet Auto Trading which helped lead me to a workaround for this issue.

It is still a little strange to me the SC's built in logic doesn't allow for a flatten/cancel all as a safeguard after autotrading is disabled, but with your help and expertise, I can make it work.

Thanks!
[2019-11-22 20:24:30]
User695518 - Posts: 50
Hello tomgilb,

I hope you are doing well and could help me once again here... I would like to use J29 to flatten/cancel on a particular date.

For the following example:

=AND((J41-INT(J41)) > TIMEVALUE("10:00:00"),J41-INT(J41)<TIMEVALUE("11:00:00"))

How could I add a date check, so that the logic is only true an a particular date? This doesn't seem to be as straightforward as I think it ought to be, or I am over complicating it.

Thanks again!
[2019-11-23 00:08:19]
Sawtooth - Posts: 3976
To return a particular date, use this function and syntax:
=DATEVALUE("11/22/2019")
https://www.sierrachart.com/index.php?page=doc/SpreadsheetFunctions.html#DATEVALUE_Function

To compare it to the Date in J41:
=INT(J41)=DATEVALUE("11/22/2019")
https://www.sierrachart.com/index.php?page=doc/SpreadsheetFunctions.html#INT_Function

To include it in your example:
=AND(J41-INT(J41)>TIMEVALUE("10:00:00"),J41-INT(J41)<TIMEVALUE("11:00:00"),INT(J41)=DATEVALUE("11/22/2019"))

Note:
J41 contains a number in Serial Date Time format, where the integer is the number of days since 1/1/1900, and the decimal is the portion of a day beginning at Midnight.
=INT(J41) returns the integer of the Serial Date Time value.
=J41-INT(J41) returns the decimal portion of the Serial Date Time value. (You can use the FRACTIME function instead): =FRACTIME(J41)
https://www.sierrachart.com/index.php?page=doc/SpreadsheetFunctions.html#FRACTIME_Function
The DATEVALUE function returns the integer of the Serial Date Time value from a text string of the date.
The TIMEVALUE function returns the decimal portion of the Serial Date Time value from a text string of the time.
Spreadsheet Example Formulas and Usage: Using Date Time
Date Time Of Last Edit: 2019-11-23 13:17:06
[2019-11-23 05:20:50]
User695518 - Posts: 50
Tom,

That is just the explanation I was looking for. I just couldn't wrap my head around INT vs. J41-INT.

Have a great weekend sir!

Thanks!

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

Login

Login Page - Create Account