How to set RiskStopLevel?
Author: brodie900
Creation Date: 3/12/2015 12:31 AM
profile picture

brodie900

#1
HI all! please bear with me as I'm completely new to wealthlab and I'm still spending time getting to know how it and its community work.

I'm having trouble understanding how to set a risk stop level so that I can use the max percent risk position sizing.

I want to size my positions so that 1% equity = the difference between the 24 EMA value below the signal bar and the buy price at open on the next bar.
obviously my stop would be set at what ever the 24 EMA value is below the signal bar too.

Have I under stood this correctly? is this possible?

everything else I can do with the rules based strategy builder as below and I'm so close to having a complete trading plan!

also what books or resources would you recommend for a beginner to learn how to program wealthscript? I have some experience with metastock code but that doesn't seem to help much here



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

Eugene

#2
Welcome to the forums.

QUOTE:
I want to size my positions so that 1% equity = the difference between the 24 EMA value below the signal bar and the buy price at open on the next bar.

Hmm, the buy price at open on the next bar slightly complicates things. Without it (here I mean by relying on the current bar), the example code would be more terse and intuitive.

For backtesting that wouldn't be an issue but for Alert generation, accessing Open[bar+1] might raise an error. Code below solves it with GetSessionOpen. Mostly all data providers support GetSessionOpen but there are exceptions.

Now, select "Max Percent Risk" from the Position Size dialog to utilize RiskStopLevel:

CODE:
Please log in to see this code.


QUOTE:
obviously my stop would be set at what ever the 24 EMA value is below the signal bar too.

I could be wrong but you're probably overlooking a scenario where the open is above the MA due to a gap.

QUOTE:
also what books or resources would you recommend for a beginner to learn how to program wealthscript? I have some experience with metastock code but that doesn't seem to help much here

Indeed, Metastock way of coding is completely different. You'll find it answered here as "How do I start with C# ?" (and eventually, even "How to program MetaStock's PREV function in Wealth-Lab?"):

FAQ | Strategies and WealthScript
profile picture

brodie900

#3
Thank you for the fast reply Eugene your support is fantastic mate!


QUOTE:

Hmm, the buy price at open on the next bar slightly complicates things. Without it (here I mean by relying on the current bar), the example code would be more terse and intuitive.

For backtesting that wouldn't be an issue but for Alert generation, accessing Open[bar+1] might raise an error. Code below solves it with GetSessionOpen. Mostly all data providers support GetSessionOpen but there are exceptions.


I only need this formula for back testing, no need for it to generate any alerts. Does that simplify things a little?


QUOTE:
I could be wrong but you're probably overlooking a scenario where the open is above the MA due to a gap.


I think we might have our wires crossed a little here as the buy price on the following bar should nearly always be above its 24EMA especially if the stock price is trending up. if it gaps down far enough to be on the other side of the MA however it should give a sell signal and I wouldn't make the trade in the first place.

I have attached a screen shot to help explain how I want to position size I hope it makes sense!
profile picture

Eugene

#4
Brodie,

Glad to have helped. For backtesting only (it will stop processing at the penultimate bar), the script without the complication might look like this:

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

brodie900

#5
Ok I tried running that exact code but I get the error "strategy must set RiskStopLevel in order to use maximum risk position size"

is there anything else I might be missing here?
profile picture

Eugene

#6
Yes. Select "Max Percent Risk" from the Position Size dialog to utilize RiskStopLevel.
profile picture

brodie900

#7
It was already selected and set at 1%, any other possible beginner mistakes?
profile picture

Eugene

#8
You're right. I've nailed down the problem to the usage of external symbol data in RiskStopLevel. On some symbols it works and with others that error message is thrown - namely when their price is less than the price of XAO. This leads me to question: do you really base your RiskStopLevel on the external symbol's data (XAO)? It makes little sense to me. If it's an error, replace one line of code:

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

brodie900

#9
Ah I see!

QUOTE:
do you really base your RiskStopLevel on the external symbol's data (XAO)?


No, I only use XAO as a bull/bear filter, only buying when XAO 6EMA is above 24EMA and tightening exits when 6 is below 24
profile picture

brodie900

#10
Does this make any sense?
profile picture

Eugene

#11
I'm fine with whatever works for you. Like I said, it takes a one-line replacement to get rid of the error message.
profile picture

brodie900

#12
ok mate,
thank you so much for your help Eugene!
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).