I'm testing out a knife juggler variation and it is opening too many positions using IB paper trading. It is set to 10% position sizing with 1.0 margin factor. It seems to me like it should only open 10 positions, but it currently has me in 33.
Rename
Not enough information. For starters...
What's the paper account size?
What's the Position Sizing Setting?
Which Trading Preferences for Portfolio Sync are enabled?
What's the Watchlist?
When did you start?
What's the paper account size?
What's the Position Sizing Setting?
Which Trading Preferences for Portfolio Sync are enabled?
What's the Watchlist?
When did you start?
The IB paper account is $1,000,000
Position size is 10% of equity, no margin
Norgate SP600 current and past
I've attempted to run the strategy for the last few days with the same results


Position size is 10% of equity, no margin
Norgate SP600 current and past
I've attempted to run the strategy for the last few days with the same results
The account is a margin account.. and it's STILL got another $559K of buying power.
If you keep sending it signals, it will keep buying.
And, you're hypothetically paying for a $2.2M margin loan.
Suggestion:
Use those Trading Thresholds - in your image.
If you only want to trade cash, check "Account Cash below" and enter an appropriate value. This will prevent sending the account more signals when cash drops below that level.
If you keep sending it signals, it will keep buying.
And, you're hypothetically paying for a $2.2M margin loan.
Suggestion:
Use those Trading Thresholds - in your image.
If you only want to trade cash, check "Account Cash below" and enter an appropriate value. This will prevent sending the account more signals when cash drops below that level.
I just don't understand if the position size is set to 10% and margin factor to 1.0 why would it keep sending signals.
Those trading thresholds seem like they would work if I were trading one strategy, but would no longer work well if I started trading more than one strategy?
Those trading thresholds seem like they would work if I were trading one strategy, but would no longer work well if I started trading more than one strategy?
The margin is for backtest simulation, it doesn't apply to live trading. You'll get whatever positions your ACTUAL margin can support, WL8 won't limit the signals based on backtest margin.
Glitch, can that be a feature request?
Using "Trading Thresholds" would be the way to set a limit on this? What if I start trading more than one strategy?
Thanks!
Using "Trading Thresholds" would be the way to set a limit on this? What if I start trading more than one strategy?
Thanks!
QUOTE:Correct. But what's the goal?
Those trading thresholds seem like they would work if I were trading one strategy, but would no longer work well if I started trading more than one strategy?
- The Cash threshold can keep you from going into margin (though it won't prevent sending 100 limit orders that could all fill at the same time.)
- The Buying Power threshold can keep you from trading that last half-million so that you're not more than $2M in debt.
If you only have 1 account what else is required?
My concern would be if I have one account, but I want to divide it 50/50 between 2 strategies and not have the whole account value used by one strategy.
Yes, allocation for the same account is a limitation for thresholds. Mixing strategies for the same account is a problem because no broker provides information [meta data] about the source of a strategy that traded the contents of the account.
You have to control your allocation at the Strategy level. For example, you could add code that checks the live account's portfolio and determine if the strategy "owns" the trade(s).
It should be a simple matter unless multiple strategies are trading the same symbols. In that case, it's time to diversify and open another account - it's free, and not a bad idea anyway.
You have to control your allocation at the Strategy level. For example, you could add code that checks the live account's portfolio and determine if the strategy "owns" the trade(s).
It should be a simple matter unless multiple strategies are trading the same symbols. In that case, it's time to diversify and open another account - it's free, and not a bad idea anyway.
Here's a strategy framework you can play around with. In `Initialize()`, enter the accountId and a list of symbols that you want to be considered for the allocation. `PositionPercentOfAccountValue()` will return the percentage of the account value for the symbols found in the account. You can use that number to prevent executing the entry logic for live trading.
Note!
This assumes that the position value is not available from the broker, and creates a data request for each position in the account to get the last price. In other words, delay.
Note!
This assumes that the position value is not available from the broker, and creates a data request for each position in the account to get the last price. In other words, delay.
CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Indicators; using System.Collections.Generic; namespace WealthScript6 { public class PortfolioTrading : UserStrategyBase { public PortfolioTrading() { AddParameter("Allow Portfolio %", ParameterType.Double, 50, 10, 90); } public override void Initialize(BarHistory bars) { _isLive = Backtester.ExecutionMode == StrategyExecutionMode.StrategyMonitor || Backtester.ExecutionMode == StrategyExecutionMode.StreamingChart; List<string> symbols = new List<string> { "NVDA", "AAPL", "IBM" }; // the stocks you want to consider in the allocation if (_allocatedPct == 0) { _allocatedPct = PositionPercentOfAccountValue("U1234567", symbols); /* use your broker account Id */ } DrawHeaderText($"Allocated: {_allocatedPct:N1}%", WLColor.NeonFuschia, 14); } public override void Execute(BarHistory bars, int idx) { if (!HasOpenPosition(bars, PositionType.Long)) { // on the last bar for live trading don't execute entry logic if you already past the allocation limit if (idx == bars.Count - 1 && _isLive && _allocatedPct >= Parameters[0].AsDouble) return; // entry logic here // } else { // exit logic here // } } public BrokerAccount GetBrokerAccount(string acct) { foreach (BrokerBase broker in SignalManager.Brokers) { BrokerAccount ba = broker.FindAccount(acct); if (ba != null) return ba; } return null; } // symbols - a list of the symbols you want to consider for this allocation. Other symbols in the account are ignored. public double PositionPercentOfAccountValue(string accountId, List<string> symbols) { BrokerAccount brokerAccount = GetBrokerAccount(accountId); if (brokerAccount != null) { double positionsTotalDollars = 0; foreach (BrokerPosition p in brokerAccount.Positions) { double value = 0; double last = 0; if (!symbols.Contains(p.Symbol)) continue; if (last == 0) { try { BarHistory xbars = WLHost.Instance.GetHistory(p.Symbol, HistoryScale.Minute1, DateTime.Now.Date, DateTime.Now.Date.AddDays(1), 0, null); last = xbars.LastValue; } catch // hasn't traded today, get the last daily close { try { BarHistory xbars = WLHost.Instance.GetHistory(p.Symbol, HistoryScale.Daily, DateTime.Now.Date.AddDays(-5), DateTime.Now.Date.AddDays(1), 0, null); last = xbars.LastValue; } catch { WLHost.Instance.AddLogItem(Backtester.Strategy.Name, "No last for " + p.Symbol, WLColor.Red); } } } if (last > 0) { value = p.Quantity * last; positionsTotalDollars += value; } WriteToDebugLog($"{p.Symbol}\t{p.Quantity}\t{p.BasisPrice:N2}\t{last:N2}\t${value:N2}"); } return 100 * positionsTotalDollars / brokerAccount.AccountValue; } else { WLHost.Instance.AddLogItem(Backtester.Strategy.Name, $"WealthLab is not connected to {accountId}", WLColor.Red); } return 0; } bool _isLive = false; static double _allocatedPct = 0; // static so that we only do it once } }
Thanks Cone,
I'm not a coder (yet?) I'll probably just open an account at another broker then if I go live with multiple strategies.
I'm not a coder (yet?) I'll probably just open an account at another broker then if I go live with multiple strategies.
Your Response
Post
Edit Post
Login is required