- ago
Is there an InputBox option in WL7?
WL6 had Utility.Input.
2
1,296
Solved
30 Replies

Reply

Bookmark

Sort
Glitch8
 ( 7.81% )
- ago
#2
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.
0
- ago
#3
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.
0
Glitch8
 ( 7.81% )
- ago
#4
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; } }
1
- ago
#6
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?
0
- ago
#7
@Glitch:
Using build 14. Getting this error:


Any suggestion how to fix?
0
- ago
#8
UNcheck WindowsBase in Assembly References.
0
- ago
#9
That fixed it, thanks!
0
- ago
#10
This line is throwing an error:
QUOTE:
s = InputWindow.ShowDialog(WLHost.Instance.MainWL7Window, "Enter some text:", "InputWindow Demo");


What would be the WL8 equivalent?
TIA.
0
Glitch8
 ( 7.81% )
- ago
#11
Assuming your code is taking care to run this in the UI thread, the code would be:

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.
3
- ago
#12
That works awesomely, thanks!!
0
- ago
#13
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.
0
edwkelly8
 ( 0.03% )
- ago
#14
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.
0
- ago
#15
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.
0
edwkelly8
 ( 0.03% )
- ago
#16
You've read it right while it was worded wrong. Thanks.
1
- ago
#17
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?
0
Glitch8
 ( 7.81% )
- ago
#18
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;    } }
0
Best Answer
- ago
#19
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?
0
- ago
#20
Glitch's code from Post #18 is working perfectly for me in production build 20. Double check your code.
0
Glitch8
 ( 7.81% )
- ago
#21
Be sure to include the using System.Windows.
1
- ago
#22
Re-tested, not working.
0
Glitch8
 ( 7.81% )
- ago
#23
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.
0
- ago
#24
I *always* run WL8 in Admin mode.
0
- ago
#25
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! 👍
0
Glitch8
 ( 7.81% )
- ago
#26
OK, it must have slipped my mind that I had added that reference a long time ago.
0
- ago
#27
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.
0
Cone8
 ( 24.56% )
- ago
#28
What does the F5 key do in WealthLab 8?
0
- ago
#29
It compiles & runs the backtest.
Surely you wrote that in jest...... !!
0
Cone8
 ( 24.56% )
- ago
#30
I knew it did that in WealthLab 6.9-, but I seriously didn't know it had been implemented in v8. 🤦‍♂️
0

Reply

Bookmark

Sort