Hello,
Can someone fix this strategy to where it will buy or go short on the close of a second consecutive bar that closes above or below the specified SMA series? I am totally new to this and have no programming experience. This is a rule based strategy that I converted to code. Thanks is advance.
CODE:
Please log in to see this code.
Size:
Color:
CODE:
Please log in to see this code.
Size:
Color:
Thank you very much Eugene!
Size:
Color:
For Eugene or anyone else that wants to take a stab at this, how would i go about adding a "Midline" series. This moving average would be the mid point of the current SMA high and SMA low in this code. Basically its (maH + maL) /2. After that is plotted, I would like to change my exits to when the bar closes below this midpoint line instead of using the maH or maL lines. Thanks in advance.
Size:
Color:
Add this new line right after the "
DataSeries maL...":
CODE:
Please log in to see this code.
Then, refer to
mid in the code above instead of maH/maL.
Size:
Color:
I could have sworn I tried this yesterday and got errors, but now it works! Oh well, that's what counts! Thanks again Eugene!
Size:
Color:
You're welcome. The errors in this case could have been caused by failing to append "[bar]" where needed (e.g. Close[bar] < mid - error) and/or referring to a value of the series at a bar where the program doesn't expect it (e.g. CrossOver( bar, Close, mid[bar] - error).
Size:
Color:
Eugene, I would like to implement Position sizing based on Volatility to this strategy (for futures). How would I go about doing this with this code? When I go to portfolio simulation mode and Position Sizer I get an error "Strategy code must set RiskStopLevel in order to use Maximum Risk position size". I've done a lot of searching in these forums and the user guide and found references to this but my lack of programing knowledge stops me from even knowing where to begin coding this.
Size:
Color:
Look up
RiskStopLevel in the QuickRef (hit F11) for a code snippet showing how to add a stop level to your Strategy. For example, in your code above a 5% RiskStopLevel would translate to:
CODE:
Please log in to see this code.
Percent volatility position sizing is implemented in our upcoming PosSizer pack.
Size:
Color:
If I were to add this in my dataseries,
CODE:
Please log in to see this code.
Can I use the ATR to set my stop level? for example:
CODE:
Please log in to see this code.
I seem to get an error when i do this..
Size:
Color:
This syntax is incorrect.
See DataSeries > Accessing a Single Value from a DataSeries in the WealthScript Programming Guide.
Size:
Color:
After looking this up like you suggested I changed it to the following:
CODE:
Please log in to see this code.
Can you explain to me though what this line is doing? Is it saying that it is setting the risk to 2.5 times the ATR of that given commodity?
Size:
Color:
Sorry, but this line doesn't make sense.
My line above (e.g.
Close[bar] * 0.95) was setting the risk stop level to 5% past the security's closing price.
To make sense, correct your line to subtract (for long positions) or add (for short) 2.5 * current ATR from the closing price - vs. multiplying:
CODE:
Please log in to see this code.
Size:
Color:
Thank you
Size:
Color:
I must not be applying what you wrote correctly. Wealth Lab is understanding it but its not doing exactly what I thought it would do. I would like to risk a specific amount (ie 2% of $100,000 = $2,000) per trade. I would like to buy as many contracts risking a specific multiplier of that commodities ATR. (ie if Sugar's ATR is .5 over the last 5 days, and my risk is set @ $1,500. it would give me a 2 lot for that volatility). Here is the code:
CODE:
Please log in to see this code.
Using this code, it wants to buy 16 contracts of Sugar at this time when i only want to risk $2000.
Size:
Color:
Have you enabled Futures mode in Symbol Info Manager?
Size:
Color:
RiskStopLevel is the level at which if you exit the trade you will lose the amount risked. (The amount can be more if prices gap through that level.) Consequently, the number of contracts depends on the the difference between the entry price, the RiskStopLevel, and the contract's Point value; it doesn't have anything directly to do with the value of ATR except in the setting of the RiskStopLevel.
See the User Guide for an example, see the QuickRef for an example, and make sure that you have a statement in your exit logic to exit at a StopLoss at the Position p's p.RiskStopLevel. If you do, then you should see that your loss is approximately 2% of your equity at that time.
Size:
Color:
Yes Futures mode is enabled. To be a little more clear, all I want to do is for Wealth Lab to tell me how many contracts I should be buying based on the amount I want to risk. I want it to do it by taking into consideration the volatility (ATR) of the given commodity. I do not want to set any stoploss in my code. My exits are already defined.
Size:
Color:
Once we release the Percent Volatility PosSizer, which dialog box you can see below, this will be a breeze:
You can create a support ticket now to request our PosSizer pack.
Size:
Color:
I have created the ticket. When will this be available?
Size:
Color:
Once I finish testing and debugging it which may happen this month.
Size:
Color:
Eugene,
Understood about being a current customer in order to receive new Posizer Pack. I have another question though. If I were to use the WealthScript overide radio button and include "SetShareSize" in the code, would I be able to achieve what I am looking to do? For example:
CODE:
Please log in to see this code.
Size:
Color:
No.
Size:
Color:
Ok, thanks for all your help.
Size:
Color: