TASC 2018-10 | Probability - Probably A Good Thing To Know (Ehlers)

Modified on 2018/08/31 06:27 by Eugene — Categorized as: TASC Traders Tips

Traders' Tip text

In October 2018 Traders' Tips, author John Ehlers has shared an interesting technique of charting the probability density of an oscillator to evaluate its applicability to swing trading. However, exporting the data into a text file to be used by Excel for plotting as a bar chart is something we'd like to avoid. What we call the "Wealth-Lab way" would be to conveniently build the chart on-the-fly.

To approach this we’ll leverage the power of .NET framework (preinstalled on any Windows PC) which comes with a powerful charting control under the hood. Its broad feature set can be easily used to extend Wealth-Lab's ability to plot various objects, images and text. Let's employ it to overlay a stock chart with a nice histogram of an oscillator's probability density. Below you can have a look at the short sample code in C# which takes RocketRSI for example (but can be adjusted to accept any oscillator).


Figure 1 shows the histogram of the oscillator’s probability density overlaid on a Daily chart of SPY (10 years of data).

Bottom line: Wealth-Lab lets a trader build some complex logic or visualization without having to resort to 3rd party applications.


using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using WealthLab;
using TASCIndicators;	//required
using System.IO;		//required for plotting
using System.Windows.Forms.DataVisualization.Charting;
//1. Click "References...", then "Other Assemblies..." > "Add a reference"
//2. In "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\" (or "Framework" on 32-bit systems),
//choose and okay "System.Windows.Forms.DataVisualization.dll"

namespace WealthLab.Strategies { public class MyStrategy : WealthScript { protected override void Execute() { var rrsi = RocketRSI.Series(Close,8,10); ChartPane paneRocketRSI = CreatePane(40,true,true); PlotSeries(paneRocketRSI,rrsi,Color.DarkBlue,LineStyle.Solid,2); double[] bin = new double[61]; for(int bar = GetTradingLoopStartBar(10 * 3); bar < Bars.Count; bar++) { for(int i = 1; i <= 60; i++) //Bin the indicator values in Bins from -3 to +3 { double j = (i - 31) / 10d; double k = (i - 30) / 10d; if( rrsi[bar] > j && rrsi[bar] <= k) bin[i] = bin[i] + 1; } }

Chart chart = new Chart(); //Histogram chart chart.Width = 600; string name = "Bins"; chart.ChartAreas.Add(name); chart.ChartAreas[0].AxisX.MajorGrid.Enabled = chart.ChartAreas[0].AxisY.MajorGrid.Enabled = false; chart.ChartAreas[0].AxisX.Title = "Deviation"; //Custom axis titles chart.ChartAreas[0].AxisY.Title = "Occurences"; chart.Series.Add(name); chart.Series[name].ChartType = SeriesChartType.Column;

for(int b = 0; b < bin.GetLength(0); b++) chart.Series[name].Points.AddXY( (b - 31)/10d, bin[b]); using (MemoryStream memStream = new MemoryStream()) { chart.SaveImage(memStream, ChartImageFormat.Png); Image img = Image.FromStream(memStream); DrawImage( PricePane, img, Bars.Count-50, Close[Bars.Count-50], false ); } } } }

Eugene (Gene Geren)
Wealth-Lab team