Login Page - Create Account

Support Board


Date/Time: Wed, 27 Nov 2024 07:38:17 +0000



Programming help-automate with spreadsheet-trigger when bar CLOSES above

View Count: 835

[2023-09-05 21:28:06]
User120358 - Posts: 29
Hello, I’m trying to put a system together, and I would like it to trigger only after a bar closes above a line, rather than just a crossover from above/below. Price wicks through too often. I have looked around and worded my idea every way I can, nothing has come up.

Does anyone know if this is possible?

Thanks!
Date Time Of Last Edit: 2023-09-06 00:27:08
[2023-09-06 00:31:52]
User61168 - Posts: 403
Here's what you could do.... assuming reference to "Spreadsheet formula" in the title means you are using this study >> True Strength Index

1) Use Color Bar based on Alert condition study (say ID1.SG1). select "Evaluate On Bar Close" checkbox. Put your condition formula of above/below price level in this alert condition with a return output value of 1 when true.

2) put this in the spreadsheet formula ID2 study... IF(ID1.SG1=1,"enter spreadsheet formula condition here",0) to calculate only at bar close.

ID2 should run right after ID1 in order to trigger both on the same tick.

ps. better to post such questions under "Programming Help" to get more responses from other users
Date Time Of Last Edit: 2023-09-06 00:32:55
[2023-09-06 00:42:20]
User120358 - Posts: 29
Really appreciate the reply!

I am using the 'spreadsheet system for trading' to automate a play. I will see if your suggestion works, and I'll rename my post.

Thanks again!
Date Time Of Last Edit: 2023-09-06 00:46:32
[2023-09-06 14:43:02]
Sawtooth - Posts: 4120
I would like it to trigger only after a bar closes above a line, rather than just a crossover from above/below.
Either set 'Signal Only On Bar Close' to Yes,
or reference row 4 in your CROSSFROMBELOW formula, e.g.:
=CROSSFROMBELOW(E4:E5,ID1.SG1@4:ID1.SG1@5)
[2023-09-06 21:35:54]
User120358 - Posts: 29
I really appreciate your reply! I have been browsing the forum and you are seriously knowledgeable with this stuff.

Most things I've found have been moving average systems, I am trying to get an entry once prices closes above a TAS box.

I found some code you posted for someone else, and I've adjusted it using another post of yours I found.

TAS box is ID19, SG1, I got it working using this code:

=CROSSFROMBELOW(E3:E4,ID19.SG1@3:ID19.SG1@4)

For the stop signal, the study is ID20, SG1, but it doesn't have to close below, just exit the trade on touch.

=CROSSFROMABOVE(E3:E4,ID20.SG2@3:ID20.SG2@4)

This code is almost right, but it is still for the close below.. I believe its the E3:E4, but when I take it away, it throws ARGS.. Would you be able to tell me how to make it just a cross/touch?


Thank you in advance!
Date Time Of Last Edit: 2023-09-06 22:57:36
[2023-09-06 23:11:06]
Sawtooth - Posts: 4120
Would you be able to tell me how to make it just a cross/touch?
The spreadsheet syntax CROSSFROMBELOW/CROSSFROMABOVE functions requires two ranges, separated by a comma.
https://www.sierrachart.com/index.php?page=doc/SpreadsheetFunctions.html#CROSSFROMABOVE_Function

Try this:
=CROSSFROMBELOW(C3:C4,ID19.SG1@3:ID19.SG1@4)
This uses the High, so with Signal Only On Bar Close set to Yes, it will not require a crossover of the Close, at bar close.
[2023-09-07 00:45:18]
User120358 - Posts: 29
That shows the trigger on the chart when I run the replay! But it didn't close my sim position. Is there something I have to do to make it work?

Its like supertrend stop that Im trying to use as my stop trigger, so once price hits it, it flips to the top to act as a stop for shorts now. So it can really just be a 'touch', it can't be a bar closing or anything. I feel like I've seen this answered before but I can't find it!
Date Time Of Last Edit: 2023-09-07 02:32:45
[2023-09-07 02:54:45]
Sawtooth - Posts: 4120
Is there something I have to do to make it work?
Yes, and it can be made to work.

Are your entries at a pullback to the TAS box 20% line?
I need to know the ID#.SG# of the TAS box high, low, and 20% line, for both longs and shorts.
[2023-09-07 23:05:19]
User120358 - Posts: 29
I got it going! With some posts of yours I found. You are very generous to give so much help on here, and I certainly appreciate it.

I'm sure I'll have more questions at some point. Thanks again!
Date Time Of Last Edit: 2023-09-07 23:12:10
[2023-09-10 14:52:15]
User120358 - Posts: 29
Ok I'm back..

I'm having trouble getting multiple contract orders to be placed. I simply want it to enter me with 2 or 3 contracts, using attatched orders for stops. I have being trying and can't figure out for the life of me why it keeps placing one or throwing errors about the parent not being the same. The code just throws a buy or sell signal for whatever I have set up in the trade window correct? So its not an issue with my code?

The error I get is 'buy/sell exit signal is ignored. Long/short position quantity does not exist or there are already working orders that will flatten the position.'

I read through a bunch of the sierra stuff, so I may as well ask you about this while Im at it. I want the identical order placed for both directions. Long or short.. is there a setting I need to change for that? I saw something about needing to turn 'cancel all working orders on exit', which makes sense if some targets are hit, then a trade in the opposite direction comes.

Thanks in advance!
Date Time Of Last Edit: 2023-09-10 15:20:29
[2023-09-10 16:07:21]
Sawtooth - Posts: 4120
I simply want it to enter me with 2 or 3 contracts, using attatched orders for stops.
The quantity is set in J26, and this overrides the Trade Window quantity.

'Attached Orders' on the Trade Window must be checked.

You must create a Trade Window config (*.twconfig) to place the targets and stop where you want them.

You would only need L3/N3 exit formulas if there are additional exit conditions other than the Attached Orders.
If you are using both L3/N3 and Attached Orders, you need to set 'Cancel All Working Orders on Exit' to Yes.
The 'exit' in this setting is L3/N3.
[2023-09-10 16:19:35]
User120358 - Posts: 29
Ok so I will set J26 to my quantity, I can set my targets in the trade window.

‘You must create a Trade Window config (*.twconfig) to place the targets and stop where you want them.‘

Are you able to explain or give an example of this? Or do I just put that line you typed somewhere?
[2023-09-10 16:46:05]
Sawtooth - Posts: 4120
A *.twconfig file is created when you save the targets and stop offsets.

On the Trade Window:
Main tab >> M button >> Save Configuration

After you save it, reselect it in the dropdown menu.
[2023-09-12 01:32:38]
User120358 - Posts: 29
Im not sure if its just sim replays, but when Im entered in a trade long, with my two targets, once one is hit, and the trade turns around, my trigger to short does not enter me. The trigger shows up, but it doesn't work. Is it because there is still one target above that was never hit?
[2023-09-12 01:39:25]
Sawtooth - Posts: 4120
Do you want to Reverse your position?
If so, you must set 'Support Reversals' to Yes.

You must also set:
'Cancel All Orders On Reversals' to Yes
'Allow Entry With Working Orders' to Yes
'Allow Opposite Entry With Opposing Position or Orders' to Yes
[2023-09-12 03:04:30]
User120358 - Posts: 29
That was it! Thank you again for the help!
[2023-09-14 13:44:04]
User120358 - Posts: 29
Back again..

=CROSSFROMABOVE(E3:E4,ID19.SG3@3:ID19.SG3@4)

E:E4 in my code here, is 'last' price, so it closes the trade on the close of a bar. To close the trade on just a touch of something, rather than bar close, would it be B3:B4 as the open? If that is correct, and I wanted two triggers at the same time, do I just add AND, and put both codes into L3?

=CROSSFROMABOVE(E3:E4,ID19.SG3@3:ID19.SG3@4)
=CROSSFROMABOVE(B3:B4,ID19.SG3@3:ID19.SG3@4)
[2023-09-14 14:10:11]
Sawtooth - Posts: 4120
E3 is the Last, and not necessarily the Close.
E3 is the Last intrabar, and the Close at close-of-bar.

The CROSSFROMBELOW will work intrabar if Signal Only On Bar Close (Columns L,N-Z) is set to No.

Intrabar exit signals are at first occurrence intrabar, so there would be no need for also a close-of-bar exit, assuming you are flat.
Date Time Of Last Edit: 2023-09-14 14:11:15
[2023-09-15 01:06:19]
User120358 - Posts: 29
Beautiful, thank you!
[2023-09-15 22:18:31]
User120358 - Posts: 29
Alright, one more question for you!

Is it possible to draw trendlines, and give those lines an ID and SG number? So you can have your lines drawn, and let it take trades based on them?

I see when you right click a line, in the menu, it has properties, and the line has an ID already. -1909 for example. But the syntax throws an error, so it mustn't be that simple.

=CROSSFROMBELOW(E3:E4,ID19.SG1@3:ID19.SG1@4)

This would be what I'm trying to use with it.

Thanks in advance!
Date Time Of Last Edit: 2023-09-15 22:24:10
[2023-09-16 02:29:17]
Sawtooth - Posts: 4120
Is it possible to draw trendlines, and give those lines an ID and SG number?
No, but you can use this in a Color Bar Based On Alert Condition study:...
Study/Chart Alerts And Scanning: Referencing Chart Drawings
...then reference the color bar study's output in your spreadsheet formulas.

Note: You will likely find this to be too cumbersome to be of much use.
[2023-09-17 22:49:55]
User120358 - Posts: 29
Ok thank you. I'll take a look!

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

Login

Login Page - Create Account