- UID
- 2
- 积分
- 2892307
- 威望
- 1396185 布
- 龙e币
- 1496122 刀
- 在线时间
- 13313 小时
- 注册时间
- 2009-12-3
- 最后登录
- 2024-12-25
|
Portfolio Rank Signal Base(signal)- inputs:
- BasedOnData(2),
- Formula( (close - close[1]) / close ),
- TraceOutput(false);
- Vars: BarN(0), R(0);
- // *** restrictions
- once if barstatus(BasedOnData) < 0 then raiseruntimeerror("Portfolio Rank Signal Base needs datastream " + numtostr(BasedOnData, 0));
- once if 1 <> getappinfo(aiisportfoliomode) then raiseruntimeerror("Portfolio Rank Signal Base can be applied to MCPortfolio application only.");
- // ****************
- once pmm_set_global_named_str("RankStrategyApplied", "true");
- BarN = BarNumber of data(BasedOnData);
- if BarN > BarN[1] then begin
- R = Formula of data(BasedOnData);
- pmm_set_my_named_num("RankStrategyR", R);
- end;
- if (TraceOutput) then begin
- print("CurrentBar = ", currentbar:0:0, ". Put MyIndicator value = ", R:0:5, " for symbol ", symbolname, ".");
- end;
- // *** Money management
- begin
- var: MoneyCostForInvestPerCtrct(0), potential_entry_price(close);
- MoneyCostForInvestPerCtrct =
- pmms_calc_money_cost_for_entry_per_cntrct(potential_entry_price, Portfolio_GetMarginPerContract)
- +
- pmms_calc_money_cost_for_entry_per_cntrct(potential_entry_price, Portfolio_GetMaxPotentialLossPerContract);
-
- if 0 > MoneyCostForInvestPerCtrct then
- raiseruntimeerror( text("Error! Price = ", potential_entry_price:0:6, "PMargin = ", Portfolio_GetMarginPerContract, "PMaxPLoss = ", Portfolio_GetMarginPerContract) );
-
- // MoneyCostForInvestPerCtrct in currency of the symbol. Convert it to portfolio currency ...
- pmm_set_my_named_num("MoneyCostForInvestPerCtrct", pmms_to_portfolio_currency(MoneyCostForInvestPerCtrct));
- end;
- // ********************
- buy next bar market;
- sellshort next bar market;
复制代码 Portfolio Rank MM Signal(信号)- inputs:
- ContractsNumber(200),
- IgnoreContractsNumberUsePcnt(false),
- PortfolioBalancePercent(1),
- StdDevLength(14),
- BuyBestN(10),
- SellWorseN(10),
- TraceOutput(false);
- variables: AvgReturn(0), SDev(0), portfolioStrategies(0), idx(0), strIdx(0), lots(0);
- array: BaseR[](0), ContractsForEntry[](0), Value_Idx[2, 10000](0);
- // *** restrictions
- once if 1 <> getappinfo(aiisportfoliomode) then raiseruntimeerror("Portfolio Rank Money Management Signal can be applied for MCPortfolio application only.");
- //once if "true" <> pmm_get_global_named_str("RankStrategyApplied") then raiseruntimeerror("Portfolio Rank Monem Management Signal can be applied in pair with Portfolio Rank Signal Base only.");
- once if pmms_strategies_count() > 10000 then raiseruntimeerror("Portfolio Rank Money Management Signal too much intruments, max value = " + numtostr(100000, 0));
- once if pmms_strategies_count() < BuyBestN + SellWorseN then raiseruntimeerror("Portfolio Rank Monem Management Signal, please check inputs, BuyBestN + SellWorseN should be less or equal to tradable Instruments number");
- // ****************
- once begin
- portfolioStrategies = pmms_strategies_count();
- array_setmaxindex(BaseR, portfolioStrategies);
- array_setmaxindex(ContractsForEntry, portfolioStrategies);
- end;
- pmms_strategies_deny_entries_all;
- AvgReturn = 0;
- for idx = 0 to portfolioStrategies - 1 begin
- BaseR[idx] = pmms_get_strategy_named_num(idx, "RankStrategyR");
- AvgReturn += BaseR[idx];
- end;
- AvgReturn /= portfolioStrategies;
- SDev = StandardDev(AvgReturn, StdDevLength, 1);
- if (SDev = 0) then SDev = 1;
- for idx = 0 to portfolioStrategies - 1 begin
- Value_Idx[1, idx + 1] = ( BaseR[idx] - AvgReturn ) / SDev;
- Value_Idx[2, idx + 1] = idx;
- if IgnoreContractsNumberUsePcnt then begin
- ContractsForEntry[idx] = pmms_calc_contracts_for_entry(PortfolioBalancePercent, idx);
- end
- else
- ContractsForEntry[idx] = ContractsNumber;
- end;
- Sort2DArray(Value_Idx, 2, portfolioStrategies, -1 {from low to high});
- variables: inLong(0), inShort(0);
- array: strategyIndexes[](0);
- inLong = pmms_strategies_in_long_count(strategyIndexes);
- for idx = 1 to BuyBestN - inLong begin
- strIdx = Value_Idx[2, idx];
- pmms_strategy_set_entry_contracts(strIdx, ContractsForEntry[strIdx]);
- pmms_strategy_allow_long_entries(strIdx);
- if TraceOutput then
- print("CurrentBar = ", currentbar:0:0, ". Allow LONG for symbol ", pmms_strategy_symbol(strIdx), ", Contracts = ", ContractsForEntry[strIdx]);
- end;
- inShort = pmms_strategies_in_short_count(strategyIndexes);
- for idx = portfolioStrategies downto portfolioStrategies - SellWorseN + inShort + 1 begin
- strIdx = Value_Idx[2, idx];
- pmms_strategy_set_entry_contracts(strIdx, ContractsForEntry[strIdx]);
- pmms_strategy_allow_short_entries(strIdx);
- if TraceOutput then
- print("CurrentBar = ", currentbar:0:0, ". Allow SHORT for symbol ", pmms_strategy_symbol(strIdx), ", Contracts = ", ContractsForEntry[strIdx]);
- end;
复制代码 |
|