Log in to see Cloud of Tags

Wealth-Lab Wiki

TASC 2016-04 | Trading Gap Reversals (Calhoun)

RSS

Traders' Tip text

The WealthScript code for Wealth-Lab for Ken Calhoun's "Trading Gap Reversals" technique is presented. Through parameter “sliders” at the bottom you can tune this system by modifying the parameters like gap percent, trailing stop value, and thresold for entry.

Image

Figure 1: The example trade in FTNT (Fortinet) in January 2016.

This strategy's code has been modified to trade only once a day, and exit as soon as gap is closed in addition to the other exits. It's advised that motivated users also experiment with replacing the fixed dollar variables with a fraction of ATR to make the system more adaptive. Additionally, rules can be inversed to explore the short side.

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

namespace WealthLab.Strategies { public class TradingGapReversals : WealthScript { private StrategyParameter gapPct; private StrategyParameter buyStp; private StrategyParameter sellStp;

public TradingGapReversals() { gapPct = CreateParameter("Gap %", 10, 1, 30, 1); buyStp = CreateParameter("Buy stop", 0.50, 0.10, 1.0, 0.1); sellStp = CreateParameter("Sell stop", 0.40, 0.10, 1.0, 0.1); }

protected override void Execute() { DataSeries trigger = Bars.Close * (1 - gapPct.Value / 100) >> 1; int cnt = 0; for (int bar = 1; bar < Bars.Count; bar++) { if( Date[bar].Date > Date[bar-1].Date ) cnt++; Position p = LastPosition; if (IsLastPositionActive) { double amount = p.MFEAsOfBar(bar) / p.Shares + p.EntryPrice - sellStp.Value; if(!SellAtStop(bar+1, p, p.EntryPrice - sellStp.Value, "Initial")) if(!SellAtTrailingStop(bar+1, p, amount, "Trailing")) SellAtLimit(bar+1, p, p.AutoProfitLevel, "Gap closed"); } else if (p == null || !p.Active && p.EntryBar < (bar - Bars.IntradayBarNumber(bar))) { if( cnt > 0 ) { int firstBarToday = bar - Bars.IntradayBarNumber(bar); int lastBarYesterday = firstBarToday - 1; bool priceFilter = (Close[firstBarToday] >= 20) && (Close[firstBarToday] <= 70); bool gap = (Open[firstBarToday] <= trigger[lastBarYesterday]); if( priceFilter && gap && Bars.IntradayBarNumber(bar) > 0 ) { if( BuyAtStop(bar + 1, Low[firstBarToday] + buyStp.Value ) != null ) LastPosition.AutoProfitLevel = Close[lastBarYesterday]; } } } } } } }

Eugene
Wealth-Lab team
www.wealth-lab.com

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.