September 2005
TRADERS' TIPS

Here is this month's selection of Traders' Tips, contributed by various developers of technical analysis software to help readers more easily implement some of the strategies presented in this and other issues.

You can copy these formulas and programs for easy use in your spreadsheet or analysis software. Simply "select" the desired text by highlighting as you would in any word processing program, then use your standard key command for copy or choose "copy" from the browser menu. The copied text can then be "pasted" into any open spreadsheet or other software by selecting an insertion point and executing a paste command. By toggling back and forth between an application window and the open Web page, data can be transferred with ease.

This month's tips include formulas and programs for:

  TRADESTATION: Shorting Moving Average Pullbacks
  METASTOCK: Shorting Moving Average Pullbacks
  WEALTH-LAB: Shorting Moving Average Pullbacks
  ESIGNAL: Shorting Moving Average Pullbacks
  NEUROSHELL TRADER: Shorting Moving Average Pullbacks
  AMIBROKER: Shorting Moving Average Pullbacks
  INVESTOR/RT: Shorting Moving average pullbacks
  NEOTICKER: Shorting Moving Average Pullbacks
  TECHNIFILTER PLUS: Shorting Moving Average Pullbacks
  AIQTRADINGEXPERT PRO
or return to September 2005 Contents


TRADESTATION: Shorting Moving Average Pullbacks

Steve Palmquist's article in this issue, "Shorting Moving Average Pullbacks," reviews a shorting technique that can be applied to a list of stocks. The technique uses a combination of signals: bars under a moving average, the existing trend, the existence of a "pullback" to the moving average, a trigger condition (lower low), a volume threshold, and a criterion based on stochastics. The article assumes a three-day holding period for each short trade. Each condition has been parameterized to allow customization. Cumulative utility is summarized in the column "Activity." When a signal takes place in real time, it is noted in the "Action" column.
 

FIGURE 1: TRADESTATION, IBM. Here is a sample daily line chart of closing prices and RadarScreen. The RadarScreen shows stocks sorted by cumulative price activity based on Steve Palmquist's ideas presented in his article this issue. This chart shows the signal displayed on a chart of IBM stock, as described in the article.


To download this code, search for the file _Mas_Short.Eld in the Support Center at TradeStation.com.
 

Indicator: __MAS_Short-Radar
inputs:
 HighestLen( 5 ),
 LowestLen( 20 ),
 LowerClosesLen( 20 ),
 PullBackLen( 35 ),
 Stoch( SlowD( 14 ) ),
 NotAboveLen( 15 ),
 VolumeThreshold( 200000 ),
 MinimumPrice( 15 ),
  CloseToRange( 0.01 ),
 HoldPeriod( 3 ) ;
variables:
 HighestHigh( 0 ),
 LowestLow( 0 ),
 LowerCloses( false ),
 PullbackMAS( 0 ),
 CloseAbovePullbackMA( 0 ),
 NotAbovePullbackMA( false ),
 ClosePullbackMA( false ),
 SetupA( false ),
 MAPullbackShort( false ),
 PrevMAPullbackShort( false ),
 ShortTrigger( false ),
 StochOK( false ),
 SMAPS1( false ),
 PriceActivity( 0 ) ;
if BarType > 1 then { look for stocks in a downtrend }
 begin
 HighestHigh = Highest( Close, HighestLen ) ;
 LowestLow = Lowest( Close, LowestLen ) ;
 LowerCloses = HighestHigh <
  LowestLow[LowerClosesLen] ;
 { defining the PullbackLen (35-bar in article)
  simple moving average }
 PullbackMAS = Average( Close, PullBackLen ) ;
 { verify stock has not been above the PullbackLen MA
  in the last NotAboveLen trading sessions }
 if Close > PullbackMAS  then
  CloseAbovePullbackMA = 1
 else
  CloseAbovePullbackMA = 0 ;
 NotAbovePullbackMA =
   Summation( CloseAbovePullbackMA, NotAboveLen ) < 1 ;
  { looks for stocks that have pulled back to within
  (CloseToRange * 100)% of the PullbackLen MA }
 ClosePullbackMA =  ( PullbackMAS - Close ) <
  CloseToRange * Close ;
 { MA pullback set-up if uptrend and hasn't been
  below the PullbackLen MA but it has pulled back to
   within (CloseToRange * 100)% of the PullbackLen MA
  and daily volume is at least VolumeThreshold shares }
 SetupA = LowerCloses and NotAbovePullbackMA and
  ClosePullbackMA ;
 MAPullbackShort = SetupA and Volume >
  VolumeThreshold and Close > MinimumPrice ;
 
 { looks for the MA set up previous bar then the trigger on current bar }
 PrevMAPullbackShort = MAPullbackShort[1] ;
 
 { trigger is stock breaking below previous bar's low }
 ShortTrigger = Low < Low[1] ;
 
 { backtest conditions are the set up previous bar
  and the trigger on current bar }
 StochOK = Stoch[1] < 80 ;
 SMAPS1 = PrevMAPullbackShort and ShortTrigger and
  StochOK ;
 if SMAPS1[4] then
  PriceActivity = PriceActivity
  + ( Close[HoldPeriod] - Close ) ;
 if GetAppInfo( aiApplicationType ) = 2
  { RadarScreen }
  then
   begin
  Plot1( PriceActivity, "Activity" ) ;
  Plot2( PullbackMAS, "Avg" ) ;
  if SMAPS1 then
   Plot3( "Short", "Action" ) ;
  end ;
 end ;


-Mark Mills
TradeStation Securities, Inc.
A subsidiary of TradeStation Group, Inc.
www.TradeStationWorld.com

GO BACK


METASTOCK: Shorting Moving Average Pullbacks

Steve Palmquist's article in this issue, "Shorting Moving Average Pullbacks," introduces a new trading system. The MetaStock code and instructions for entering this system are as follows:

1. Select Tools > the Enhanced System Tester.
2. Click "New."
3. Enter a name for the system.
4. Select the "Sell Short Order" tab and enter the following formula:
voltarget:=2000;
setup:= HHV( C, 5 ) < Ref( LLV( C, 20 ), -20 ) AND
Ref( Sum( C < Mov( C, 35, S ), 15 ) = 15, -1 ) AND
( ( Mov( C, 35, S ) - C ) < ( 0.01 * C ) ) AND
C > 15 AND Mov( V, 50, S ) > voltarget;
Ref( setup, -1 ) AND
Stoch( 5, 3 ) < 80 AND
L < Ref( L, -1 )


5. Select the "Buy to Cover Order" tab and enter this formula:
 

 Simulation.CurrentPositionAge >= 3


6. Click "OK" to close the system editor.


Note the first line of the "sell short order" formula: The value of 2,000 is correct for locally stored data. If you are using online data, you will need to change this to 200,000 to get the correct results.

-William Golson
Equis International (A Reuters Company)
801 265-9998, www.MetaStock.com
GO BACK

WEALTH-LAB: Shorting Moving Average Pullbacks

In this issue, Steve Palmquist presents a moving average short system to use in declining markets. In the April 2005 issue of Stocks & Commodities, he presented an article on trading moving average pullbacks (Maps) in bullish environments. That article was the focus of Traders' Tips for that issue.

With some small modifications, we converted the Wealth-Lab ChartScript we created for the Maps system for the April 2005 issue to use most of the rules specified by Palmquist for shorting. Specifically, we elected to exclude the [close]>15 condition in the trading rules. Analysts should be cautious of such rules when backtesting, and here's why.

Apple Computer Inc. (AAPL), which traded above and below $20 during 2000-2001, subsequently rose to above $90 and split two-for-one. After back-adjusting the data for the split, AAPL would have appeared to trade around $10 in 2000-2001 and consequently would be removed from backtesting consideration, when actually it was a valid candidate had you been trading this system at that time. A few more examples of this situation from the Nasdaq 100 include ADSK, AMAT, and APOL, and those are just the A's!

As in the prior Maps ChartScript, we used indicators from Wealth-Lab's Code Library to calculate and draw logarithmic trendline projections of the two most recent 8% peaks/troughs in the specified index series. Using the relationship between the index's closing price and the trendline projections, the IsBear function returns "true" if the market is in a bearish phase, which is used as an enabling condition for Mas. You can quickly identify the bearish periods in the ChartScript window shown in Figure 2.
 


Figure 2: WEALTH-LAB, Moving Average Pullbacks SHORT SYSTEM. The Nasdaq price series and trendline projections are plotted in the upper pane, where a red background indicates a bearish market phase. Likewise, a blue background in the price pane shows that a stock's closing price series has been below its moving average for 15 bars.
WealthScript code:
{$I 'VolumeColor'}
{$I 'TrendLinePeaks'}
{$I 'TrendLineTroughs'}
var IDX: string = '.IXIC';
const bLOG = true;
const REV = 8;
var Bar, yBar, Start, p, hSMA, hAvgVol, hProximity, IDXPane: integer;
var hPeakPrj, hTrghPrj, hIDX_C, hIDX_L: integer;
var Setup, Falling, CloseToPullback, bDownTrend: boolean;
{ Returns true if market in Bear phase w.r.t. trend lines }
function IsBear( Bar: integer ): boolean;
begin
var TroughTransition, AbovePeakTrend, BelowTrghTrend: boolean;
  TroughTransition := TroughBar( Bar, hIDX_L, REV ) <> TroughBar( Bar - 1, hIDX_L, REV );
  AbovePeakTrend := @hIDX_C[Bar] > @hPeakPrj[Bar];
  BelowTrghTrend := @hIDX_C[Bar] < @hTrghPrj[Bar];
 
  if not AbovePeakTrend and BelowTrghTrend then
    bDownTrend := true
  else if AbovePeakTrend and ( ROC( Bar, hPeakPrj, 1 ) < 0 ) then
    bDownTrend := false
  else if not TroughTransition then
    if not BelowTrghTrend and ( ROC( Bar, hTrghPrj, 1 ) > 0 ) then
      bDownTrend := false
    else if CrossUnder( Bar, hIDX_C, hTrghPrj ) then
      bDownTrend := true;
  Result := bDownTrend;
end;
SetPrimarySeries( IDX );
hIDX_C := #Close;
hIDX_L := #Low;
hPeakPrj := TrendLinePeaksSeries( #High, REV, bLOG );
hTrghPrj := TrendLineTroughsSeries( #Low, REV, bLOG );
RestorePrimarySeries;
{ MAS System indicators req'd for setup }
hAvgVol := SMASeries( #Volume, 20 );
hSMA := SMASeries( #Close, 35);
hProximity := SubtractSeries( hSMA, #Close );
{ Plotting }
PlotSeriesLabel( hSMA, 0, #Teal, #Thin, 'SMA(Close,35)' );
PlotSeriesLabel( hAvgVol, 1, #Blue, #Thin, 'SMA(Volume,20)' );
IDXPane := CreatePane( 100, true, true );
SetLogScale( IDXPane, bLOG );
PlotSymbol( IDX, IDXPane, #Gray, #Candle );
DrawLabel( IDX, IDXPane );
PlotSeries( hPeakPrj, IDXPane, #Green, #Dotted );
PlotSeries( hTrghPrj, IDXPane, #Fuchsia, #Dotted );
{ Execute MAS Trading System }
InstallTimeBasedExit( 3 );
Start := Round( Max( Max( 30, TrendPeaksValidBar ), TrendTroughsValidBar ) );
for Bar := Start to BarCount - 1 do
begin
  ApplyAutoStops( Bar );
{ Lt. blue background if 15 days below SMA }
  if Lowest( Bar, hProximity, 15 ) >= 0 then
    SetPaneBackgroundColor( Bar, 0, #BlueBkg );
  if IsBear( Bar ) then
  begin
    SetPaneBackgroundColor( Bar, IDXPane, #RedBkg );
  { Yesterday's conditions }
    yBar := Bar - 1;
    Setup := ( Lowest( yBar, hProximity, 15 ) >= 0 )
         and ( @hAvgVol[yBar] > 200000 );
    Falling := Highest( yBar, #Close, 5 ) < Lowest( yBar - 20, #Close, 20 );
    CloseToPullback := @hProximity[yBar] < 0.01 * PriceClose( yBar );
    if Setup and Falling and CloseToPullback and ( StochK( Bar, 1 ) < 80 ) then
      if PriceLow( Bar ) < PriceLow( yBar ) then  // Today's trigger
        ShortAtMarket( Bar + 1, '' );
  end;
end;


-Robert Sucher
www.wealth-lab.com

GO BACK

eSignal: Shorting Moving Average Pullbacks

For this month's article by Steve Palmquist, "Shorting Moving Average Pullbacks," we've provided the formula as a downloadable file, named "Smaps.efs." This study is similar to the one presented in Palmquist's April 2005 article in S&C, "Trading Moving Average Pullbacks." As we did with that study, which was provided in the downloadable file named "Maps.efs," we've included the logic for taking long positions as well.

This logic is a combination of the rules used from the April issue as well as the specifics from this issue's article. The study does have the ability to leave out the long entries by setting the "Enable Long Positions" formula parameter to "false" through the Edit Studies option, if you wish to run backtests on only short positions. There's also an option to enable/disable short positions.
 


Figure 3: eSIGNAL, Moving Average Pullbacks SHORT SYSTEM


The study is coded as a backtesting study to generate the report with the Strategy Analyzer (Tools->Back Testing). It also has parameters to further optimize the study based on the market and interval of the Advanced Chart. You may adjust the moving average length, moving average source, moving average type, pullback percent envelope, long entry trend bars (number of bars to define a long trend), short entry trend bars (number of bars to define a short trend), average volume filter (level for x-period average volume), average volume periods, price filter (for chart symbol), stochastic K long filter, stochastic K short filter, stochastic K length, stochastic K smoothing, and stochastic D length.

To discuss this study or download a complete copy of the formula, please visit the Efs Library Discussion Board forum under the Bulletin Boards link at https://www.esignal.com

Download Smaps.efs or copy and paste the following code.
 

/***************************************
Provided By : eSignal (c) Copyright 2005
Description:  Shorting Moving Average Pullback System - by Steve Palmquist

Version 1.0  7/8/2005

Notes:
September 2005 Issue - "Different Systems for Different Markets -
                        Shorting Moving Average Pullbacks"

Formula Parameters:                 Defaults:
MA Length                           35
MA Source                           Close
MA Type                             SIMPLE
Pullback Percent Envelope           1%
Enable Long Positions               true
Enable Short Positions              true
Long Entry Trend Bars               30
Short Entry Trend Bars              15
Average Volume Filter               200000
Average Volume Periods              10
Price Filter                        15
Stochastic K Long Filter            20
Stochastic K Short Filter           80
Stochastic K Length                 14
Stochastic K Smoothing              1
Stochastic D Length                 3
***************************************/

function preMain() {
    setPriceStudy(true);
    setStudyTitle("Short Moving Average Pullback System ");
    setShowTitleParameters(false);
    setCursorLabelName("+1\%", 0);
    setCursorLabelName("MA", 1);
    setCursorLabelName("-1\%", 2);
    setCursorLabelName("Trend Count", 3);
    setDefaultBarFgColor(Color.blue, 0);
    setDefaultBarFgColor(Color.maroon, 1);
    setDefaultBarFgColor(Color.blue, 2);
    setDefaultBarFgColor(Color.grey, 3);
 
    var fp1 = new FunctionParameter("nLength", FunctionParameter.NUMBER);
        fp1.setName("MA Length");
        fp1.setDefault(35);
        fp1.setLowerLimit(1);
    var fp2 = new FunctionParameter("sSource", FunctionParameter.STRING);
        fp2.setName("MA Source");
        fp2.setDefault("Close");
        fp2.addOption("Open");
        fp2.addOption("High");
        fp2.addOption("Low");
        fp2.addOption("Close");
        fp2.addOption("HL/2");
        fp2.addOption("HLC/3");
        fp2.addOption("OHLC/4");
    var fp3  = new FunctionParameter("type", FunctionParameter.STRING);
        fp3.setName("MA Type");
        fp3.setDefault("Simple");
        fp3.addOption("Simple");
        fp3.addOption("Exponential");
        fp3.addOption("Weighted");
        fp3.addOption("Volume Weighted");
    var fp4 = new FunctionParameter("nPBpercent", FunctionParameter.NUMBER);
        fp4.setName("Pullback Percent Envelope");
        fp4.setDefault(1);
        fp4.setLowerLimit(0);
        fp4.setUpperLimit(100);
    var fp5 = new FunctionParameter("bLong", FunctionParameter.STRING);
        fp5.setName("Enable Long Positions");
        fp5.setDefault("true");
        fp5.addOption("true");
        fp5.addOption("false");
    var fp6 = new FunctionParameter("bShort", FunctionParameter.STRING);
        fp6.setName("Enable Short Positions");
        fp6.setDefault("true");
        fp6.addOption("true");
        fp6.addOption("false");
    var fp7 = new FunctionParameter("nLTrendBars", FunctionParameter.NUMBER);
        fp7.setName("Number of Bars for Long Trend");
        fp7.setDefault(30);
        fp7.setLowerLimit(1);
    var fp8 = new FunctionParameter("nSTrendBars", FunctionParameter.NUMBER);
        fp8.setName("Number of Bars for Short Trend");
        fp8.setDefault(15);
        fp8.setLowerLimit(1);
    var fp9 = new FunctionParameter("nVFilter", FunctionParameter.NUMBER);
        fp9.setName("Average Volume Filter");
        fp9.setDefault(200000);
        fp9.setLowerLimit(0);
    var fp10 = new FunctionParameter("nAvgVolLen", FunctionParameter.NUMBER);
        fp10.setName("Average Volume Periods");
        fp10.setDefault(10);
        fp10.setLowerLimit(1);
    var fp11 = new FunctionParameter("nPFilter", FunctionParameter.NUMBER);
        fp11.setName("Price Filter");
        fp11.setDefault(15);
        fp11.setLowerLimit(0);
    var fp12 = new FunctionParameter("nStochKLFilter", FunctionParameter.NUMBER);
        fp12.setName("Stochastic K Long Filter");
        fp12.setDefault(20);
        fp12.setLowerLimit(0);
    var fp13 = new FunctionParameter("nStochKSFilter", FunctionParameter.NUMBER);
        fp13.setName("Stochastic K Short Filter");
        fp13.setDefault(80);
        fp13.setLowerLimit(0);
    var fp14 = new FunctionParameter("nStochKLen", FunctionParameter.NUMBER);
        fp14.setName("Stochastic K Length");
        fp14.setDefault(14);
        fp14.setLowerLimit(1);
    var fp15 = new FunctionParameter("nStochKSmooth", FunctionParameter.NUMBER);
        fp15.setName("Stochastic K Smoothing");
        fp15.setDefault(1);
        fp15.setLowerLimit(1);
    var fp16 = new FunctionParameter("nStochDLen", FunctionParameter.NUMBER);
        fp16.setName("Stochastic D Length");
        fp16.setDefault(3);
        fp16.setLowerLimit(1);
}

var bVersion = null;
var study = null;   // MA
var study2 = null;  // Daily Avg Volume
var study3 = null;  // StochK
var bt = true;      // back testing on
var nTrendCntr = 0;
var nTrendCntr1 = 0;// previous bar's nTrendCntr
var sSide = 0;      // 1 = obove MA, -1 = below MA
var sSide1 = 0;     // previous bar's sSide
var bInit = true;   // initialization routine.
var bLongTrigger = false;
var bShortTrigger = false;
var vPosition = 0;  // 0 = no position, 1 = long, -1 = short
var nTriggerIndex = null;
var nBarCount = 0;  // bar counter for exit strategy

function main(nLength, sSource, type, nPBpercent, bLong, bShort,
              nLTrendBars, nSTrendBars, nVFilter, nAvgVolLen, nPFilter,
              nStochKLFilter, nStochKSFilter, nStochKLen, nStochKSmooth, nStochDLen) {

    if (bVersion == null) bVersion = verify();
    if (bVersion == false) return;

    var nState = getBarState();

    if (nState == BARSTATE_ALLBARS || bInit == true) {
        var xSource = close();
        switch (sSource) {
            case "Open" :       xSource = open(); break;
            case "High" :       xSource = high(); break;
            case "Low" :        xSource = low(); break;
            case "Close" :      xSource = close(); break;
            case "HL/2" :       xSource = hl2(); break;
            case "HLC/3" :      xSource = hlc3(); break;
            case "OHLC/4" :     xSource = ohlc4(); break;
            default :           xSource = close();
        }
        switch (type) {
            case "Simple" :             study = sma(nLength, xSource); break;
            case "Exponential" :        study = ema(nLength, xSource); break;
            case "Weighted" :           study = wma(nLength, xSource); break;
            case "Volume Weighted" :    study = vwma(nLength, xSource); break;
            default :                   study = sma(nLength, xSource);
        }
        study2 = sma(nAvgVolLen, volume());
        study3 = stochK(nStochKLen, nStochKSmooth, nStochDLen);
        if (close(0) > study.getValue(0)) sSide = 1;
        else sSide = -1;
        setCursorLabelName("+" + nPBpercent + "\%", 0);
        setCursorLabelName("-" + nPBpercent + "\%", 2);
        bt = true;
        bInit = false;
    }
 
    var bL = eval(bLong);
    var bS = eval(bShort);
    var vMA = study.getValue(0);
    var vMA1 = study.getValue(-1);
    if (vMA == null || vMA1 == null) return;
 
    if (nState == BARSTATE_NEWBAR) {
        nTrendCntr1 = nTrendCntr;
        nTrendCntr += 1;
        sSide1 = sSide;
        nBarCount += 1;
        if (getCurrentBarIndex() < 0) bt = true;
        else bt = false;
    }
 
    if (sSide == 1 && low(-1) < vMA1) sSide = -1;
    else if (sSide == -1 && high(-1) > vMA1) sSide = 1;
 
    if (nState == BARSTATE_NEWBAR && bLongTrigger == false && bShortTrigger == false) {
        if (study2.getValue(0) > nVFilter && close(0) >= nPFilter) {
            if (bL && nTrendCntr1 >= nLTrendBars && sSide1 == 1 && vPosition != 1
                    && study3.getValue(0) > nStochKLFilter) {
                if ( Math.abs((close(-1) - vMA1)/vMA1) <= (nPBpercent/100) ) {
                    bLongTrigger = true;
                    nTriggerIndex = getCurrentBarIndex();
                }
            } else if (bS && nTrendCntr1 >= nSTrendBars && sSide1 == -1 && vPosition != -1
                    && study3.getValue(0) < nStochKSFilter) {
                if ( Math.abs((vMA1 - close(-1))/vMA1) <= (nPBpercent/100) ) {
                    bShortTrigger = true;
                    nTriggerIndex = getCurrentBarIndex();
                }
            }
        }
    }
 
    // Position Exit
    if (vPosition != 0 && nBarCount == 3) {
        if (bL && vPosition == 1) {
            longExit();
        } else if (bS && vPosition == -1) {
            shortExit();
        }
    }
 
    // Position Entry
    if (getCurrentBarIndex() == nTriggerIndex) {
        if (bLongTrigger == true) {
            if (high(0) > high(-1)) longEntry();
        } else if (bShortTrigger == true) {
            if (low(0) < low(-1)) shortEntry();
        }
    } else {
        bLongTrigger = false;
        bShortTrigger = false;
    }

    if (vPosition == 1) setBarBgColor(Color.green);
    if (vPosition == -1) setBarBgColor(Color.red);
 
    if (sSide1 != sSide) {  // reset trend
        nTrendCntr = 0;
        //nSTrendCntr = 0;
    }
 
    return new Array(((nPBpercent/100)*vMA)+vMA, vMA, vMA-((nPBpercent/100)*vMA), nTrendCntr+"");
}

/***** Support Functions *****/

function verify() {
    var b = false;
    if (getBuildNumber() < 700) {
        drawTextAbsolute(5, 35, "This study requires version 7.9 or later.",
            Color.white, Color.blue, Text.RELATIVETOBOTTOM|Text.RELATIVETOLEFT|Text.BOLD|Text.LEFT,
            null, 13, "error");
        drawTextAbsolute(5, 20, "Click HERE to upgrade.@URL=https://www.esignal.com/download/default.asp",
            Color.white, Color.blue, Text.RELATIVETOBOTTOM|Text.RELATIVETOLEFT|Text.BOLD|Text.LEFT,
            null, 13, "upgrade");
        return b;
    } else {
        b = true;
    }
 
    return b;
}

function longEntry() {
    bLongTrigger = false;
    vPosition = 1;
    setBarBgColor(Color.green);
    var nEntryPrice = high(-1);
    if (open(0) > nEntryPrice) nEntryPrice = open(0);
    if (bt == true) {
        Strategy.doLong("Buy", Strategy.LIMIT, Strategy.THISBAR, null, nEntryPrice);
    }
    nBarCount = 0;
    return;
}

function shortEntry() {
    bShortTrigger = false;
    vPosition = -1
    setBarBgColor(Color.red);
    var nEntryPrice = low(-1);
    if (open(0) < nEntryPrice) nEntryPrice = open(0);
    if (bt == true) {
        Strategy.doShort("Short", Strategy.LIMIT, Strategy.THISBAR, null, nEntryPrice);
    }
    nBarCount = 0;
    return;
}

function longExit() {
    vPosition = 0;
    //if (bt == true) Strategy.doSell("Long Stop", Strategy.MARKET, Strategy.THISBAR);
    if (bt == true) Strategy.doSell("Long Stop", Strategy.CLOSE, Strategy.THISBAR);
    return;
}

function shortExit() {
    vPosition = 0;
    //if (bt == true) Strategy.doCover("Short Stop", Strategy.MARKET, Strategy.THISBAR);
    if (bt == true) Strategy.doCover("Short Stop", Strategy.CLOSE, Strategy.THISBAR);
    return;
}
 

 
 
 
 

-Jason Keck
eSignal, a division of Interactive Data Corp.
800 815-8256, www.esignalcentral.com
GO BACK

NEUROSHELL TRADER: Shorting Moving Average Pullbacks

The indicators described by Steve Palmquist in his moving average short (Mas) system can be easily recreated using NeuroShell Trader's point-and-click indicator wizard. To create the indicators, select "New Indicator ..." from the Insert menu and proceed through the Indicator Wizard to create the following:
 

Pullback MAS
  SimpleMovAvg (close, 35)
Lower Closes
   A < B (Max Close, 5), (Lag(Min(Close,20)20))
CloseAbovePullbackMA
   If Close > PullbackMAS, 1, 0
NotAbovePullbackMA
   If sum (CloseAbovePullbackMA,15) < 1
ClosePullbackMA
   Sub (PullbackMAS,Close)  <  (0.01 * Close)
setupA
   And3 (all 3 are true):  LowerCloses, NotAbovePullbackMA, and ClosePullbackMA
MApullbackShort
   And3 (all 3 are true):  setupA, Volume > 200000, and Close > 15
Short Trigger
   Low < Lag(Low,1)
StochOK
   Lag (Stoch#K,21),1  <  80
MAPullbackShortYesterday
   Lag(MaPullbackShort,1) = 1
SMAPS1
   And3 (all 3 are true):  MAPullbackShortYesterday, ShortTrigger, and StochOK
Figure 4: NEUROSHELL TRADER, Moving Average Pullbacks SHORT SYSTEM. Here's an example of the moving average short (mas) trading system implemented in NeuroShell Trader.
 


To recreate Palmquist's Mas trading system, select "New Trading Strategy ..." from the Insert menu and enter the following entry and exit conditions in the appropriate locations of the Trading Strategy Wizard:
 

Generate a buy short MARKET order if ANY of the following are true:
SMAPS1
Generate a short exit order if any of the following are true:
Bars Since Fill = 3


If you have NeuroShell Trader Professional, you can also choose whether any of the indicator parameters should be optimized. After backtesting the trading strategy, use the "Detailed Analysis ..." button to view the backtest and trade-by-trade statistics for the Palmquist Mas trading system.

-Marge Sherald, Ward Systems Group, Inc.
301 662-7950, sales@wardsystems.com
www.neuroshell.com
GO BACK

AMIBROKER: Shorting Moving Average Pullbacks

In "Shorting Moving Average Pullbacks," Steve Palmquist presents a short-term system for trading declining markets. The article includes a sidebar with program code written in Eds language for use in AIQSystems' Trading Expert Pro. We have translated that Eds code directly into AmiBroker's Formula Language (AFL), given below. This code should be used in the "Automatic Analysis" window. In the Settings screen, the "Positions" combo box should be set to "short."
 

// Short-only MAS system
LowerCloses = HHV( Close, 5 ) < Ref( LLV( Close, 20 ), -20 );
PullbackMAS = MA( Close, 35 );
// check if close was never above MAS during last 15 bars
NotAbovePullbackMA = Sum( Close > PullbackMAS, 15 ) == 0;
ClosePullbackMA = ( PullbackMAS - Close ) < 0.01 * Close;
SetupA = LowerCloses AND NotAbovePullbackMA AND ClosePullbackMA;
MAPullbackShort = SetupA AND Volume > 200000 AND Close > 15;
MAPullbackShortYesterday = Ref( MAPullbackShort, -1 );
ShortTrigger = Low < Ref( Low, -1 );
StochOK = Ref( StochK() < 80, -1 );
Short = MAPullbackShortYesterday AND ShortTrigger AND StochOK;
Cover = 0; // exit only by stop
// trade on open with one bar delay
SetTradeDelays(1,1,1,1);
ShortPrice = CoverPrice = Open;
// apply 3-day stop
ApplyStop( stopTypeNBar, stopModeBars, 3, 0 );
- Tomasz Janeczko
AmiBroker.com
GO BACK

Investor/RT: Shorting Moving average pullbacks

The moving average pullback short signal that Steve Palmquist discusses in his article in this issue can be coded in Investor/RT RTL with the following expression:
 

MAX(CL, 5) < MIN(CL.20, 20)
 AND SUM(CL > MA, 15) = 0
 AND (MA - CL) < (0.01 * CL)
 AND VMA > 200000
 AND CL > 15
 AND FASTD < 80


This signal would be used as an entry/short rule within a trading system. The chart in Figure 5 shows this signal in a daily chart of Microsoft, using both a signal marker (red down arrow) and a paint bar/background indicator (purple highlights).
 


FIGURE 5: Investor/RT, SMAP. On this sample Investor/RT daily bar chart of Microsoft, the signal markers (red down arrows) are overlaid with the paint bar/background (purple highlights) indicators, representing the SMAP short signal.


To exit after three bars/days, as Palmquist discusses, use the following signal as an exit/cover rule:

BARSOPEN = 3
More information on the Investor/RT real-time language (RTL) can be found at:
https://www.linnsoft.com/tour/scanElems.htm
More information on the Investor/RT real trading systems and backtesting can be found at:
https://www.linnsoft.com/tour/tradingSystems.htm
 To learn more about the Investor/RT RTL language, visit https://www.linnsoft.com/tour/scanElems.htm.
-Chad Payne, Linn Software
www.linnsoft.com, info@linnsoft.com
GO BACK

NEOTICKER: Shorting Moving Average Pullbacks

To apply in NeoTicker the concept presented in "Shorting Moving Average Pullbacks" by Steve Palmquist in this issue, two indicators are needed. The first indicator is the moving average short, which is a signal-generation indicator; it returns a "1" when all five moving average pullback criteria are met (Listing 1). The second indicator is the TASC shorting moving average pullbacks system, which is a system. It has one integer parameter position size, and it returns the current equity of the system (Listing 2).

When you add this trading system to a chart, you can evaluate system performance with an equity curve display and a detailed performance report for a single symbol. In addition, you can combine the pattern scanner in NeoTicker with a system or indicator to test the feasibility of the system and help identify trading opportunities on a group of stocks.

For example, you can find symbols that satisfy all five criteria for the current day from a list of symbols. First, create a pattern scanner using daily data on 250 days as base data. Then, at the Indicator tab, add Mas as an indicator to scan for greater than zero, since the moving average short indicator returns "1" when there is a short trigger signal. Figure 6 shows sample scanning results for the Nasdaq 100 with a short trigger.
 


Figure 6: NEOTICKER, Moving Average Pullbacks SHORT SYSTEM. Here are sample scanning results for the Nasdaq 100 with a short trigger.

You can also show equity results for a list of stocks. Create another pattern scanner and use daily bars for 250 days. At the "Indicator" tab, add the TASC shorting moving average pullbacks system. Check the "OP" option to list trading system calculation results in the pattern scanner window, and use "greater than zero" as your scanning criteria. The scanning results will list equity figures in descending order (Figure 7).

Figure 7: NEOTICKER, Moving Average Pullbacks SHORT SYSTEM. Check the OP option to list trading system calculation results in the pattern scanner window and use "greater than zero" as your scanning criteria. The scanning results will list equity figures in descending order.


A downloadable version of the indicators and install groups is available at the NeoTicker blog (https://blog.neoticker.com).
 

LISTING 1
LowerCloses := hhv(data1, 5) < llv(20, data1, 20);
'Verify stock has not been above the MA in the last DaySince number of bars
CloseAbovePullback := barssince(data1, "c>average(data1, 35)") > 15;
'Look for stocks that have pull back to within 1% of the 35MA
ClosePullbackMA := (average(dat1, 35)-c) < 0.01*c;
'Daily volume is at least 200,000 shares and price above 15
SetupA := LowerCloses>0 and CloseAbovePullback>0 and ClosePullbackMA>0;
MApullbackshort := SetupA>0 and v>200000 and c>15;
$ShortTrigger := l<l(1) and qc_stochastic(data1,15,3,3)<80;
plot1 := MApullbackshort(1)>0 and $ShortTrigger>0;
LISTING 2
$pos_size := param1;
'save the short position indication
pos_dir := if(openpositionshort>0, 1, 0);
Shortatmarket(MAS(data1)>0 and openpositionflat>0, $pos_size);
shortexitatmarket(summation(pos_dir, 5)>4, $pos_size);
plot1 := currentequity;
-Kenneth Yuen, TickQuest Inc.
www.tickquest.com
GO BACK

TECHNIFILTER PLUS: Shorting Moving Average Pullbacks

The following TechniFilter Plus strategy is based on "Shorting Moving Average Pullbacks" by Steve Palmquist in this issue.
 

NAME: MAS
TEST TYPE: equal
DATE RANGE:
POSITION LIMIT: none
ENTRY FEE:
EXIT FEE:
ISSUES:
INITIAL INVESTMENT:
FORMULAS-----------------
  [1] Date
  [2] LowerCloses
       (Cm5<Cn20y20)y1
  [3] CloseabovePullbackMa
       (((C>ca35)F15)<=1)y1
  [4] ClosePullBackMA
       ((CA35-C)<(0.01*c) & C<(Ca35*1.01))F3
  [5] DailVolandMinPrice
       (VA20>2000 & C>15)Y1
  [6] Trigger
       (L<LY1)
  [7] StochasticTest(5,3)
       [1]: (((C-LN&1)F&2/(HM&1-LN&1)F&2)*100)A&2
       [2]: ([1]<80)Y1
  [8] Open
       O
RULES-----------------
  r1: Short
       open short all on [8]
       at signal: OpenShort
      CurrentIndex >= 35 &Shares = 0 & [2] = 1 & [3]=1 & [4] >=
      1 & [4]=1 {& [5] = 1} & [6] = 1  & [7]=1
  r2: CloseShort
       cover short all on Close
       at signal: Covershort     CurrentIndex-EntryIndex=3


 Visit the TechniFilter Plus website to download this strategy backtest and other formulas.

-Benzie Pikoos, Brightspark
+61 8 9375-1178, sales@technifilter.com
www.technifilter.com
GO BACK

AIQTRADINGEXPERT PRO

Editor's note: For the Eds code for this system for use in AIQ Systems' Trading Expert Pro, see the sidebar on page 44, which was provided by Steve Palmquist with his article.

GO BACK

All rights reserved. © Copyright 2005, Technical Analysis, Inc.


Return to September 2005 Contents