- ago
Any example how initialize bars object from timeseries in wl8 ?
0
595
Solved
8 Replies

Reply

Bookmark

Sort
- ago
#1
For instance something like
//ts is some timeseries
BarHistory bh = Bars.FromTimeSeries(ts) ; //?
0
- ago
#2
Is it possible and how to use available to code but not documented method
BarHistory AddFrom
to modify Barhistory?
0
Glitch8
 ( 9.28% )
- ago
#3
Yes it's possible, but what are you going after? What is the source TimeSeries and why do you want to create a BarHistory based on it.

A BarHistory has FOUR price TimeSeries (OHLC) and ONE volume, what will the other 3 price TimeSeries get set to, and what about volume?
0
Glitch8
 ( 9.28% )
- ago
#4
Here's an example I just whipped up, one way to do it,

CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Data; using WealthLab.Indicators; 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) {          RSI rsio = RSI.Series(bars.Open, 10);          RSI rsih = RSI.Series(bars.High, 10);          RSI rsil = RSI.Series(bars.Low, 10);          RSI rsic = RSI.Series(bars.Close, 10);          BarHistory bh = new BarHistory("RSI", bars.Scale);          bh.DateTimes.AddRange(bars.DateTimes);          bh.Open.Values.AddRange(rsio.Values);          bh.High.Values.AddRange(rsih.Values);          bh.Low.Values.AddRange(rsil.Values);          bh.Close.Values.AddRange(rsic.Values);          PlotBarHistory(bh, "RSI", WLColor.GreenYellow); } //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
Best Answer
- ago
#5
Was trying to aggregate underlying bar histories for a sector. Still playing.
Thank you
0
Cone8
 ( 5.88% )
- ago
#6
Maybe you really just want a aggregate index in a TimeSeries. Check out the Index-Lab folder of Indicators which does just that.

Open a chart, drag and drop "CompInd", select the DataSet...
1
- ago
#7
QUOTE:
Maybe you really just want a...

Yes @flanda, sometimes it's simply more productive for both parties if we know your goal from the start.
1
MIH8
- ago
#8
I have been playing with a second time scale in an intraday context. Although you can compress data from the actual intraday scale, it makes sense to use real data as well for various reasons. This works in either direction (loading intraday for EOD). You need to pay attention to the data convention used by WL.

I have tried to create a strategy that works on multiple time scales. Here is an example.

CODE:
      public void load_eod_data(string symbol)       {          string[] token;          string[] lines = { };          BarData bar;          // data location          String s = "YOURPATH\\API\\workfiles\\eod\\";          s = s + symbol + ".txt";          // load data          try          {             lines = System.IO.File.ReadAllLines(s);          }          catch          {             WriteToDebugLog("File " + s + " not found");          }          eod_data.Clear();          foreach (string line in lines)          {             token = line.Split(",");             bar = new BarData();             // load bardata             bar.DateTime = DateTime.ParseExact(token[0], "yyyy-MM-dd", CultureInfo.InvariantCulture);             bar.Open = double.Parse(token[1], CultureInfo.InvariantCulture);             bar.High = double.Parse(token[2], CultureInfo.InvariantCulture);             bar.Low = double.Parse(token[3], CultureInfo.InvariantCulture);             bar.Close = double.Parse(token[4], CultureInfo.InvariantCulture);             bar.Volume = double.Parse(token[5], CultureInfo.InvariantCulture);             eod_data.Add(bar);          }       }

0

Reply

Bookmark

Sort