using System; using System.Collections.Generic; using System.Text; using System.Drawing; using WealthLab; using WealthLab.Indicators; using TASCIndicators; //Requires CBOE provider extensions from www.wealth-lab.comnamespace WealthLab.Strategies { public class PutCallRatioIndicator : WealthScript { StrategyParameter _rsiPeriod; StrategyParameter _wmaPeriod; StrategyParameter _devs; StrategyParameter _slowRainbowPeriod; StrategyParameter _wmaSlow; StrategyParameter _rsiPer; public PutCallRatioIndicator() { _rsiPeriod = CreateParameter("Fast RSI Period", 5, 2, 30, 1); _wmaPeriod = CreateParameter("Fast WMA Period", 5, 2, 10, 1); _devs = CreateParameter("SD Multiple", 1.3, 1, 2, 0.1); _slowRainbowPeriod = CreateParameter("Slow Rbw Period", 4, 1, 10, 1); _wmaSlow = CreateParameter("Slow Smooth Period", 2, 1, 10, 1); _rsiPer = CreateParameter("Slow IF RSI Period", 8, 1, 20, 1); } // Transforms a series for unscaled plotting (translated from WL4 Code Library, Dexter Brunet) public DataSeries TransformSeries( DataSeries ds, double a1, double a2, double b1, double b2) { string sName = ds.Description + "(No Scale)"; if (Math.Abs(a1 - a2) > 0.00001) { double a = (b1 - b2)/(a1 - a2); double b = (b2 * a1 - a2 * b1)/(a1 - a2); DataSeries s = ds * a; s += b; s.Description = sName; return s; } else return ds; } protected override void Execute() { // Access the raw P/C Ratio data //DataSeries pcrEQ = GetExternalSymbol("CBOE Put/Call Ratio", "EQUITYPC", true).Close; DataSeries pcrEQ = GetExternalSymbol("EQUITYPC", true).Close; /* Create and plot indicators */ HideVolume(); DataSeries fastPCRI = PCRiFast.Series(pcrEQ, _rsiPeriod.ValueInt, _wmaPeriod.ValueInt); DataSeries uBand = BBandUpper.Series(fastPCRI, 200, 1.3); DataSeries lBand = BBandLower.Series(fastPCRI, 200, 1.3); DataSeries slowPCRI = PCRiSlow.Series(pcrEQ, _slowRainbowPeriod.ValueInt, _wmaSlow.ValueInt); ChartPane rsiPane = CreatePane(40, false, true); PlotSeries(rsiPane, fastPCRI, Color.Black, LineStyle.Solid, 2); PlotSeries(rsiPane, uBand, Color.Blue, LineStyle.Dashed, 1); PlotSeries(rsiPane, lBand, Color.Blue, LineStyle.Dashed, 1); // Transform slowPCRI for plotting in same pane as fastPCRI int n = Bars.Count - 1; DataSeries slowT = TransformSeries(slowPCRI, Lowest.Value(n, slowPCRI, n - 30), Highest.Value(n, slowPCRI, n - 30), 0, 100); PlotSeries(rsiPane, slowT, Color.Red, LineStyle.Solid, 2); DataSeries pcri_IF = PCRiSlowIFT.Series(pcrEQ, _slowRainbowPeriod.ValueInt, _wmaSlow.ValueInt, _rsiPer.ValueInt); PlotSeries(rsiPane, pcri_IF, Color.Blue, LineStyle.Solid, 2); ChartPane pcPane = CreatePane(40, false, true); PlotSeries(pcPane, pcrEQ, Color.Black, LineStyle.Solid, 2, "P/C Ratio (raw, clipped)"); } } }