699
edits
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
Portfolio Trader Strategy Examples for regular MultiCharts (PowerLanguage) can be downloaded '''[https://dl.dropboxusercontent.com/u/95112551/Portfolio%20RT%20Manual.%20Examples.pdf here]''' | Portfolio Trader Strategy Examples for regular MultiCharts (PowerLanguage) can be downloaded '''[https://dl.dropboxusercontent.com/u/95112551/Portfolio%20RT%20Manual.%20Examples.pdf here]''' | ||
== Rotation Strategy == | |||
This strategy was suggested by '''kbeary33''' on MultiCharts Forum (http://www.multicharts.com/discussion/viewtopic.php?f=19&t=45413). | |||
=== Strategy Description === | |||
'''Rotation Strategy''' is a simple strategy that calculates a specific indicator by using every instrument in the portfolio. Positions are opened for those instruments which have the best indicator value(s). | |||
Take for example the '''% Change''' indicator. This set of instruments is determined by the user in the Portfolio Trading application. The number of instruments to enter a Long position is configured by the '''BuyBestX''' input. Standard stop loss +profit target strategy is used to exit positions. | |||
=== Strategy Development === | |||
==== Portfolio_Rotation Signal ==== | |||
This signal generates entry orders and calculates indicator values for all instruments in the portfolio. | |||
Indicator formula is entered into the input field and it is calculated on every bar. | |||
<syntaxhighlight>inputs: | |||
Formula (PercentChange(close, 14)); | |||
variables: formulaValue(0); | |||
formulaValue = Formula;</syntaxhighlight> | |||
To further compare and decide to enter the position, the formula is then entered into global variables: | |||
<syntaxhighlight>pmm_set_my_named_num ("RotationalValue", formulaValue);</syntaxhighlight> | |||
Entries for all instruments are generated: | |||
<syntaxhighlight>buy("LE") next bar market; | |||
sellshort("SE") next bar market;</syntaxhighlight> | |||
To manage the capital, standard Portfolio settings '''Margin per Contract''' and '''Potential Loss per Contract''' set by the user will be used: | |||
<syntaxhighlight>pmm_set_my_named_num("MoneyCostForInvestPerCtrct", pmms_to_portfolio_currency(MoneyCostForInvestPerCtrct));</syntaxhighlight> | |||
<syntaxhighlight>var: PotentialEntryPrice(close), MoneyCostForInvestPerCtrct(0); | |||
if (entryprice > 0) then PotentialEntryPrice = entryprice; | |||
MoneyCostForInvestPerCtrct = | |||
pmms_calc_money_cost_for_entry_per_cntrct(PotentialEntryPrice, Portfolio_GetMarginPerContract) | |||
+ | |||
pmms_calc_money_cost_for_entry_per_cntrct(PotentialEntryPrice, Portfolio_GetMaxPotentialLossPerContract);</syntaxhighlight> | |||
When one lot price value is calculated, this value will be converted into portfolio currency and written into portfolio global variables. | |||
<syntaxhighlight>pmm_set_my_named_num("MoneyCostForInvestPerCtrct", pmms_to_portfolio_currency(MoneyCostForInvestPerCtrct));</syntaxhighlight> | |||
Standard Stop Loss and Profit Target set in percent from portfolio capital will be used for exit. | |||
<syntaxhighlight>inputs: StopLossPcntsOfPortfolio(0.1), | |||
ProfitTargetPcntsOfPortfolio(0.1); | |||
variable: value(0); | |||
setstopposition; | |||
value = StopLossPcntsOfPortfolio * 0.01 * Portfolio_Equity; | |||
setstoploss(convert_currency(datetime[0], portfolio_CurrencyCode, SymbolCurrencyCode, value)); | |||
value = ProfitTargetPcntsOfPortfolio * 0.01 * Portfolio_Equity; | |||
setprofittarget(convert_currency(datetime[0], portfolio_CurrencyCode, SymbolCurrencyCode, value));</syntaxhighlight> | |||
==== Portfolio_Rotation_MM Signal ==== | |||
The signal is used as a '''Money management signal''' in portfolio. This study verifies the indicator values for all the portfolio instruments and manages positions opening. | |||
The number of portfolio instruments for which positions will be opened is set by the user: | |||
<syntaxhighlight>inputs: | |||
BuyBestX(10), | |||
SellWorstY(10);</syntaxhighlight> | |||
Indicator values will be extracted for all the strategies and a sorted list of values at every calculation will be created. To do so, we will need to use 2-dimensional array of the indicator values and the strategy indexes: | |||
<syntaxhighlight>variables: idx(0), strategyIdx(0), strategyValue(0); | |||
arrays: allStrategies[10000, 1](-1);</syntaxhighlight> | |||
Entry orders generation before every calculation is denied: | |||
<syntaxhighlight>pmms_strategies_deny_entries_all;</syntaxhighlight> | |||
Fill the array with the indicator values and the index for each strategy and then we will sort out the array by values: | |||
<syntaxhighlight>for strategyIdx = 0 to pmms_strategies_count - 1 begin | |||
strategyValue = pmms_get_strategy_named_num(strategyIdx, "RotationalValue"); | |||
allStrategies[strategyIdx , 0] = strategyValue; | |||
allStrategies[strategyIdx , 1] = strategyIdx; | |||
end; | |||
Sort2DArrayByKey(allStrategies, pmms_strategies_count, 1);</syntaxhighlight> | |||
Let’s count the number of strategies that are now in position. According to the best indicator indexes '''BuyBestX''' instruments should have Long position and '''SellWorstY''' instruments should have Short position: | |||
<syntaxhighlight>variables: inLong(0), inShort(0); | |||
arrays: strategiesLong[](-1), strategiesShort[](-1); | |||
inLong = pmms_strategies_in_long_count(strategiesLong); | |||
inShort = pmms_strategies_in_short_count(strategiesShort);</syntaxhighlight> | |||
In calculation we cycle through those strategies that should have Long position according to the indicator indexes (wherein, if the strategy is already in position, we track it in '''strategiesLong''' array): | |||
<syntaxhighlight>for idx = 0 to BuyBestX - 1 begin | |||
cur_idx = allStrategies[idx, 1]; | |||
if (not array_contains(strategiesLong, cur_idx)) then | |||
pmms_strategy_allow_long_entries(cur_idx) | |||
else | |||
strategiesLong[array_indexof(strategiesLong, cur_idx)] = -1; | |||
if UsePortfolioMoneyPcnt then | |||
pmms_strategy_set_entry_contracts( | |||
cur_idx, | |||
pmms_calc_contracts_for_entry( PortfolioMoneyPcntForEntry, cur_idx ) | |||
); | |||
End;</syntaxhighlight> | |||
Strategies which are in position, but are not among the best according to the indicator indexes are forced to close: | |||
<syntaxhighlight>for idx = 0 to inLong - 1 begin | |||
value1 = strategiesLong[idx]; | |||
if value1 >= 0 then begin | |||
pmms_strategy_close_position(value1); | |||
end; | |||
end;</syntaxhighlight> | |||
Strategies for Short entry are processed likewise. | |||