Wealth-Lab Wiki

API ChartStyles Community Components Community Indicators IndexDefinitions Knowledge Base Misc Optimizers Pending Deletion PosSizers Providers Standard Indicators TASC Traders Tips TASCIndicators Tutorial Videos Visualizers


Quick Search
Advanced Search »

TASC 2020-06 | Correlation as a Cycle Indicator (Ehlers)


Traders' Tip text

In June 2020 issue, Mr. Ehlers follows up his previous monthÆs article with a new mode switching indicator - the CorrelationAngle. To illustrate the application of the indicator, please find below a sample trading system that changes approach depending on the phase angle.

We define an uptrend when the CorrelationAngleÆs state ôflatlinesö at 1 for 2 bars (or -1 for a downtrend). The logic is simple. An uptrend switches the system into trend following mode, with entries and exits made via channel breakout. If permitted, short trades are done in the same manner in a downtrend -- yet with a shorter lookback period for the channel. An absense of trend directs the system to take cyclic trades: buying small dips and selling at the high of the channel.

Here are the rules:

  1. Buy at stop next day when price breaks through the highest price of 20 days and thereÆs an uptrend detected
  2. Short at stop next day when price breaks below the lowest price of 10 days and thereÆs a downtrend detected (if short trades are allowed)
  3. Buy at limit next day at 5% below todays low if thereÆs neither uptrend nor downtrend (buy dips)
  4. Exit at a -10% stop loss
  5. Exit long next day when a downtrend kicks in
  6. Exit long at stop next day at the lowest price of 10 days
  7. Cover at stop next day at the highest price of 10 days


Figure 1. Trading system switches gears when AppleÆs stock experiences a smooth uptrend followed by a rapid decline. The CorrelationAngle indicator is plotted on the upper pane of the chart. The ômarket stateö is plotted as a ôbinary waveö on the lower pane of the chart.

To execute the included trading system, Wealth-Lab users need to install (or update) the latest version of the TASCIndicators library from the Extensions section of our website if they haven't already done so, and restart Wealth-Lab. Then either copy/paste the included Strategy's C# code or simply let Wealth-Lab do the job. From ôOpen Strategyö dialog, click ôDownloadö to get this strategy as well as many other contributed by the Wealth-Lab community.

WealthScript Code (C#)

using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using WealthLab;
using WealthLab.Indicators;
using TASCIndicators;

namespace WealthLab.Strategies { public class TASC2020_06 : WealthScript { private StrategyParameter paramShort; private StrategyParameter paramStop;

public TASC2020_06() { paramShort = CreateParameter("Short enabled", 0, 0, 1, 1); paramStop = CreateParameter("S/L %", 10, 5, 30, 5); }

protected override void Execute() { var ca = CorrelationAngle.Series(Close, 14, 0); var State = new DataSeries(Close, "BinaryWave"); bool shortTrades = paramShort.ValueInt == 1; var stopLoss = paramStop.Value;

for(int bar = GetTradingLoopStartBar(20); bar < Bars.Count; bar++) { bool upTrend = false, downTrend = false; //Compute and plot market state if (bar > 0) { if (Math.Abs(ca[bar] - ca[bar - 1]) < 9 && ca[bar] < 0) State[bar] = -1; if (Math.Abs(ca[bar] - ca[bar - 1]) < 9 && ca[bar] >= 0) State[bar] = 1;

upTrend = State[bar] == 1 && State[bar-1] == 1; downTrend = State[bar] == -1 && State[bar-1] == -1; }

if(upTrend) SetBackgroundColor(bar, Color.FromArgb(30, Color.Green)); if (downTrend) SetBackgroundColor(bar, Color.FromArgb(30, Color.Red)); if (IsLastPositionActive) { Position p = LastPosition; if (!ExitAtStop(bar + 1, p, p.RiskStopLevel, string.Format("SL {0}%", stopLoss))) { if (p.PositionType == PositionType.Long) { switch (p.EntrySignal) { case "Breakout": if (downTrend) SellAtMarket(bar + 1, p, "Trend change"); else SellAtStop(bar + 1, p, Lowest.Series(Low, 20)[bar]); break; case "Dip buy": SellAtLimit(bar + 1, p, Highest.Series(High, 5)[bar]); break; default: break; } } else { CoverAtStop(bar + 1, p, Highest.Series(High, 10)[bar]); } } } else { if (bar > 0) { RiskStopLevel = Close[bar] * (1 - (stopLoss / 100d)); if (upTrend) { BuyAtStop(bar + 1, Highest.Series(High, 20)[bar], "Breakout"); } else if (downTrend && shortTrades) { ShortAtStop(bar + 1, Lowest.Series(Low, 10)[bar], "Breakdown"); } else { BuyAtLimit(bar + 1, Low[bar] * 0.95, "Dip buy"); } } } } ChartPane paneCA = CreatePane(30,true,true); ChartPane paneBW = CreatePane(30,false,true); PlotSeries(paneCA,ca,Color.DarkBlue,LineStyle.Solid,2); PlotSeries(paneBW,State,Color.DarkBlue,LineStyle.Solid,2); DrawHorzLine(paneCA,0,Color.DarkCyan,LineStyle.Solid,2); DrawHorzLine(paneBW,0,Color.DarkCyan,LineStyle.Solid,2); HideVolume(); } } }

Gene Geren (Eugene)
Wealth-Lab team

Important Disclaimer: The information provided by Wealth-Lab is strictly for informational purposes and is not to be construed as advice or solicitation to buy or sell any security.  The owner of Wealth-Lab.com assumes no liability resulting from the use of the material contained herein for investment purposes. By using this web site, you agree to the terms of this disclaimer and our Terms of Use.

ScrewTurn Wiki. Some of the icons created by FamFamFam.