- ago

Is there a way to mark the signals that you can actually trade based on the account size.
I want to send my signals to C2 and I don't know how to limit the signals.
0
883
Solved
12 Replies

Reply

Bookmark

Sort
Cone8
 ( 4.98% )
- ago
#1
Give an example of what you mean, exactly. Use numbers with a real example.
0
- ago
#2
Is this a repercussion of the earlier topic?
https://www.wealth-lab.com/Discussion/Signals-without-demand-8247

Or are you looking for something like Portfolio Sync (Preferences > Trading)?
0
- ago
#3
QUOTE:
Give an example of what you mean, exactly. Use numbers with a real example.

e.g.
I use the "Sizing with the Trend" function for position management.
I receive over 100 signals.
Since I didn't know how many signals I could process, I sent 40 of them to C2 as a test.
The next day I saw that WL only processed 31 of them.
How should I know that exactly 31 signals are valid. I only see it the day after.
If I can only realise this by code, can you give me an example?
I am not a programmer, but maybe I can insert the missing parts.
For the future I would like to have the function that everything I enter in "Position Sizing" is valid for backtest and real trade.


0
Cone8
 ( 4.98% )
- ago
#4
QUOTE:
How should I know that exactly 31 signals are valid.
You're using complex position sizing and a strategy that will inevitably create more signal candidates than buying power, which will result in "NSF Positions".

To answer your question more directly, due to price gaps and limited buying power (unless you're trading for the Federal Reserve) an EOD strategy can never know how many signals will be filled on the next bar.

My question is, "why do you need to know how many signals will be 'valid', i.e., filled?
0
- ago
#5
I realize that this will never fit exactly, but I would at least like to be close and not completely in the dark.
The WL and C2 should run largely in parallel.
But that does not work because C2 buys on margin if the money is not enough, which is not part of the strategy.
I do not know if it works this way, but I mean based on the closing prices of yesterday and the set or transmitted balance should be displayed the possible signals.
The way I see it, at the moment I would have to export all the signals sorted to Excel, add up there the capital probably needed per trade and then submit only the trades as long as the money lasts. That is a lot of manual work.
As mentioned above, I now have 40 positions in C2 and only 31 in WL

0
Cone8
 ( 4.98% )
- ago
#6
QUOTE:
because C2 buys on margin if the money is not enough, which is not part of the strategy.
Really? You can't make a C2 Strategy cash only? This seems to be the short stick in this equation. It's not a problem with Wealth-Lab.

QUOTE:
As mentioned above, I now have 40 positions in C2 and only 31 in WL
Wealth-Lab will still generate signals for the NSF positions, but you can, of course, use margin in Wealth-Lab.

QUOTE:
That is a lot of manual work.
When you can program anything and everything in a strategy, for the life of me I don't know why everyone thinks "Excel is the answer".

If you need to make Portfolio level trading decisions in your code, then you can use PreExecute (or PostExecute) method to determine which signals you want to trigger based on anything you want.

One question before continuing - yours is a Market order strategy, correct? Because you're using Stop or Limit entries all orders are "valid" because you can't know which will fill a priori.
1
- ago
#7
Thanks for the answer:

1.
I know that WL still generates NSF positions.
However, I would like to trade only the currently valid signal when it occurs for the first time.

2.
Also that I can trade on margin in WL is I know.
But I do not want that.
I want to see what signals are real tradable based on my account balance with the value of yesterday's closing price.

3.
Manual work:
Yes, who can program does not need Excel. But I am a user and trader, not a programmer. I am looking for a solution. That is for me at the moment Excel in combination with WL.

4.
Yes, in this case it is a market-on-open strategy. I do not use stop or limit orders in this strategy.

0
Cone8
 ( 4.98% )
- ago
#8
Since a strategy can't access a broker's account value (unless you build that link) you can't automate this completely for an EOD Market order strategy. If you were trading intraday, and assuming you're using finantic's C2 broker adapter, you could take advantage of Thresholds in Preferences > Trading by enabling the Account Cash Below item.

But that won't help with an EOD Market Order strategy since these orders need to be placed prior to the open and won't actually reduce the account's cash until the orders are filled. So, you have to make the order fill estimate, choosing the orders by some sort of priority/weight until the cash estimate is exhausted.

There's still no way of getting around knowing the cash value of the account, which the strategy can't access directly (at least not yet, there's a Feature Request for that). So you need to tell the strategy what it is. For now, you can edit it in the code below each day, or read it from a file, etc.)

The solution.
Add this method to your strategy. It takes the account cash available, adds the exit value total estimate to it, sorts new entries by weight, and eliminates entry signals that would result in a negative cash balance. For reference, the Debug Log will show all the signals before pruning.

CODE:
/* IMPORTANT: Add using System.Linq; */ public override void BacktestComplete() { double cashAvailable = 25000;   // change this to account cash                    WriteToDebugLog("True Signal Count = " + Backtester.Orders.Count.ToString(), false);          foreach (Transaction t in Backtester.Orders)          {             double tradevalue = t.Bars.LastValue * t.Quantity;             string signal = String.Format("{0,-6}{1,-6}{2,-8}{3,-8:N4}{4:10}", t.TransactionType, t.Quantity, t.Bars.Symbol, t.Weight, tradevalue.ToString("$0,0"));             WriteToDebugLog(signal, false);          }          //exit orders - add trade estimate value to cash                cashAvailable += Backtester.Orders.Where(x => x.IsExit).Sum(y => y.Quantity * y.Bars.LastValue);          WriteToDebugLog("", false);          WriteToDebugLog("Cash Available with exits: " + cashAvailable.ToString("$0,0"), false);          //sort and remove excess buys that exceed cash          List<Transaction> buys = Backtester.Orders.Where(x => x.IsEntry).OrderBy(w => w.Weight).ToList();          for (int n = buys.Count - 1; n >= 0; n--)          {             Transaction t = buys[n];                         double tradevalue = t.Bars.LastValue * t.Quantity;             cashAvailable -= tradevalue;             if (cashAvailable < 0)                Backtester.Orders.Remove(t);          } }

2
Best Answer
- ago
#9
Thank you for the detailed answer.
I can live well with the solution.
I will try to include the code.
Maybe I should take a course in C#.
Then I have more possibilities.
0
- ago
#10
There is a problem:

Compiled at 02.08.2022 21:47:50
78: "List<Transaction>" does not contain a definition for "Where" and no accessible where extension method could be found that accepts a first argument of type "List<Transaction>" (possibly a using directive or an assembly reference is missing).
83: "List<Transaction>" does not contain a definition for "Where" and no accessible Where extension method could be found that accepts a first argument of the type "List<Transaction>" (possibly missing a using directive or an assembly reference).

0
- ago
#11
Did you follow Cone's directive? I mean the one that says IMPORTANT. You're doing Linq queries here, so you need a using statement to include Linq. See the error message ...
QUOTE:
... possibly a using directive or an assembly reference is missing ...


CODE:
/* IMPORTANT: Add ... using System.Linq; */
0
- ago
#12
Thank you, I hadn't seen that.


1

Reply

Bookmark

Sort