ScrewTurn

Active Trader Strategies API Community ChartStyles Community Commissions Community Components Community Indicators Community Providers Community Visualizers Knowledge Base Misc Optimizers PosSizers Standard Indicators TASC Traders Tips TASCIndicators Tutorial Videos
RSS

Navigation







Quick Search
»
Advanced Search »

PoweredBy

Description

Exiting after a certain number of profitable closes is a time-based technique designed to take profits when a market is moving in your direction. This long-only system combines simple trend and countertrend entry rules, each of which will be exited after different numbers of profitable closes. A weakness of this technique is that by factoring out price action, it does not adapt to changing market conditions.

Trend entry rule: Buy with a stop order on a breakout of the highest high of the past 20 days.
Countertrend entry rule: Buy with a limit order at the lowest low of the past 10 days.
Trend exit rule: Exit at the market on the next bar’s open when the number of profitable closes (excluding the entry bar) reaches 20.
Countertrend exit rule: Exit at the market on the next bar’s open when the number of profitable closes (excluding the entry bar) reaches eight.
Stop-loss: Protect each trade with a stoploss order 10-percent below the entry price.


Code


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

namespace WealthLab.Strategies { public class ProfitableCloses : WealthScript { protected override void Execute() { int bars, ProfitableClosesTrend, ProfitableClosesCounter; double stopLevel = 0; bars = 0; // Number of profitable closes, trend mode ProfitableClosesTrend = 20; // Number of profitable closes, counter-trend mode ProfitableClosesCounter = 8;

for(int bar = 20; bar < Bars.Count; bar++) { if (IsLastPositionActive) { stopLevel = ( LastPosition.PositionType == PositionType.Long) ? LastPosition.EntryPrice*0.9 : LastPosition.EntryPrice*1.1; ExitAtStop( bar+1, LastPosition, stopLevel, "Stop Loss" ); if( Bars.Close[bar] > LastPosition.EntryPrice ) bars++; if( LastPosition.EntrySignal == "Channel Breakout" ) { if( bars == ProfitableClosesTrend ) SellAtMarket( bar+1, LastPosition, "Profitable Closes.Trend" ); } else if( LastPosition.EntrySignal == "Counter Trend" ) { if( bars == ProfitableClosesCounter ) SellAtMarket( bar+1, LastPosition, "Profitable Closes.CounterTrend" ); } } else { if( ( BuyAtStop( bar+1, Highest.Series( Bars.High, 20 )[bar], "Channel Breakout" ) != null ) || ( BuyAtLimit( bar+1, Lowest.Series( Bars.Low, 10 )[bar], "Counter Trend" ) != null ) ) bars = 0; } } } } }

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.

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


ScrewTurn Wiki version 3.0.2.509. Some of the icons created by FamFamFam.