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
These strategies were featured in the April, 2009 issue of Active Trader magazine.

Strategy 1 rules (basic moving-average crossover system):

  1. Cover short and go long the next day at the open when the 20-day SMA crosses above the 60-day SMA.
  2. Exit long and go shortthe next day at the open when the 20-day SMA crosses below the 60-day SMA.

Strategy 2 rules (crossover system filtered by Impulse system on daily data):

This system executes the basic strategy's rules according to the Impulse system's filter state, which indicates whether long or short trades should be taken.

The Impulse system filter states are green (long) and red (short):
  • Green: : The 13-day EMA and 12-26-9 MACD histogram are both higher than yesterday's values.
  • Red: : The 13-day EMA and 12-26-9 MACD histogram are both lower than yesterday's values.

  1. Buy next day at open when the 20-day SMA crosses above the 60-day SMA and the Impulse filter is green.
  2. Sell short next day at open when the 20-day SMA crosses below the 60-day SMA and the Impulse filter is red.
  3. Exit long next day at open when the 20-day SMA crosses below the 60-day SMA and the Impulse filter is not green.
  4. Cover short next day at open when the 20-day SMA crosses above the 60-day SMA and the Impulse filter is not red.

Strategy 2 code:


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

namespace WealthLab.Strategies { public class ImpulseFilteredCrossOver : WealthScript { private StrategyParameter paramEMA; private StrategyParameter paramSwitch; public ImpulseFilteredCrossOver() { paramEMA = CreateParameter("EMA", 13, 6, 18, 1 ); paramSwitch = CreateParameter("Filter Off/On", 1, 0, 1, 1 ); } protected override void Execute() { EMACalculation modern = EMACalculation.Modern; bool ImpulseBuy, ImpulseShort; int perEma = paramEMA.ValueInt; int FilterOn = paramSwitch.ValueInt;

DataSeries maFast = SMA.Series(Close, 20); DataSeries maSlow = SMA.Series(Close, 60); DataSeries ema = EMA.Series( Close, perEma, modern ); ema.Description = "EMA"; //DataSeries macd = MACD.Series( Close ); macd.Description = "MACD"; DataSeries macd = MACDEx_Histogram.Series( Bars, Close, 12, 26 ); macd.Description = "MACD-H"; // Plotting PlotSeries(PricePane,maFast,Color.Red,LineStyle.Solid,2); PlotSeries(PricePane,maSlow,Color.Green,LineStyle.Solid,2); PlotSeries( PricePane, ema, Color.DarkBlue, LineStyle.Solid, 2 ); ChartPane PaneMACD = CreatePane( 30, false, true ); PlotSeries( PaneMACD, macd, Color.Purple, LineStyle.Histogram, 2 ); SetBarColors( Color.Silver, Color.Silver ); HideVolume(); for(int bar = maSlow.FirstValidValue+1; bar < Bars.Count; bar++) { // Reset Impulse on each bar ImpulseShort = false; ImpulseBuy = false;

// Define Impulse condition ImpulseBuy = ( ema[bar] > ema[bar-1] ) & ( macd[bar] > macd[bar-1] ); ImpulseShort = ( ema[bar] < ema[bar-1] ) & ( macd[bar] < macd[bar-1] ); if( ImpulseBuy ) SetBarColor( bar, Color.Green ); if( ImpulseShort ) SetBarColor( bar,Color.Red );

if (IsLastPositionActive) { Position p = LastPosition; if( LastPosition.PositionType == PositionType.Long ) // Long exit { if( FilterOn == 1 ) { if( CrossUnder(bar, maFast, maSlow) & !ImpulseBuy ) SellAtMarket(bar + 1, p); } else if (CrossUnder(bar, maFast, maSlow)) SellAtMarket(bar + 1, p); } else // Short exit { if( FilterOn == 1 ) { if( CrossOver(bar, maFast, maSlow) & !ImpulseShort ) CoverAtMarket(bar + 1, p); } else if (CrossOver(bar, maFast, maSlow)) CoverAtMarket(bar + 1, p); } } else { if (CrossOver(bar, maFast, maSlow)) // Long entry { if( FilterOn == 1 ) // Impulse filter enabled { if( ImpulseBuy ) if( BuyAtMarket(bar + 1) != null ) LastPosition.Priority = RSI.Series( Close, 7 )[bar]; } else // Impulse filter disabled { if( BuyAtMarket(bar + 1) != null ) LastPosition.Priority = RSI.Series( Close, 7 )[bar]; } } else if (CrossUnder(bar, maFast, maSlow)) // Short entry { if( FilterOn == 1 ) // Impulse filter enabled { if( ImpulseShort ) if( ShortAtMarket(bar + 1) != null ) LastPosition.Priority = -RSI.Series( Close, 7 )[bar]; } else // Impulse filter disabled { if( ShortAtMarket(bar + 1) != null ) LastPosition.Priority = -RSI.Series( Close, 7 )[bar]; } } } } } } }

Strategy 3 rules (crossover system filtered by Impulse system on weekly data):

Impulse filter states:
  • Green: : The 13-week EMA and 12-26-9 MACD histogram are both higher than last week's values.
  • Red: : The 13-week EMA and 12-26-9 MACD histogram are both lower than last week's values.

  1. Buy at open next day when the 20-day SMA crosses above the 60-day SMA and the weekly Impulse filter is green.
  2. Sell short at open next day when the 20-day SMA crosses below the 60-day SMA and the weekly Impulse filter is red.
  3. Exit long at open next day when the 20-day SMA crosses below the 60-day SMA and the Impulse filter is not green.
  4. Cover short position at open next day when the 20-day SMA crosses above the 60-day SMA and the Impulse filter is not red.



Strategy 3 code:


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

namespace WealthLab.Strategies { public class WeeklyImpulseFilteredCrossOver : WealthScript { private StrategyParameter paramWeekly; private StrategyParameter paramSwitch; public WeeklyImpulseFilteredCrossOver() { paramWeekly = CreateParameter("Weekly EMA", 26, 12, 36, 2); paramSwitch = CreateParameter("Impulse Off/On", 1, 0, 1, 1 ); } protected override void Execute() { EMACalculation modern = EMACalculation.Modern; bool ImpulseBuy, ImpulseShort; int per = paramWeekly.ValueInt; int FilterOn = paramSwitch.ValueInt;

// For simplicity, allow operation on minute and daily scales only if( !( Bars.Scale == BarScale.Daily ) & !( Bars.Scale == BarScale.Minute )) return; // The GetWeeklyBar workaround SetScaleWeekly(); DataSeries CompBar = Close * 0; CompBar.Description = "Compressed Bar Number"; for (int bar = 0; bar < Bars.Count; bar++) // load the bar numbers CompBar[bar] = bar; DataSeries wEMA = EMA.Series( Bars.Close, per, modern ); wEMA.Description = "Weekly EMA"; //DataSeries wMACD = MACD.Series( Close ); wMACD.Description = "Weekly MACD"; DataSeries wMACD = MACDEx_Histogram.Series( Bars, Close, 12, 26 ); wMACD.Description = "MACD-H"; RestoreScale();

// Synch the bar numbers with the base time frame (here's your "function") DataSeries w_EMA = Synchronize( wEMA ); DataSeries w_MACD = Synchronize( wMACD ); DataSeries GetWeeklyBar = Synchronize(CompBar); DataSeries maFast = SMA.Series(Close, 20); DataSeries maSlow = SMA.Series(Close, 60); // Plotting PlotSeries( PricePane, w_EMA, Color.Blue, LineStyle.Solid, 2 ); PlotSeries( PricePane, maFast, Color.Red, LineStyle.Solid, 1 ); PlotSeries( PricePane, maSlow, Color.Green, LineStyle.Solid, 1 ); ChartPane PaneMACD = CreatePane( 30, false, true ); PlotSeries( PaneMACD, w_MACD, Color.Blue, LineStyle.Histogram, 2 ); HideVolume(); for(int bar = maSlow.FirstValidValue+1; bar < Bars.Count; bar++) { int wBar = (int)GetWeeklyBar[bar]; // Reset Impulse on each bar ImpulseShort = false; ImpulseBuy = false;

// Define Impulse condition ImpulseBuy = ( wEMA[wBar] > wEMA[wBar-1] ) & ( wMACD[wBar] > wMACD[wBar-1] ); ImpulseShort = ( wEMA[wBar] < wEMA[wBar-1] ) & ( wMACD[wBar] < wMACD[wBar-1] ); if( ImpulseBuy ) SetBarColor( bar, Color.LightGreen ); if( ImpulseShort ) SetBarColor( bar,Color.Red );

if (IsLastPositionActive) { Position p = LastPosition; if( LastPosition.PositionType == PositionType.Long ) // Long exit { if( FilterOn == 1 ) { if( CrossUnder(bar, maFast, maSlow) & !ImpulseBuy ) SellAtMarket(bar + 1, p); } else if (CrossUnder(bar, maFast, maSlow)) SellAtMarket(bar + 1, p); } else // Short exit { if( FilterOn == 1 ) { if( CrossOver(bar, maFast, maSlow) & !ImpulseShort ) CoverAtMarket(bar + 1, p); } else if (CrossOver(bar, maFast, maSlow)) CoverAtMarket(bar + 1, p); } } else { if (CrossOver(bar, maFast, maSlow)) // Long entry { if( FilterOn == 1 ) // Impulse filter engaged { if( ImpulseBuy ) if( BuyAtMarket(bar + 1) != null ) LastPosition.Priority = RSI.Series( Close, 7 )[bar]; } else // Impulse filter disabled { if( BuyAtMarket(bar + 1) != null ) LastPosition.Priority = RSI.Series( Close, 7 )[bar]; } } else if (CrossUnder(bar, maFast, maSlow)) // Short entry { if( FilterOn == 1 ) // Impulse filter engaged { if( ImpulseShort ) if( ShortAtMarket(bar + 1) != null ) LastPosition.Priority = -RSI.Series( Close, 7 )[bar]; } else // Impulse filter disabled { if( ShortAtMarket(bar + 1) != null ) LastPosition.Priority = -RSI.Series( Close, 7 )[bar]; } } } } } } }

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.