I've noticed with some backtests that look good that my strategy is buying more than 56,000 shares on shares that may only have an average daily volume of 100,000 shares. That won't work in the real world as my trade will obviously affect the price. I'd like to put some code in my strategy to prevent the maximum number of shares from exceeding 1/100th of the daily volume (or possibly even less).
It appears the only way I can override the share size is by controlling it in my strategy and backtesting with Position Sizing set to "Wealthscript Override". I'd like to be able to set a maximum with Position Sizing set to "Percent of Equity" or "Fixed Dollar". Is there any way to do this?
At the momment I'm just excluding securities that have a price below a certain value and average volume since those are the ones that I'm trying purchase with large share sizes.
Size:
Color:
Yes, enabling "Reduce Quantity based on Volume" in Preferences > Backtest Settings should work.
Size:
Color:
Thanks Eugene! That should help some.
The preferences feature uses the current bar's volume which would be the volume in 1 minute for a Scale of 1 minute. I actually wanted to code it based on the average daily volume. Is there any way for me to control the maximum number of shares in my strategy code without actually overriding the size?
From my experimenting, it appears the following code may work; however 'LastPosition.OverrideShareSize' appears to be undocumented:
CODE:
Please log in to see this code.
Size:
Color:
OverrideShareSize is an undocumented function which, as we believe, is used by SetShareSize internally.
You'll be able to mix your intraday trade size limit logic with "Pct of Equity" sizing once Version 5.6 brings the support for PosSizers (aka $imuScripts).
Size:
Color:
Any chance this will become a documented feature as my test shows this does exactly what I want?
Size:
Color:
Why? The code is equivalent to using SetShareSize before BuyAtMarket, and should not work unless Override is on.
Size:
Color:
I thought OverrideShareSize was working even when Position Sizing was set to something other than "Wealthscript Override", but now I'm getting different results during my testing. I may have commented too soon.
I'll wait to see what 5.6 has to offer with the PosSizers. Until then I'll try the "Reduce Quantity based on Volume" in Preferences > Backtest Settings that you suggested.
Thanks.
Size:
Color: