I have a problem with connecting some system libraries. As an example, this code compiles successfully everywhere on .net 6 except wealth-lab
I get the following error messages:
I definitely have added using System.Net; and using System.Net.Http;
CODE:
using System; using System.Collections.Generic; using System.Net; using System.Net.Http; public class Program { public static void Main() { var httpClient = new HttpClient(); var requestUri = new Uri("https :// example.com"); var requestData = new Dictionary<string, string> { { "Name", "John" }, { "Age", "30" } }; var content = new FormUrlEncodedContent(requestData); HttpResponseMessage response = null; try { response = httpClient.PostAsync(requestUri, content).GetAwaiter().GetResult(); } catch (Exception ex) { return; } if (response.StatusCode == HttpStatusCode.OK) { var responseContent = response.Content.ReadAsStringAsync().GetAwaiter().GetResult(); } } }
I get the following error messages:
CODE:
21: The type name 'HttpClient' could not be found in the namespace 'System.Net.Http'... 31: The type name 'FormUrlEncodedContent' could not be found in the namespace 'System.Net.Http'... 33: The type name 'HttpResponseMessage' could not be found in the namespace 'System.Net.Http'...
I definitely have added using System.Net; and using System.Net.Http;
Rename
You'll need to open Tools/Assembly References and add the references below.
Also, it won't compile because WL8 can only compile classes derived from UserStrategyBase. The following will compile.

Also, it won't compile because WL8 can only compile classes derived from UserStrategyBase. The following will compile.
CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Data; using WealthLab.Indicators; using System.Collections.Generic; using System.Net; using System.Net.Http; 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 httpClient = new HttpClient(); var requestUri = new Uri("https :// example.com"); var requestData = new Dictionary<string, string> { { "Name", "John" }, { "Age", "30" } }; var content = new FormUrlEncodedContent(requestData); HttpResponseMessage response = null; try { response = httpClient.PostAsync(requestUri, content).GetAwaiter().GetResult(); } catch (Exception ex) { return; } if (response.StatusCode == HttpStatusCode.OK) { var responseContent = response.Content.ReadAsStringAsync().GetAwaiter().GetResult(); } } //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 } }
Your Response
Post
Edit Post
Login is required