SellatMarket and SellatStop in the same script
Author: topcat77
Creation Date: 2/16/2009 6:58 PM
profile picture

topcat77

#1

This momentum strategy exits once any one of a set of technical objectives
have been met. All of these exits are SellatMarket.

I would like to install an additional defensive exit condition which is to create a stop-at-entry-price after a trigger point gain has been achieved
(for example, if the price gains 2% from entry-price then establish a stop at entry-price). I have used the trailing-stop function for this before; however this would be a SellatStop exit.

I do not know how to script two sets of exits - one SellatLimit, the other Sellat TrailingStop - to work together

Help or direction would be v useful

CODE:
Please log in to see this code.


profile picture

Eugene

#2
Note that it's incorrect to start the main loop at bar #16: even Bollinger Bands period is 20 bars, and the RSI is an 'unstable' indicator. Therefore the trading loop here starts at three times RSI lookback period:
CODE:
Please log in to see this code.
profile picture

topcat77

#3

V helpful (and elegant)
Thank you
profile picture

topcat77

#4
Eugene

Looking at this in action it seems that NetProfitAsOfBarPercent uses
an observation at the close of a bar to trigger the Breakeven Stop.
I have searched in Wiki and in Advanced Searches (two entries) to find how it
may be possible for the function to use bar-highs instead - that is to use the
MFE for the position(so, for example, if NetProfitAsOfBarPercent occurred at the High for a bar
but not at its close, this would trigger the b/e stop)

The compiler does not like my (simple) attempts eg to go
NetProfitAsOfBarPercent(Close[bar]). What would be the right way to go about this?
profile picture

Cone

#5
Change p.NetProfitAsOfBarPercent(bar) to p.MFEAsOfBarPercent(bar).