Log in to see Cloud of Tags

Wealth-Lab Wiki

Syntax

public CandleCode(Bars ds, string description)
public static CandleCode Series(Bars ds)

Parameter Description

Bars The symbol's Bars object

Description

In the March, 2001 issue of Stocks & Commodities magazine, Viktor Likhovidov shares a method of coding candlesticks. The CandleCode method expresses a candlestick value as a binary number, coding the body, upper shadow, and lower shadow in different "bits" of the number. One principal of binary numbers is that we can use the highest bit as a sign. In our adaptation this is what we do. Rather than adding 64 to the CandleCode value, we simply make black candles have negative values. This simplifies the code because we do not have to reverse the bits values when calculating black candlesticks.

On a technical note, we use 20 day Bollinger Bands with 0.5 Standard Deviations to determine whether the body and shadow sizes are small, medium or large. A value above the upper BBand indicates large, within the BBands medium, and below the lower BBand small. The ChartScript displays the candle body size, with corresponding Bollinger Bands, to illustrate this technique.

Example

The system presented, based on the sign-modified CandleCode, takes a 20 day simple moving average of CandleCode. When this value crosses below -25, an extreme reading occurs and a long position is established. When it crosses above 25 a short position is opened. The system exits at a 20% stop loss, and 15% profit target.
/* CandleCode System*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using WealthLab;
using WealthLab.Indicators;
using TASCIndicators;

namespace WealthLab.Strategies { public class MyStrategy : WealthScript { protected override void Execute() { // Create and Plot CandleCode with a 20 day SMA DataSeries cc = CandleCode.Series(Bars); DataSeries smaCC = SMA.Series(cc, 20); ChartPane cp = CreatePane(40, true, true); PlotSeries(cp, cc, Color.Blue, LineStyle.Histogram, 1); PlotSeries(cp, smaCC, Color.Red, LineStyle.Solid, 1); //Simple CandleCode trading system PlotStops(); for(int bar = 20; bar < Bars.Count; bar++) { if (IsLastPositionActive) { // 20% stop and 15% Profit Target Position p = LastPosition; if (p.PositionType == PositionType.Long) { if( ! SellAtStop(bar + 1, p, p.EntryPrice * 0.8, "Stop Loss") ) SellAtLimit(bar + 1, p, p.EntryPrice * 1.15, "Profit Target"); } else if( ! CoverAtStop(bar + 1, p, p.EntryPrice * 1.2, "Stop Loss") ) CoverAtLimit(bar + 1, p, p.EntryPrice * 0.85, "Profit Target"); } else { if( CrossUnder(bar, smaCC, -25) ) BuyAtMarket(bar + 1); else if( CrossOver(bar, smaCC, 25) ) ShortAtMarket(bar + 1); } } } } }

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.