Login Page - Create Account

Support Board


Date/Time: Sat, 04 May 2024 04:13:26 +0000



[User Discussion] - Multiple Positions Entry and Exit

View Count: 2356

[2018-05-10 15:46:41]
User172040 - Posts: 70
I'm testing SC multiple entries and exits in the spreadsheet study. K column is a simple MA crossover trigger (=CROSSFROMBELOW(ID3.SG1@3:ID3.SG1@4,ID3.SG2@3:ID3.SG2@4)) and exit is an exact replica from SC at this link - Spreadsheet Systems, Alerts and Automated Trading: Multiple Exit Automated Trading Example

Order Quantity Formula (Cell J26): =IF( ABS(J8) = 5, 2, IF( ABS(J8) = 3, 3, 0)).

Buy Exit Formula (Cell L3): =OR( AND( $J$8 = 5, ID0.SG4@$3 - $J$9 > 3), AND( $J$8 = 3, ID0.SG4@$3 - $J$9 > 5))

So I have these formulas in my J26 and L3. Problem is, I thought entry would be 5 contracts and exit at 10 points would be 2 contracts off and the last 3 off at 20 points profit.

If 'Allow Multiple Entries in the Same Direction' = No then only 1 contract is triggered at the beginning of the backtest period with no exit.

If 'Allow Multiple Entries in the Same Direction' = Yes then multiple 1 contracts are triggered with no exits.

Can someone please help?
[2018-05-10 16:17:39]
Sawtooth - Posts: 3993
Both entries and exits will use J26 for the order quantity. (Unless J82/J83 is used).

Your J26 formula does not return a quantity for entries. (A J26 of zero will default to 1). Try this:
=IF( ABS(J8) = 5, 2, IF( ABS(J8) = 3, 3, 5))

Your L3 formula is triggering at 3 points and 5 points, not 10 and 20. Try this:
=OR( AND( $J$8 = 5, E$3 - $J$9 > 10), AND( $J$8 = 3, E$3 - $J$9 > 20))

Set 'Allow Multiple Entries in the Same Direction' = No.
Date Time Of Last Edit: 2018-05-10 17:55:01
[2018-05-10 18:07:20]
User172040 - Posts: 70
Thank you tomgilb. Learning a lot from you.

So my Buy Exit only triggers when a profit target is hit. I added 2 stops. I want my whole position closed when price = -10 points from my avg entry price. I added the following to the end of the formulae (italics):

=OR( AND( $J$8 = 5, E3 - $J$9 > 10), AND( $J$8 = 3, E3 - $J$9 > 20), AND($J$8 = 5, E3 - $J$9 < -10), AND($J$8 = 3, E3 - $J$9 < -10))

But my stop exists are weird. Although I specify 10 point loss max, my backtest stops 2 out at +- 13 point loss and the other 3 at a 15 or 16 point loss. Any ideas?

Lastly, do you know of code examples where my stops move to breakeven + 2 ticks when price moves in my favor?
[2018-05-10 22:32:05]
Sawtooth - Posts: 3993
Your J26 formula doesn't specify a quantity when you want to flatten.
Instead of creating a more complex J26 formula, I would use J29 to flatten:
=OR(AND(J8>0,$J$9-E3>=10),AND(J8<0,E3-$J$9>=10))
and use the original L3:
=OR( AND( $J$8 = 5, E$3 - $J$9 > 10), AND( $J$8 = 3, E$3 - $J$9 > 20))

Actually, I prefer to use Attached Orders to handle targets and stops, if they are not a calculated level.
You can create a Trade Window configuration that will do what you want, then check 'Use Attached Orders'. Much easier. J26 only needs to be for entries, and L3/N3, J29 are empty.
[2018-05-11 14:44:42]
@sstfrederik - Posts: 403
You can also try out the autotrading study I just released.

New autotrading study released

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

Login

Login Page - Create Account