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
RSS

Navigation


Quick Search
»
Advanced Search »


TASC 2020-01 | An Interplanetary Marriage (Leavitt)

RSS

Traders' Tip text

We strived to find clear rules that build a trading system in this month’s article but it doesn’t appear to contain a complete strategy. Here’s our attempt at creating something:

Entry rules

  • Buy next bar at open when the Leavitt Convolution Slope and the LcAcceleration both get above zero

Exit rules

  • Exit at market when the Leavitt Convolution Slope "reaches its peak" (as defined by rising to its 20-bar high) and then the LcAcceleration changes its sign (i.e. goes below zero).


Image

Figure 1. Trading rules applied to a chart of AXP (American Express) Data provided by Yahoo Finance.


Figure 1 illustrates the system’s mechanics on a sample trade in AXP. In July’19 the LeavittConvSlope indicator hits a 50-bar highest high, touching the blue dashed line. Shortly after the LcAcceleration indicator turns down and the system is out.

To get the Strategy's C# code, no need in copy/paste: simply download it right from Wealth-Lab's "Open Strategy" dialog.

WealthScript Code (C#)


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

namespace WealthLab.Strategies { public class Leavitt : WealthScript { private StrategyParameter paramLength; private StrategyParameter paramPeak; public Leavitt() { paramLength = CreateParameter("LcP Length", 50, 10, 50, 10); paramPeak = CreateParameter("LcSlope Peak", 50, 5, 50, 5); } protected override void Execute() { bool reachedPeak = false, changedSign = false; int peakBar = -1, signBar = -1; int peakBars = paramPeak.ValueInt;

int Length = paramLength.ValueInt; var LeavittProjection = LinearReg.Series(Close, Length); int LenConv = Convert.ToInt32(Math.Sqrt(Length)); // this is how EasyLanguage extracts the integer portion of a variable var LeavittConv = LinearReg.Series(LeavittProjection, LenConv); //inline function call // The slope follows the same pattern. However, step 2, which defines the line, is replaced by capturing the slope of that line. var LeavittConvSlope = LinearRegSlope.Series(LeavittProjection, LenConv); LeavittConvSlope.Description = "LeavittConvSlope"; // The acceleration is simply the difference between two consecutive values of the slope. var LcAcceleration = LeavittConvSlope - (LeavittConvSlope>>1); LcAcceleration.Description = "LcAcceleration"; var LeavittConvAcc = new DataSeries(Bars,"LeavittConvAcc"); LeavittConvAcc.Description = "LeavittConvAcc"; HideVolume(); ChartPane p3 = CreatePane(10,false,false); ChartPane p2 = CreatePane(30,true,false); ChartPane p1 = CreatePane(30,true,false); PlotSeries(p1, LcAcceleration, Color.Blue, LineStyle.Histogram, 5 ); PlotSeries(p2, LeavittConvSlope, Color.Blue, LineStyle.Histogram, 5 ); PlotSeries(p3, LeavittConvAcc, Color.Blue, LineStyle.Histogram, 5 ); PlotSeries( p2, Highest.Series( LeavittConvSlope, peakBars ), Color.Blue, LineStyle.Dashed, 1 ); for(int bar = 1; bar < Bars.Count; bar++) { SetSeriesBarColor( bar, LcAcceleration, LcAcceleration[bar] > 0 ? Color.DarkGreen: Color.Red ); SetSeriesBarColor( bar, LeavittConvSlope, LeavittConvSlope[bar] > LeavittConvSlope[bar-1] ? Color.DarkGreen: Color.Red );

if( bar > 2 ) { if (Close[bar - 2] - 2*Close[bar - 1] + Close[bar] > 0) LeavittConvAcc[bar] = 1; else LeavittConvAcc[bar] = -1; } } for(int bar = GetTradingLoopStartBar(1); bar < Bars.Count; bar++) { if (IsLastPositionActive) { //This exit was taken on the 30-minute chart precisely when //LcSlope reached its peak and LcAcceleration changed sign. var hb = HighestBar.Series( LeavittConvSlope, peakBars )[bar]; if( !reachedPeak ) { if( bar == hb ) { SetBackgroundColor( bar, Color.FromArgb(50,Color.LightBlue)); reachedPeak = true; peakBar = bar; } } if( reachedPeak ) { if( !changedSign ) { if( LcAcceleration[bar] < 0 ) { SetBackgroundColor( bar, Color.FromArgb(50,Color.LightSalmon)); changedSign = true; signBar = bar; } if( changedSign ) { if( SellAtMarket(bar+1, LastPosition ) ) { reachedPeak = false; changedSign = false; } } } } } else { if( LeavittConvSlope[bar] > 0 && LcAcceleration[bar] > 0 ) BuyAtMarket(bar+1); } } } } }

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.

Used under license from FMR Corp. Copyright 2008 FMR Corp. All rights reserved.


ScrewTurn Wiki. Some of the icons created by FamFamFam.