Login Page - Create Account

Support Board


Date/Time: Thu, 02 May 2024 15:11:08 +0000



[Programming Help] - Spreadsheet System - Capture a value for later use?

View Count: 1251

[2020-06-19 01:03:17]
j4ytr4der_ - Posts: 918
I've read a bit about using persistent variables in Spreadsheets (thanks tomgilb), but they seem to require that you have values carried over from bar to bar. I just need to store a value when a trade triggers, for later use.

Specifically, I want to have two different trade signals. So my K3 and M3 columns each have a nested IF statement that contains the two triggers. If signal 1 is triggered, the value 1 is displayed. if signal 2 triggers, the value 2 is displayed So far so good.

The trouble is, as soon as the entry condition is no longer valid (which in this case can be a fraction of a second later at times) the entry cell goes back to 0 and I have no way to know which signal was taken. I want to change the target offset from the spreadsheet, only in the case of trigger 2 being taken. That would be easy except that the trigger value of 1 or 2 is gone after the entry so the offset cell has no idea if it should be used or not.

Is there some way to capture the trigger value when it appears, store it on a different cell, then clear it again on exit?

Hope that made sense! =)
[2020-06-19 02:21:07]
j4ytr4der_ - Posts: 918
Scratch that, I just realized that the stop offset value changing after entry, doesn't matter since it doesn't actually update the stop in any way once the trade is on. So my needs are met. =)
[2020-06-19 02:27:08]
j4ytr4der_ - Posts: 918
Actually now I seem to have bumped into a new issue with this.

When trigger 2 occurs, the stop offset is set and overrides whatever is in the TWC. This works fine. But, after that trade is done... the TWC has been lost.

How can I revert the TWC back to its original, saved state, after closing a trade that used the spreadsheet offset (J80)?
[2020-06-19 02:37:02]
j4ytr4der_ - Posts: 918
Now I'm afraid this might not be possible. I just read through Automated Trading Management: SupportAttachedOrdersForTrading and it looks like I can only specify (or reload) a TWConfig file through ACSIL. Am I right about this or is there any other way to get the TWC to reset after a trade?
[2020-06-19 03:41:52]
j4ytr4der_ - Posts: 918
OK I think I figured out what's going on. For anyone else who runs into this, here's the deal:

If you use a TWConfig to specify a target & stop, but then also specify a target (but NOT a stop) in your spreadsheet, your stop will suddenly vanish from the TWConfig and there is no way to bring it back without manually reloading the saved setting file.

BUT if your spreadsheet has BOTH a stop AND a target in it, then the existing stop and target are modified but not deleted. This means you can keep a BE Trigger Trail Stop in effect for instance, but under certain conditions adjust the target only (like in my case, I have a "strong signal" and a "weak signal" and the weak signal has a much tighter target than the strong signal, but both use the same stop logic).

Just don't leave one of the two field s(stop or target) blank in your spreadsheet, or the blank one will disappear from your Trade Window.
Date Time Of Last Edit: 2020-06-19 03:41:59
[2020-06-19 14:15:03]
Sawtooth - Posts: 3990
Is there some way to capture the trigger value when it appears, store it on a different cell, then clear it again on exit?
It's not possible to capture an intrabar value unless it endures until close of bar. A persistent value in a spreadsheet study is only from bar to bar.
You could use this method to capture an intrabar TRUE, but it is only a TRUE(1) not the value at its occurrence:
Spreadsheet Studies Special Tasks: Locking the State of a One Time Condition
Here is another example:
https://www.sawtoothtrade.com/example-9.html

How can I revert the TWC back to its original, saved state, after closing a trade that used the spreadsheet offset (J80)?
J80/J81 only sets the initial Attached Orders' target and stop offsets, and it overrides the Trade Window Config. If you leave one of these cells blank, it assumes you don't want to use it. Also, it assumes you are using a single target and a static stop.

The preferred method to do what you want is:
- Don't use J80 or J81.
- Use your saved TWC with its target and stop and BE setting
- Use the Trade Management by Study study to move the target, referencing a Formula Column/subgraph formula:
Attached Orders: Study Controlled Targets and Stops

This will keep your TWC and allow you to dynamically control your target.
Date Time Of Last Edit: 2020-06-19 14:32:20
[2020-06-19 14:28:20]
j4ytr4der_ - Posts: 918
Ahh ok, thanks so much. I saw that study but mistakenly assumed that using the cells in the spreadsheet was probably the better approach. I'll play with the other... thanks again!
[2020-06-20 18:16:32]
j4ytr4der_ - Posts: 918
I'm playing with managing a trail stop from the Trade Management by Study study, and it's behaving strangely. I have it set to update every 30 seconds and remain 2 ticks behind current price (using the Current Price Line study). But the instant a trade is filled (replay), the stop gets moved to 2 ticks behind current price. I can't figure out why... I have stripped my TWConfig down to have no target at all and only a simple 4 point stop. No BE triggers or trails or anything. The only thing that should be moving the stop is the management study, but why would it go into effect the instant a trade is filled? If I turn it off of course, then the stop is not adjusted and stays the 4 points away as expected.

Any idea what's going on here?
[2020-06-20 18:17:03]
j4ytr4der_ - Posts: 918
Oh and I've run in debug mode but nothing useful is displayed there.
[2020-06-20 19:09:05]
Sawtooth - Posts: 3990
I have it set to update every 30 seconds and remain 2 ticks behind current price (using the Current Price Line study). But the instant a trade is filled (replay), the stop gets moved to 2 ticks behind current price.
If the TMS is referencing the Current Price Line, and you have the TMS to trail it by 2 ticks, then the stop will be 2 ticks behind the current price.

The only thing that should be moving the stop is the management study, but why would it go into effect the instant a trade is filled?
The TMS can't move a stop until there is one, and that happens when a trade is filled.

Oh and I've run in debug mode but nothing useful is displayed there.
That's because it's doing everything you've told it to do.
[2020-06-20 19:42:32]
j4ytr4der_ - Posts: 918
Shouldn't the TMS kick in after the allotted time has passed? This is what isn't making sense to me. If I set it to 5 seconds, shouldn't it wait 5 seconds to start? Or is it intended to adjust the stop instantly upon fill, and then continuously after the desired time intervals pass?

I was looking for it to wait 1 block of time before kicking in. Maybe it just doesn't do that?
[2020-06-20 20:22:27]
Sawtooth - Posts: 3990
is it intended to adjust the stop instantly upon fill, and then continuously after the desired time intervals pass?
Yes, but that functionality is not documented.
Date Time Of Last Edit: 2020-06-20 20:24:45
[2020-06-20 20:43:35]
j4ytr4der_ - Posts: 918
Aha, ok that completely explains it then.

So given that the TSM won't work for me after all... any ideas on how to accomplish what I'm looking to do? Specifically I'm playing with a Spreadsheet system and am wondering how to implement two ideas:

1. A "time trail" that adjusts say maybe 1 tick every X seconds (but of course doesn't initiate until that many seconds have passed). This way if the momentum of the trade slows down but doesn't actually reverse enough to hit a stop, I'll gradually be locking in profits/reducing risk all the time.
2. I'd like to cancel working orders if they haven't filed within X seconds. I'm playing with a signal that, when it's going to work, generally moves very quickly (I'm placing stop orders to enter, 1 tick outside current price) and if within a few seconds the trade has not filled, then I want to cancel and bail on the signal. But I can't figure out any way to track the time since a signal was given, unless the signal persists over a full bar.

Appreciate any input into these two ideas you may have. Maybe they can't be done without delving into ACSIL, but I thought I'd at least give them a shot.
[2020-06-20 22:03:14]
Sawtooth - Posts: 3990
1. If you want to wait intrabar for the TMS to move the stop, the only way I can think of is to do it by referencing a formula on the spreadsheet.

2. You could compare J41 with J93 or J95. You'll also need to reference J4 in your J27 formula.
Here's an example for minutes across bars instead of seconds intrabar:
Spreadsheet Example Formulas and Usage: Cancel Unfilled Working Order n Minutes After Entry

Note: Using intrabar entries instead of close of bar entries will always create difficulties and complexities.
For example:
- Arrows only show what occurred at close of bar.
- Signals that occur intrabar will not be marked by an arrow.
- Troubleshooting unexpected occurrences is much more difficult.
- Intrabar signals are always the first occurrence; you can't exclude the first occurrence and use a subsequent occurrence instead.
- Intrabar values cannot be made persistent unless they endure until close of bar.
- Intrabar entries usually require the use of J column values that are not persistent, not even intrabar in some cases.
IMO, there are plenty of disadvantages and usually no advantage to using an intrabar entry. You can often just use close-of-bar entries on a shorter timeframe chart instead.
[2020-06-20 22:45:47]
j4ytr4der_ - Posts: 918
Thanks, I had read that page and experimented with the NMinutes approach, but since the signals I'm using don't persist to the close of a bar, I couldn't get it to work at all.

I'll play around with just using a shorter timeframe and maybe have better luck. Thanks for the input!!
[2020-06-21 14:27:07]
Ackin - Posts: 1865
Aha, ok that completely explains it then.

So given that the TSM won't work for me after all... any ideas on how to accomplish what I'm looking to do? Specifically I'm playing with a Spreadsheet system and am wondering how to implement two ideas:

1. A "time trail" that adjusts say maybe 1 tick every X seconds (but of course doesn't initiate until that many seconds have passed). This way if the momentum of the trade slows down but doesn't actually reverse enough to hit a stop, I'll gradually be locking in profits/reducing risk all the time.
2. I'd like to cancel working orders if they haven't filed within X seconds. I'm playing with a signal that, when it's going to work, generally moves very quickly (I'm placing stop orders to enter, 1 tick outside current price) and if within a few seconds the trade has not filled, then I want to cancel and bail on the signal. But I can't figure out any way to track the time since a signal was given, unless the signal persists over a full bar.


what to try calculations to do on a 1 second chart and work with the result in another timeframe?

Even Acsil won't solve this for you in a larger timeframe. In general, only information about the start and end time of the Bar is stored. In the meantime, you would have to take time information from your pc or use study output such as: CountDown Timer.
[2020-06-21 14:43:28]
j4ytr4der_ - Posts: 918
Yeah I've been playing with live countdown timers in the spreadsheet, and they work for example for closing out an open position after X seconds if it's unprofitable, etc. But that doesn't help with unfilled orders since there is no record of when they were placed if they were triggered by a signal that doesn't persist to the end of the bar. At this point I'm thinking I should probably abandon this line of thinking entirely, as it's not likely to ever work well.
[2020-06-21 14:51:49]
Sawtooth - Posts: 3990
But that doesn't help with unfilled orders since there is no record of when they were placed
Not so. J93/J95 output the time a working order is placed.
[2020-06-21 15:04:43]
Ackin - Posts: 1865
Not so. J93/J95 output the time a working order is placed.

:)

nice ...

And then it should no longer be a problem to compare the time of the last bar with the above time on the micro timeframe
[2020-06-21 15:19:53]
j4ytr4der_ - Posts: 918
Oh holy hell how did I not see that??? I went looking around the Last Entry Date cells and saw nothing for orders so just figured they didn't have them. Never thought to see if they were in some totally disconnected place!!!

THANK YOU Tom!!! LOL
[2020-06-21 16:44:44]
Sawtooth - Posts: 3990
I mentioned it in post #14.
Cells J90 and below are not documented yet.
[2020-06-21 17:38:09]
j4ytr4der_ - Posts: 918
Oh that's what you were talking about! I went on memory that those cells were just some extra parameters and net P&L stuff, I didn't actually go check and you didn't name them until you did. LOL

Now I have some potential to play with. Wheeeeeeee. =)
[2020-06-21 18:20:25]
j4ytr4der_ - Posts: 918
So in the interest of closure... using J93 has made it ridiculously easy to do exactly what I wanted. I now have a simple seconds counter since my last exit order (which is my OCO) was placed, and I can simply cancel it if not filled within X seconds. Lovely!!

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

Login

Login Page - Create Account