- ago
Code from examples:

CODE:
using WealthLab.Backtest; using WealthLab.Core; using WealthLab.Indicators; using System.Drawing; namespace WealthScript4 {    public class MyStrategy1 : UserStrategyBase    {       //create indicators and other objects here, this is executed prior to the main trading loop       public override void Initialize(BarHistory bars)       {          //get weekly data          BarHistory monthly = BarHistoryCompressor.ToMonthly(bars);          //get 4 week RSI          RSI rsiMonthly = new RSI(monthly.Close, 4);          //synchronize it back to the original (daily) scale          TimeSeries rsiMonthlySynched = TimeSeriesSynchronizer.Synchronize(rsiMonthly, bars);          //Plot the weekly RSI on the daily chart          PlotTimeSeries(rsiMonthlySynched, "RSI(Monthly)", "RSI", Color.Blue);       }       //execute the strategy rules here, this is executed once for each bar in the backtest history       public override void Execute(BarHistory bars, int idx)       {       }       //declare private variables below    } }


Is it possible to add some code so that the value of the monthly indicator on the daily chart does not change on the current bar within the monthly interval? This creates inconvenience, since the current signal to open/close a position is distorted:

0
620
Solved
2 Replies

Reply

Bookmark

Sort
Cone8
 ( 26.65% )
- ago
#1
The idea would be not to look at a monthly strategy until the last day of the month :). But if you insist...

CODE:
using WealthLab.Backtest; using WealthLab.Core; using WealthLab.Indicators; using System.Drawing; namespace WealthScript4 {    public class MyStrategy1 : UserStrategyBase    {              //create indicators and other objects here, this is executed prior to the main trading loop       public override void Initialize(BarHistory bars)       {          //get monthly data          BarHistory monthly = BarHistoryCompressor.ToMonthly(bars);          //get 4-month RSI          RSI rsiMonthly = new RSI(monthly.Close, 4);          //synchronize it back to the original (daily) scale          TimeSeries rsiMonthlySynched = TimeSeriesSynchronizer.Synchronize(rsiMonthly, bars);          TimeSeries daysLeft = TradingDaysLeft.Series(bars, TradingDayChoices.Monthly);          int n = bars.Count - 1;          if (daysLeft[n] > 0)             rsiMonthlySynched[n] = rsiMonthlySynched[n -1];          //Plot the weekly RSI on the daily chart          PlotTimeSeries(rsiMonthlySynched, "RSI(Monthly)", "RSI", Color.Blue);       }       //execute the strategy rules here, this is executed once for each bar in the backtest history       public override void Execute(BarHistory bars, int idx)       {                           }    } }
1
Best Answer
- ago
#2
That's cool. Thanks.
0

Reply

Bookmark

Sort