I enhanced the Dynamic Position Sizing object to support 4 different rebalance modes - based on StdDev (current), 1/StdDev (inverse volatility), Sharpe Ratio, Sq-rt(StdDev).
Below is the code I added. The code compiles with no errors when in the Money Mgmt Compile menu .. but when i backtest, it throws a compilation error - "OnEndPeriod : Compilation error in 'OnEndPeriod':
Specified cast is not valid."
It seems to choke on this line below, as it cant cast the GetVariable object to int
int rebalance_mode = (int)Variables.GetVariable("rebalance_mode");
How do i convert this object to int?
Also, once i get this working, how do i submit this package to the community?
There's another issue i'm running into - i need to calculate relative strength of Close/SPY, but the script gets confused with the extra "" in "SPY" within the formula. How do i escape the "" within the formula?
Escace using "\" or better use single quotes inside the "ParseFormula".
ts = Data.ParseFormula("a=Sma(close/GetSeries('SPY',close,LastData),20);").GetTimeSeries(pos.Symbol, "a");
Trading financial instruments, including foreign exchange on margin, carries a high level of risk and is not suitable for all investors. The high degree of leverage can work against you as well as for you. Before deciding to invest in financial instruments or foreign exchange you should carefully consider your investment objectives, level of experience, and risk appetite. The possibility exists that you could sustain a loss of some or all of your initial investment and therefore you should not invest money that you cannot afford to lose. You should be aware of all the risks associated with trading and seek advice from an independent financial advisor if you have any doubts.