It's not possible to bring up dialog boxes in a strategy code, because WL7 runs the strategies on different threads. Therefore, you'll run into errors about not being able to display user interface elements in a non-UI thread. And, if you force them to run on the UI thread, the strategy will continue running while the dialog box is open, and complete before you get the result back.
The strategy is stand-alone, not meant for the Strategy Monitor.
Based on the input it updates certain plotted values which I could then use for trade-specific purposes. Much easier this way than rely on my head!
I'll try playing with the Windows Message Box.
Based on the input it updates certain plotted values which I could then use for trade-specific purposes. Much easier this way than rely on my head!
I'll try playing with the Windows Message Box.
If you must do this, you'll have to jump through some hoops like this. We do have an undocumented InputWindow method in WealthLab.WPF.
CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.WPF; using System.Threading; namespace WealthScript1 { public class MyStrategy : UserStrategyBase { //input some data public override void BacktestBegin() { string s = ""; ThreadUtils.ThreadSafe(new Action(() => { s = InputWindow.ShowDialog(WLHost.Instance.MainWL7Window, "Enter some text:", "InputWindow Demo"); dataEntered = true; })); while (!dataEntered) { Thread.Sleep(10); } DrawHeaderText(s); } //Initialize public override void Initialize(BarHistory bars) { } //Execute public override void Execute(BarHistory bars, int idx) { } //private members private bool dataEntered = false; } }
Works like a charm! Thank you!!
Last Q: I modified it to provide a default value. Is there a way that when the box pops up the displayed value is highlighted so one can just type over it instead of having to delete it first?
Last Q: I modified it to provide a default value. Is there a way that when the box pops up the displayed value is highlighted so one can just type over it instead of having to delete it first?
@Glitch:
Using build 14. Getting this error:
Any suggestion how to fix?
Using build 14. Getting this error:
Any suggestion how to fix?
UNcheck WindowsBase in Assembly References.
That fixed it, thanks!
This line is throwing an error:
What would be the WL8 equivalent?
TIA.
QUOTE:
s = InputWindow.ShowDialog(WLHost.Instance.MainWL7Window, "Enter some text:", "InputWindow Demo");
What would be the WL8 equivalent?
TIA.
Assuming your code is taking care to run this in the UI thread, the code would be:
You'll need to be sure using System.Windows is one of your using clauses, too.
CODE:
s = InputWindow.ShowDialog(Application.Current.MainWindow, "Enter some text:", "InputWindow Demo");
You'll need to be sure using System.Windows is one of your using clauses, too.
That works awesomely, thanks!!
Thanks for that information.
I have a significant form that I input data to the strategy and that worked well.
I used a windows WPF form and inputWindow1.ShowDialog();. Saved the values I needed for multiple securities into static variables.
Keep up the good work.
I have a significant form that I input data to the strategy and that worked well.
I used a windows WPF form and inputWindow1.ShowDialog();. Saved the values I needed for multiple securities into static variables.
Keep up the good work.
I need a free floating (not contextual) window a lot like WL6 PrintDebug(). Some background for this request is that I drop my rather large VS 2022 compiled strategy on to a chart window to run. It is not ran from the New Strategy button so I can't use the current PrintDebug() feature. So, to make a long story short, is there a way to get a simple free-floating WL6 PrintDebug() style functionality in WL8. I have implemented the thread-safe code given here from Dion but it is a contextual dialog. Since this InputWindow is hidden, is there another window component I could use to post runtime messages to or would it be better to explore the WPF framework? Thanks.
QUOTE:
... is there another window component I could use to post runtime messages to or would it be better to explore the WPF framework?
Perhaps I'm reading this wrong, but it sound like you're trying to "output" results rather than "input" information (which is what this thread is about). If you're trying to output stuff, then take a look at this thread instead. https://www.wealth-lab.com/Discussion/Write-to-File-example-8323
The docs about AddLogItem is what you want.
You've read it right while it was worded wrong. Thanks.
Getting the following exception on running the code:
Using build 20. Don't know when the issue may have resurfaced as I hadn't opened this strategy in a while.
How to fix?
Using build 20. Don't know when the issue may have resurfaced as I hadn't opened this strategy in a while.
How to fix?
Here's how you can get InputWindow to work now in WL8:
CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.WPF; using System.Threading; using System.Windows; namespace WealthScript1 { public class MyStrategy : UserStrategyBase { //input some data public override void BacktestBegin() { string s = ""; ThreadUtils.ThreadSafe(new Action(() => { Window w = Application.Current.MainWindow; s = InputWindow.ShowDialog(w, "Enter some text:", "InputWindow Demo"); dataEntered = true; })); while (!dataEntered) { Thread.Sleep(10); } DrawHeaderText(s); } //Initialize public override void Initialize(BarHistory bars) { } //Execute public override void Execute(BarHistory bars, int idx) { } //private members private bool dataEntered = false; } }
Tried the code, still getting the same error.
BTW, I'm using Windows 10 (not sure if that matters).
Are there some assemblies I'm supposed to include/exclude?
BTW, I'm using Windows 10 (not sure if that matters).
Are there some assemblies I'm supposed to include/exclude?
Glitch's code from Post #18 is working perfectly for me in production build 20. Double check your code.
Be sure to include the using System.Windows.
Re-tested, not working.
What if you run WL8 in Administrator mode? Right click on the desktop icon and try that. Since this is an "undocumented" feature, you might need to run in Admin mode for it to work.
I *always* run WL8 in Admin mode.
Got it working *after* I included the System.Windows assembly reference (was unchecked). Initially I'd thought you were talking about the code instead of the assembly.
It's all good now! 👍
It's all good now! 👍
OK, it must have slipped my mind that I had added that reference a long time ago.
Follow-up: I'm afraid I'm still getting the exception... randomly.
Using WL8b20 in Admin mode. Windows 10 Pro.
Got the exception again today, tried a number of tricks, here's the outcome:
- It appears that adding/ removing an assembly will get it to work - but only once; hitting the F5 key may cause the exception to reappear; when that happens one doesn't have to just close the strategy but WL8 itself and start afresh (the assemblies I tested were all the System.Threading subcategories ones plus WindowsBase)
- once the exception appears one has to close and reopen WL8 - this seems to reset something (?cache) that cannot be reset in the same WL8 session
- its inconsistent: Once I get the strategy working w/o an error there is no guarantee that in the next WL8 session it won't reappear
Very puzzling behavior.
Using WL8b20 in Admin mode. Windows 10 Pro.
Got the exception again today, tried a number of tricks, here's the outcome:
- It appears that adding/ removing an assembly will get it to work - but only once; hitting the F5 key may cause the exception to reappear; when that happens one doesn't have to just close the strategy but WL8 itself and start afresh (the assemblies I tested were all the System.Threading subcategories ones plus WindowsBase)
- once the exception appears one has to close and reopen WL8 - this seems to reset something (?cache) that cannot be reset in the same WL8 session
- its inconsistent: Once I get the strategy working w/o an error there is no guarantee that in the next WL8 session it won't reappear
Very puzzling behavior.
What does the F5 key do in WealthLab 8?
It compiles & runs the backtest.
Surely you wrote that in jest...... !!
Surely you wrote that in jest...... !!
I knew it did that in WealthLab 6.9-, but I seriously didn't know it had been implemented in v8. 🤦♂️
Your Response
Post
Edit Post
Login is required