Yet another post about RiskStopLevel
Author: Bionian
Creation Date: 1/14/2010 6:07 PM
profile picture

Bionian

#1
While I think I understand what SetRiskSTopLevel does, I am confused about how to insert it into script. I have studied the User Guide under Reference > Data Panel > Position Size Control > Portfolio Simulation Mode. I have also read the RiskStopLevel Property in the Quick Ref guide. I have also read posts on the topic, but most are from previous version of Wealth Lab. Please help me understand by example.

The following script sets a stop-loss at 6% below the purchase price. Where in the script would I placde the SetRiskStopLevel property, and what would the syntax be to set the RiskStopLevel at 6% below the purchase price?

Thanks.

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

Eugene

#2
First off, your strategy contains a serious error -- it's peeking into the future:
CODE:
Please log in to see this code.

Without a time machine or a good crystal ball, you can not build a series based on the daily close and sell at open this day. Re-read the Wealth-Lab Knowledge Base: Introductory | Bars, Loops, and Bar + 1, and then, the WealthScript Programming Guide > Programming Trading Strategies > Peeking.

Next stop: GetTradingLoopStartBar(51). Take a look at the Programming Guide > Indicators > Stability of indicators. Notice what was changed in your strategy to account for the EMA's instability.

Now, to RiskStopLevel. Like in real life, for AtMarket orders you don't know the exact price of order execution. Consequently, you need to set the RiskStopLevel at the basis price (i.e. Close[bar]) - 6%, and then enter a stop order at Position.EntryPrice - 6% to actually use the established stop level as an exit.

Corrected code follows:
CODE:
Please log in to see this code.

For backtesting purposes though, "peeking" at Bars.Open[bar+1] is also valid:
CODE:
Please log in to see this code.
profile picture

Bionian

#3
Thanks for the information, Eugene.

QUOTE:
Without a time machine or a good crystal ball, you can not build a series based on the daily close and sell at open this day.


I am aware of this limitation, but this was discussed in another post about this same strategy. Actually, the strategy is to enter a limit order to sell upon the price crossing the upper band. Since I cannot backtest that strategy as such, I decided to sell at the open of the day in which the price later crosses the upper band would be a better estimate than to sell at the open at bar+1, in which case the price could gap higher or lower at the open. Since the opening price on that day will always be lower than the limit price which will be reached later that day, I felt that, while the strategy is impractical as written, since I cannot set a limit price in backtesting as I would in a live trade, this would be the closest and most conservative work-around for that limitation. Let me know if I am totally missing something in that assumption.

QUOTE:
Notice what was changed in your strategy to account for the EMA's instability.


I'll have to look at the EMA stability. As I understand it, an EMA has to have a sufficient amount of back data, in this case, about 150 days' data, in order to make the EMA meaningful. This may necesitate my creating a future post for clarification.

Also, thanks for your explanation regarding the RiskStopLevel. Since I have had little programming experience, and no experience with an object-based language, getting the syntax right has been a matter of typing the code into the program and trying to understand the language while doing so.

-Rick
profile picture

Eugene

#4
QUOTE:
this would be the closest and most conservative work-around for that limitation.

This is an interesting Q&D workaround w/o having to reverse-engineer the Bands.

Clearly, we need to translate and add gbeltrame's RevEngBBandLowerCross and RevEngBBandUpperCross indicators to TASCIndicators. Let's mark this thread for later.