- ago
Hi, I copied some code from your BarHistoryCompressor example (the hour version) and adapted it for minutes since there was no source code example with the ToMinute. Im trying to compress 5 minute to 20 minutes and use CCI Timeseries with differing intervals for trade signals. The compressed bars and underlying compressed CCI don't seem to line up with the original interval as in there is a drop in the 5 minute data but the candlesticks and CCI seem shifted.

CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Indicators; using System.Drawing; using System.Collections.Generic; namespace WealthScript9 {    public class BarHistoryToHourlyExample : UserStrategyBase    {       TimeSeries _rsi2hour;       TimeSeries indicator;       TimeSeries indicator2;       TimeSeries indicator3;       TimeSeries indicator4;       BarHistory h2Bars;       Position foundPosition0;              public override void Initialize(BarHistory bars)       {          if (!bars.IsIntraday)          {             throw new InvalidOperationException("Example is intended for an intraday BarHistory");          } //         StartIndex = 4;          //Compress to 2-hour bars          BarHistory h2Bars = BarHistoryCompressor.ToMinute(bars, 20);          //Get a RSI(14) of the 2-hour low series          _rsi2hour = RSI.Series(h2Bars.Low, 14);          //synchronize the rsi          indicator = new CCI(h2Bars, 12);          indicator2 = new CCI(h2Bars, 8);          indicator3 = new CCI(h2Bars, 20);          indicator4 = new Lowest(h2Bars.Close, 14);          indicator4 = TimeSeriesSynchronizer.Synchronize(indicator4, bars);          indicator3 = TimeSeriesSynchronizer.Synchronize(indicator3, bars);          indicator2 = TimeSeriesSynchronizer.Synchronize(indicator2, bars);          indicator = TimeSeriesSynchronizer.Synchronize(indicator, bars);          _rsi2hour = TimeSeriesSynchronizer.Synchronize(_rsi2hour, bars.Close);          h2Bars = BarHistorySynchronizer.Synchronize(h2Bars, bars);          //         PlotTimeSeries(_rsi2hour, "RSI(14) of 2 hour bars", "RSIPane", WLColor.Blue, PlotStyle.Line);          PlotTimeSeries(indicator, "CCI(12) of 20 minute bars", "RSIPane", WLColor.Blue, PlotStyle.Line);          PlotTimeSeries(indicator2,"CCI(8) of 20 minute bars", "RSIPane", WLColor.Green, PlotStyle.Line);          PlotTimeSeries(indicator3, "CCI(20) of 20 minute bars", "RSIPane", WLColor.Brown, PlotStyle.Line);          PlotTimeSeries(indicator3, "Lowest(14) of 20 minute bars", "RSIPane", WLColor.Black, PlotStyle.Line);          PlotBarHistory(h2Bars, "Price", WLColor.FromArgb(62, 0, 0, 0));       }       public override void Execute(BarHistory bars, int idx)       {          foundPosition0 = FindOpenPosition(0);          if (foundPosition0 == null)          {             //buy when the 2-hr rsi of the lows drops below 30             if (_rsi2hour.CrossesUnder(30, idx))             {                PlaceTrade(bars, TransactionType.Buy, OrderType.Market,0,0);       //         PlaceTrade(bars, TransactionType.Sell, OrderType.MarketClose);             }          }          else          {             //sell when the 2-hr rsi of the lows rises above 50    //         PlaceTrade(bars, TransactionType.Sell, OrderType.Market);             if (idx - foundPosition0.EntryBar + 1 >= 3)                ClosePosition(foundPosition0, OrderType.Market, 0, "Sell after 3 bars");          }       }    } }
0
283
Solved
2 Replies

Reply

Bookmark

Sort
Cone8
 ( 23.52% )
- ago
#1
The code, and as far as I can tell, the result, are both correct.

The compressed bars will be a summary of the 20-minute interval ending on minutes :50, :10, and :30 - assuming that you've enabled Filter for U.S. market hours. If you don't enable the Filter, compressed bars will end at :00, :20, and :40.

In either case, you'll see repeated compressed bars until the end of the interval, during which the 5 minute base scale will have changed 4 times.
0
Best Answer
- ago
#2
thank you
0

Reply

Bookmark

Sort