Traders' Tip text
We’ve coded the multi-faceted strategy by author Domenico D’Errico in WealthScript for use in Wealth-Lab. It contains quite a number of variables to adjust its behavior. For example, you can switch between the three modes of detection of price compression: range,
ATR and
ADX, configure its
RSI and ADX thresholds, the consolidation factor, choose preferred type of entry (breakout or pullback) and so on. You’ll find them exposed for optimization as well as for manual fine-tuning at the bottom left of the screen. These "parameter sliders" can be dragged interactively, making the chart redraw instantly with the updated trades and performance.
As the accumulation phase often takes place at the end of a downtrend, we believe that motivated traders would want to throw in some logic to limit the system’s exposure to other market conditions. As presented by the author, it takes many trades during the other phases and thus might benefit from filtering.
Figure 1. Sample trades on the Weekly chart of AAPL (Apple).If you want more of the same kind of trading technique in Wealth-Lab, we got you covered. Hit Ctrl-O, choose “Download…” and you should have the downloadable Strategy
“Rectangle trading system (Acme R)” under the “Chart patterns” folder. Most like the Accumulation/Distribution system, its idea is in identifying tradable rectangle patterns by comparing the size of consolidation to the size of preceding trending range. An entry is signaled after a breakout if the consolidation range (measured in ATR units) is rather tight than volatile. It’s also flexible in configuring its various parameters interactively through “sliders”.
Codeusing System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using WealthLab;
using WealthLab.Indicators;
namespace WealthLab.Strategies
{
public class TASC_2018_08 : WealthScript
{
private StrategyParameter paramMode;
private StrategyParameter paramLength;
private StrategyParameter paramADX;
private StrategyParameter paramConsTimeout;
private StrategyParameter paramConsFactor;
private StrategyParameter paramEntryBreakout ;
public TASC_2018_08()
{
paramMode = CreateParameter("A/D/ ATR/ ADX", 0, 0, 2, 1);
paramLength = CreateParameter("Length", 4, 4, 10, 2);
paramADX = CreateParameter("ADX Trigger", 30, 5, 40, 5);
paramConsTimeout = CreateParameter("Cons. timeout", 4, 2, 20, 2);
paramConsFactor = CreateParameter("Cons. factor", 0.75, 0.25, 0.75, 0.25);
paramEntryBreakout = CreateParameter("Brkout/Pullback", 0, 0, 1, 1);
}
protected override void Execute()
{
int mode = paramMode.ValueInt;
int Length = paramLength.ValueInt, ADXTrigger = paramADX.ValueInt,
TopBar = -1, BottomBar = -1, ConsolidationBar = -1,
ConsolidationTimeout = paramConsTimeout.ValueInt;
double ConsolidationFactor = paramConsFactor.Value, ATRFactor = paramConsFactor.Value,
Top = 0.0, Bottom = 0.0;
var Range_ = Highest.Series(High,Length)-Lowest.Series(Low,Length);
var ATR_ = ATR.Series(Bars,Length);
var ADX_ = ADX.Series(Bars,Length);
int minPeriod = Math.Max(Length * 3, 20);
bool Consolidation = false, breakout = paramEntryBreakout.ValueInt == 0 ? true : false;
for(int bar = GetTradingLoopStartBar(minPeriod); bar < Bars.Count; bar++)
{
if( !Consolidation )
{
bool conditionRange = (Range_[bar] < ConsolidationFactor * Range_[bar - Length]) && paramMode.ValueInt == 0;
bool conditionATR = (ATR_[bar] < ATRFactor * ATR_[Length]) && paramMode.ValueInt == 1;
bool conditionADX = (ADX_[bar] < ADXTrigger) && paramMode.ValueInt == 2;
if( conditionRange || conditionATR || conditionADX )
{
Consolidation = true;
Top = Highest.Series(High,Length)[bar];
Bottom = Lowest.Series(Low,Length)[bar];
TopBar = bar;
BottomBar = bar - Length;
ConsolidationBar = bar;
}
}
if( Consolidation )
{
double[] rectangle = { TopBar, Top, TopBar, Bottom, BottomBar, Bottom, BottomBar, Top };
//if( ActivePositions.Count == 0 )
DrawPolygon( PricePane, Color.Blue, Color.FromArgb(30,Color.LightSteelBlue), LineStyle.Solid, 1, true, rectangle );
if( Range_[bar] > ConsolidationFactor * Range_[bar - Length] )
Consolidation = false;
if( bar > ConsolidationBar + ConsolidationTimeout )
Consolidation = false;
}
if (IsLastPositionActive)
{
SellAtTrailingStop(bar+1, LastPosition, Bottom);
}
else
{
if( Consolidation )
{
if( breakout ) // Breakout entry
{
if( Bottom > Lowest.Series(Low,Length)[bar - 12] )
if( BuyAtStop(bar+1, Top, "Breakout") != null )
Consolidation = false;
else
Consolidation = bar + 1 - ConsolidationBar < ConsolidationTimeout;
}
else // Pullback entry
{
if(( Close[bar] > Bottom ) && CrossOver(bar, RSI.Series(Close, Length), 30 )
&& Bottom > Lowest.Series(Low,Length)[bar - 12])
if( BuyAtMarket(bar+1, "Pullback") != null )
Consolidation = false;
else
Consolidation = bar + 1 - ConsolidationBar < ConsolidationTimeout;
}
}
}
}
}
}
}
Eugene (Gene Geren)
Wealth-Lab team
www.wealth-lab.com