- ago
I am not sure if I am doing a mistake or missing something or if it is the desired behavior. When I run a strategy using StrategyRunner.RunBackTest(), I don't see any child window getting launched in WealthLab and the corresponding chart and other visualizers. This is my code:
CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Indicators; using System.Drawing; using System.Collections.Generic; namespace WealthScript1 { public class MyStrategy : UserStrategyBase { //create indicators and other objects here, this is executed prior to the main trading loop public override void Initialize(BarHistory bars) {          var symbol = "AAPL";          var strategy = "Test1";                    Strategy s = StrategyFactory.FindStrategy(strategy);          if (s == null)          {             WriteToDebugLog("strategy could not be found. Strategy = '" + strategy + "'");             //throw new ArgumentException("Strategy not found: RSI2");             return;          }          StrategyRunner sr = new StrategyRunner();          sr.Symbols.Add(symbol);          sr.BacktestSettings.CommissionType = CommissionTypes.None;          StrategyBase sb = s.CreateInstance();          Backtester bt = sr.RunBacktest(sb);          WLHost.Instance.AddLogItem("Test2", "Executing my test script", Color.Red);          WriteToDebugLog("Log: " + bt.ToString()); } //execute the strategy rules here, this is executed once for each bar in the backtest history public override void Execute(BarHistory bars, int idx) { if (!HasOpenPosition(bars, PositionType.Long)) { //code your buy conditions here } else { //code your sell conditions here } } //declare private variables below } }
0
911
Solved
11 Replies

Reply

Bookmark

Sort
- ago
#1
It does not mean to instantiate any Strategy window with visualizers nor a chart. The point is to have code-based access to the strategy backtest object in the strategy code.
0
- ago
#2
Got it!

Is there any other method/class to launch (or use existing one if already open) Strategy Window with the chart and visualizers? If not, can we add this as a feature request?
0
Cone8
 ( 6.32% )
- ago
#3
What the purpose? Is it something you can't do by opening a Workspace?
0
Best Answer
- ago
#4
You can use ScottPlot for doing your own plotting:
https://www.youtube.com/watch?v=js81fCy_rx4&t=662s
0
- ago
#5
Yeah, ChartComponent will help, but it will be just easier to launch a chart with specific WealthLab script. My current use case is that when I click on a symbol, I want to see four charts (with their own WealthLab scripts) updated:
1. stock daily
2. stock weekly
3. stock's industry group daily
4. stock's industry group weekly
I can have a "driver" script which can run the scripts for all the above 4 charts if we have the StrategyRunner.RunBackTest() show the Window with the chart and visualizers.
0
Glitch8
 ( 12.10% )
- ago
#6
I'm sorry but this is out of scope for the StrategyRunner. It's not meant to interface with the WL7 GUI at all.
0
- ago
#7
I get it that this was not in the original scope of StrategyRunner.

Can we take it as a feature request?

I think you already have all the individual pieces, it will just require plumbing them.
0
Glitch8
 ( 12.10% )
- ago
#8
I don’t feel this is an appropriate task for the StrategyRunner. It operates at a lower logical level, and doesn’t even have any concept of the WL7 UI.
0
- ago
#9
QUOTE:
Yeah, ChartComponent will help, but it will be just easier to launch a chart with specific WealthLab script.

As @Cone already suggested, and I believe it's to the point, you can simply open a Workspace. It hardly makes sense to build an awkward programmatic solution for what can already be reached by pressing a button.
0
- ago
#10
@Glitch,

How about having a new method in IHost class - IHost.RunScript(scriptName, symbolName, timeFrame) ?
0
Glitch8
 ( 12.10% )
- ago
#11
The IHost class is at an even lower level, it doesn't have any concept of the WL7 UI.
0

Reply

Bookmark

Sort