Inverse Return To Mean System

DRAFT ONLY - SUBJECT TO CHANGE

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//P_InverseRTM  
//A SYSTEM BASED ON THE INVERSE OF A REVERSION TO MEAN  
//The one bar ROC of three moving averages is used to test for a bull trend 
 
ShortTermMA = ROC(MA(C,30),1);
MediumTermMA = ROC(MA(C,50),1);
LongTermMA = ROC(MA(C,100),1);  
 
Condition1 = ShortTermMA > 0 AND MediumTermMA > 0 AND LongTermMA > 0;  
 
Buy = Condition1;
Sell = 0;  
 
shape = Buy * shapeUpArrow + Sell * shapeDownArrow;
PlotShapes( shape, IIf( Buy, colorGreen, colorRed ), 0, IIf( Buy, Low, High ) );

This plots an up arrow for every bar where the 3 MA’s are moving up.

IRTM001 

Another way to do the same thing (the bull condition is meet a little earlier).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
//P_InverseRTM  
//A SYSTEM BASED ON THE INVERSE OF A REVERSION TO MEAN  
//The one bar ROC of three moving averages is used to test for a bull trend  
 
//ShortTermMA = ROC(MA(C,30),1);
//MediumTermMA = ROC(MA(C,50),1);
//LongTermMA = ROC(MA(C,100),1);  
 
ShortTermMA = MA(C,30);
MediumTermMA = MA(C,50);
LongTermMA = MA(C,100);  
 
Condition1 = ShortTermMA > MediumTermMA AND MediumTermMA > LongTermMA;  
 
Buy = Condition1;
Sell = 0;  
 
shape = Buy * shapeUpArrow + Sell * shapeDownArrow;
PlotShapes( shape, IIf( Buy, colorGreen, colorRed ), 0, IIf( Buy, Low, High ) );

IRTM002

Add a condition to screen for reversal bars (using the second MA method).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
//P_InverseRTM  
//A SYSTEM BASED ON THE INVERSE OF A REVERSION TO MEAN  
//The one bar ROC of three moving averages is used to test for a bull trend  
 
//ShortTermMAChange = ROC(MA(C,30),1);
//MediumTermMAChange = ROC(MA(C,50),1);
//LongTermMAChange = ROC(MA(C,100),1);  
 
ShortTermMA = MA(C,30);
MediumTermMA = MA(C,50);
LongTermMA = MA(C,100);  
 
ReverseTrend = Ref(L,-1) > Ref(ShortTermMA,-1) AND L < ShortTermMA;  
 
Condition1 = ShortTermMA > MediumTermMA AND MediumTermMA > LongTermMA;
Condition2 = ReverseTrend == 1;  
 
Buy = Condition2;// AND Condition2;
Sell = 0;  
 
shape = Buy * shapeUpArrow + Sell * shapeDownArrow;
PlotShapes( shape, IIf( Buy, colorGreen, colorRed ), 0, IIf( Buy, Low, High ) );

IRTM003

The first buy signal (marked by the green up arrow) meets the system criteria but the second violates the 50 MA rule and the third breaks the MA bias rule.

Changing back to the first MA method:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
//P_InverseRTM  
//A SYSTEM BASED ON THE INVERSE OF A REVERSION TO MEAN  
//The one bar ROC of three moving averages is used to test for a bull trend  
 
ShortTermMAChange = ROC(MA(C,30),1);
MediumTermMAChange = ROC(MA(C,50),1);
LongTermMAChange = ROC(MA(C,100),1);  
 
ShortTermMA = MA(C,30);
MediumTermMA = MA(C,50);
LongTermMA = MA(C,100);  
 
ReverseTrend = Ref(L,-1) > Ref(ShortTermMA,-1) AND L < ShortTermMA;  
 
//Condition1 = ShortTermMA > MediumTermMA AND MediumTermMA > LongTermMA;
Condition1 = ShortTermMAChange > 0 AND MediumTermMAChange > 0 AND LongTermMAChange > 0;  
Condition2 = ReverseTrend;  
 
Buy = Condition1 AND Condition2;
Sell = 0;  
 
shape = Buy * shapeUpArrow + Sell * shapeDownArrow;
PlotShapes( shape, IIf( Buy, colorGreen, colorRed ), 0, IIf( Buy, Low, High ) );

This restores the MA bias as per the rules.

IRTM004 

Adding a third condition excludes trend reversals that cross the 50 MA (on the close).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
//P_InverseRTM  
//A SYSTEM BASED ON THE INVERSE OF A REVERSION TO MEAN  
//The one bar ROC of three moving averages is used to test for a bull trend  
 
ShortTermMAChange = ROC(MA(C,30),1);
MediumTermMAChange = ROC(MA(C,50),1);
LongTermMAChange = ROC(MA(C,100),1);  
 
ShortTermMA = MA(C,30);
MediumTermMA = MA(C,50);
LongTermMA = MA(C,100);  
 
ReverseTrend = Ref(L,-1) > Ref(ShortTermMA,-1) AND L < ShortTermMA;  
 
//Condition1 = ShortTermMA > MediumTermMA AND MediumTermMA > LongTermMA;
Condition1 = ShortTermMAChange > 0 AND MediumTermMAChange > 0 AND LongTermMAChange > 0;
Condition2 = ReverseTrend;
Condition3 = C > MediumTermMA;  
 
Buy = Condition1 AND Condition2 AND Condition3;
Sell = 0;  
 
shape = Buy * shapeUpArrow + Sell * shapeDownArrow;
PlotShapes( shape, IIf( Buy, colorGreen, colorRed ), 0, IIf( Buy, Low, High ) );

IRTM005

That ’screens’ the charts for bars that meet the trade conditions (raw signal) - to turn it into a system it needs specific entry and exit rules (stops) - followed by testing and the addition of money management rules.

Moving up the chart, and looking at a longer period, the ’system’ produced two wins and one loss in 9 months of ‘trading’ one stock from the S&P500 (that isn’t a typical outcome and the author picked a favorable part of the chart.

IRTM006

1 Star2 Stars3 Stars4 Stars5 Stars (2 votes, average: 5 out of 5)
Loading ... Loading ...

MACD Trend System

I use a small setup criteria to scan for my stocks.

Settings:

MACD default,
I look for Histogram 4 down bars and 1 up bar for buy signal(I have the histogram set to red for down and blue for up so I can see
clearly).
MACD above Zero Line
RSI Above 30
This system is base on trend trading. Buying on pullback when the market continues its up trend.

To scan for MACD Trend setups:

1) Insert the following formula into a chart.

MACD004

2) Run a Scan in AA using S_MACDTrend with All symbols, n last days, n = 1 and Sync chart on select as the settings.

Stocks that meet the criteria will be reported in the Results list.

Note: Some variations of the setup rules can define signals that are quite rare and in small databases it is possible that there will be no setups on any given day (hence no stock will be reported by the scan).

MACD003

3) Click on any symbol in the Results pane to view the chart, for that symbol, in the background.

Note: In this example a training database, that only contains data up to 5/11/2007, was used.

  • Trading idea by protraderinc.
  • Comments and formula by Bill - WaveMechanic.

AmiBrokerYahooGroup message #116233  “MACD Histogram” http://finance.groups.yahoo.com/group/amibroker/message/116233

1 Star2 Stars3 Stars4 Stars5 Stars (2 votes, average: 5 out of 5)
Loading ... Loading ...

15 Day Performers Trading System

  • AmiBrokerYahooGroup message #116148
  • “Code Question: buy best performing ticker of last 15 days”

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//Buy on Friday the ticker symbol with the best performance of the last 15 trading days.
//Sell 5 weeks later
//It calculates the PositionScore on the Close at a thursday then it enters a trade at the Open on a friday AND closes this trade on the Open on a thrursday at least 22 bars after entry,
//You will need the latest Version of Amibroker for this because of the break function.
//Ed Pottasch and Samantha 
 
SetBarsRequired(10000,10000); 
SetOption("MaxOpenPositions", 1 ); 
PositionSize = -100; 
SetTradeDelays(0,0,0,0); 
PositionScore = IIf( Ref(ROC(C,15),-1) > 0, Ref(ROC(C,15),-1), 0); 
 
procedure sell_proc(Buy,Sellday){ 
 
global Sell; 
global SellPrice; 
SellPrice = 0; 
Sell = 0; 
 
// sell delay in bars 
selldelay = 22; 
 
for (i = 1; i < BarCount; i++) 
{ 
   if (Buy[ i ]) 
   { 
      for (j = i + selldelay; j < BarCount; j++)  
      { 
         if (Sellday[ j ]) 
         { 
            Sell[ j ] = 1; 
            i = j; 
            break; 
         } 
      } 
   } 
} 
} 
 
Buy = DayOfWeek() == 5; 
BuyPrice = O; 
 
sell_proc(Buy,DayOfWeek() == 4); 
SellPrice = O; 
 
SetChartOptions(0, chartShowDates); 
GraphXSpace = 5; 
Plot(C,"C",1,64); 
 
PlotShapes(IIf(Buy,shapeUpArrow,0),colorWhite, layer = 0, yposition = BuyPrice, offset = 0 );

The idea works. Backtesting, using the above code on, for instance, a stock list Nasdaq 100, will give positive results. The results get even better if you divide your money in smaller portions like for instance

SetBarsRequired(10000,10000);
SetOption(”MaxOpenPositions”, 10 );
PositionSize = -10;
SetTradeDelays(0,0,0,0);

However, since it is a long only system you will see that in a down market it will give bad results. So you can add additional constraints only to buy when the market is trending upwards, like:

  • Cf = Foreign(”!COMP”,”C”);
  • Buy = DayOfWeek() == 5 and Cf > MA(Cf,100);

Just adding some ideas. In an upmarket the system makes around 25% per year without slippage. But slippage for such a system will be very small to negligable and can easily be avoided. The idea needs to be fine tuned so it will make money in any market. Also 25% per year is too little in my opinion. Need systems > 60% before they get interesting in my opinion.

  • Trading idea by Samantha.
  • Code and comments by Ed Pottasch.

To meet and greet Ed and Samantha visit http://finance.groups.yahoo.com/group/amibroker/

ATTACHED FILES

15 Day Performers: b_15dayperformers.afl   (AFL formula file)

  • To download .afl files; right click on the link  and Save Target As ‘filename’ at Program Files/AmiBroker/Formulas/Custom to access them as formulas in the AmiBroker Charts list.
  • 1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
    Loading ... Loading ...

    KISS-001: Gap Trading

    This is the first in a series off KISS (keep it simple, stupid) trading ideas for you to play with. All system ideas presented here are unproven, unfinished, and may contain errors. They are intended to show possible patterns for further exploration. As always, you are invited to make comments and/or add your own ideas to this series.

    I prefer real-time systems that trade fast, are automated, and are devoid of traditional indicators. Preferably, they should have no optimizable parameters; however, I may not always be able to meet this objective. Not all systems will be ‘that’ simple; there will be some that use simple averaging or HHV/LLV type functions. The first system shown below is a copy of the demo system I use to develop Trade-Automation routines elsewhere on this site.

    Real-Time Gap-Trading.
    To see how this works, you should Backtest it on 1-minute data with a periodicity in the range of 5-60 minutes. Your first impression may be that these profits are simply due to an up market, however, the fact that Long and Short profits are about equal suggests there is more to it. Because 98% of all trades fall between 9:30 AM and 10:30 AM, this type of system is nice if you just want to trade a short time each day. This reduces risk with respect to market exposure and gives you more time to enjoy other activities.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    
    SetOption("CommissionMode",3);
    SetOption("CommissionAmount", 0.005);
    SetTradeDelays(0,0,0,0);
    Buy = O < Ref(L,-1);
    BuyPrice = O;
    Sell = L < Ref(L,-1);
    SellPrice = C;
    Short = O > Ref(H,-1);
    ShortPrice = O;
    Cover = H > Ref(H,-1);
    CoverPrice = C;
    E=Equity(1);
    Plot(C,"",1,128);
    if( PlotTriangles = ParamToggle("Triangles","HIDE|SHOW",1) )
    {
    PlotShapes(IIf(Buy, shapeSmallUpTriangle, shapeNone),5,0,BuyPrice,0);
    PlotShapes(IIf(Sell, shapeHollowDownTriangle, shapeNone),4,0,SellPrice,0);
    PlotShapes(IIf(Cover, shapeHollowUpTriangle, shapeNone),5,0,CoverPrice,0);
    PlotShapes(IIf(Short, shapeSmallDownTriangle, shapeNone),4,0,ShortPrice,0);
    }

    Backtesting this on the NASDAQ-100 watchlist (individual backtests, 15 min. Periodicity) gives the profits shown below for the period of 1 MAR 2007 to 17 AUG 2007. Ticker names are omitted to keep the chart compact; the chart simply shows a net profit bar for each ticker tested. Average exposure for this system is about 15%; hence, you may be able to trade portfolios to increase profits and smooth the equity curves. Be cautioned that in its raw form the drawdowns are unacceptable and that there may be volume restrictions for many tickers.

    kiss-001-netprofit.png

    Since this system has low exposure, it may be a candidate for market scanning and ranked portfolio trading. RARs would be an indication of the absolute maximum profits that could be obtained if one succeeded to increase exposure to near 100%. However, price movement from different tickers may be correlated, and trades from different tickers may overlap. If many tickers trade at the same time, it would be difficult to increase system exposure.

    kiss-001-rar.png
    Edited by Al Venosa.

    1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
    Loading ... Loading ...

    Introduction to Trading Systems - Ideas

    This is where you can share trading systems that are marginally profitable, i.e., those that should not be traded as they are but that show potential. Typically this would be a basic system that is profitable but experiences draw downs of 50%. Such systems can often be improved by adding Stops, Targets, Money Management, Portfolio techniques, etc. The reality is that while you may not have the expertise to make it work someone else may.

    Almost all of us find trading system ideas in books and magazines that we then code in AFL for evaluation. Some of these systems may have been around for many years while others are new ideas. After coding them, almost always, we are disappointed and chuck out the system (work!). Instead of throwing out your work you are invited to post the system here to give another developer a chance to fix it.

    You are invited to contribute as an author (requires registration) or in a comment to this post.

    1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
    Loading ... Loading ...