The code I am sharing below overcomes this limitation. This how it works:
* the trading signal always emits buy and sell orders
* the portfolio signal enables and disables these orders and adjusts the entry size as required
In order for this to work, the following is required:
* the trading signal must set [SameExitFromOneEntryOnce = false]
* in portfolio trader, set 'allow up to xxx entry orders in the same direction' to a ridiculously high value
The code I am providing keeps the money invested per strategy close to $10k. You will sure have better ideas what to do here.
Hope this helps,
best regards, Felix
Trading signal:
Code: Select all
[SameExitFromOneEntryOnce = false]
buy 1 share next bar at market;
sell 1 share total next bar at market;
pmm_set_my_named_num("STRATEGY_POS", {marketposition *} currentcontracts);
pmm_set_my_named_num("STRATEGY_PRICE", close);
Code: Select all
once ClearPrintLog;
var: idx(0);
for idx = 0 to pmms_strategies_count - 1 begin
var: pos(0);
pos = pmms_get_strategy_named_num(idx, "STRATEGY_POS");
var: price(0);
price = pmms_get_strategy_named_num(idx, "STRATEGY_PRICE");
var: net(0);
net = pos * price;
var: delta(0);
delta = IntPortion((10000 - net) / price);
print(ELDateToString(date),
" ", pmms_strategy_symbol(idx),
", pos = ", pos,
", price = ", price,
", net = ", net,
", delta = ", delta);
if delta > 0 then begin
pmms_strategy_deny_exit_from_long(idx);
pmms_strategy_allow_long_entries(idx);
pmms_strategy_set_entry_contracts(idx, delta);
end else if delta < 0 then begin
pmms_strategy_deny_long_entries(idx);
pmms_strategy_allow_exit_from_long(idx);
pmms_strategy_set_entry_contracts(idx, -delta);
end else begin
pmms_strategy_deny_long_entries(idx);
pmms_strategy_deny_exit_from_long(idx);
end;
end;