Same Bar Exits
Author: topcat77
Creation Date: 10/7/2008 3:16 PM
profile picture

topcat77

#1

My program trades off 1 min bars; for Exits the script uses Bracketed Exits with trailing stops. In general autotrading this configuration has held up well through the entertainment of the past week EXCEPT for instances where same bar exits are necessary for either Limit, stop loss or Trailing stop triggers.

The Quick reference guide points to the use of AutoProfitlevel and RiskStopLevel values to allow same bar exits. Questions:i) can these be used with bracketed stops and to engage the trailing stop trigger ii) where in the script should I insert the code for these values?

Help much appreciated
profile picture

Cone

#2
First, for same-bar exits, you must enable that option in the Trading Preferences (F12).

While you've got the Preferences dialog open, strike F1 for the Help. Click on the the "Trading" Preferences topic and see the instructions for use of that option. Of course, the QuickRef has examples for these functions too.
profile picture

topcat77

#3

Cone

thank you; I had done all of that before I wrote to the community site.
The topic reference does not make clear whether trailing stop triggers can be engaged with this option (properly coded); will they be?

Most importantly I am not confident, even after studying the two guides,
that I know where in the script I should insert the two values or whether/how the rest of the script would need editing for this

this is an example of the script that I would like to upgrade for same-bar exit functionality:


CODE:
Please log in to see this code.


would appreciate you pointing me in the right direction
thanks

profile picture

Cone

#4
QUOTE:
The topic reference does not make clear whether trailing stop triggers can be engaged with this option (properly coded); will they be?
No. The option has nothing to do with trailing stops. It only deals with limit target stop loss values set by AutoProfitlevel and RiskStopLevel, respectively, on the trade's entry bar.

QUOTE:
Most importantly I am not confident, even after studying the two guides, that I know where in the script I should insert the two values
Clear, concise examples are in the QuickRef. Call the method(s) before the BuyAtMarket signal.

CODE:
Please log in to see this code.
profile picture

topcat77

#5

ok
QuickRef makes two inserts, so if I follow that method:

1) the line:

CODE:
Please log in to see this code.


would include . . . . .,p,RiskStopLevel,"Stop Loss" )

and, equally, the SellAtLimit line would change to:

SellAtLimit(bar+1,p,AutoprofitLevel,ProfitTgt,"profit Target")

is this correct ? (it seems to include one more term than in the example but
I'm reasoning that this is called for)

AND

2)the final segment of the code would read:

RiskStopLevel=(Bar.Close[bar]*(1-0.50/100 d))
AutoProfitLevel=(Bar.Close[bar]*(1+0.41/100 d))
BuyatMarket etc etc

I am working my way to understanding code for scripts so it would be helpful
to know if this is all correct and, if not, what needs changing



profile picture

Eugene

#6
QUOTE:
and, equally, the SellAtLimit line would change to:

SellAtLimit(bar+1,p,AutoprofitLevel,ProfitTgt,"profit Target")

It would become:

SellAtLimit(bar+1,p,AutoprofitLevel,"profit Target")
QUOTE:
2)the final segment of the code would read:


Yes.
profile picture

topcat77

#7
grateful
WL is brilliant once you can figure your way around;
another small step here
profile picture

Cone

#8
If you're sure that your Strategy is trading only one Position, you can use the "global" values for AutoProfitLevel and RiskStopLevel in your exit logic. However, it would be much better to use the Position-based values, e.g.,
CODE:
Please log in to see this code.
Note! You do not need to add this signal in your exit logic unless you want to exit at the AutoProfitLevel after the entry bar. On the other hand, if you use Max Risk sizing, you must program an exit for RiskStopLevel because the sizing strategy depends on the exit at the price you determined would be the maximum risk.


In your second snippet -
CODE:
Please log in to see this code.
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).