in Search

code for Pullback system

Last post 06-11-2009, 14:33 by zigzag. 3 replies.
Sort Posts: Previous Next
  •  06-08-2009, 14:35 29879

    code for Pullback system

    Would anybody be interested in taking a crack at this system?  it seems very promising based on some testing i saw in an article...

    I came across a system called Pullback that has the following trading rules (assume today T):

    A. LE setup and rule

    A1. two previous closes (at bars T-2 and T-1) must have been two consecutive lower closes and

    A2. H of bar at T must be higher than H at T-1 and

    A3. close of bar at T must be higher than the 50-period EMA of closes for bar T

    A4. buy at next open if A1 and A2 and A3 are all true

    B. LX

    B1. sell at next open when position shows a profit at close

    B2. sell at a loss if the L falls below lowest low of the last two bars

    C. Position Size

    number of shares to trade = 4% * available equity / (entry price-stop-loss price [item B2 above])

     

    This is my attempt to code it in MS's EST:

    BUY:

    LEsetup1:=ref(c,-2)<ref(c,-3) and ref(c,-1)<rf(c,-2);

    LEsetup2:=h>ref(h,-1);

    LEsetup3:=c>mov(c,50,e);

    LE:=LEsetup1=1 and LEsetup2=1 and LEsetup3=1;

    ref(LE=1,-1)

    SELL:

    LXsetup1:=valuewhen(1,LE,ref(o,1))-c>0;

    LXsetup2:=l<(llv(l,2),-1);

    LX:=LXsetup1=1 or LXsetup2=1;

    ref(LX,-1)

     

    NOT SURE HOW TO CODE "availbale equity" but the basic equation for position size is:

    number of shares to trade = 4% * available equity / (valuewhen(1,LE,ref(o,1))-ref(llv(l,2),-1))

  •  06-08-2009, 21:57 29880 in reply to 29879

    Re: code for Pullback system

    Here is my first shot. Looks Ok. Color the spike yellow, that's the signal, The next is the profit
    potential. Looks like you can go long any time profit curve crosses to positive.


    a1:=(C<Ref(C,-1))*(Ref(C,-1)<Ref(C,-2));
    a2:=(H>Ref(H,-1));
    a3:=(C>Mov(C,50,E));
    a4:=a1*a2*a3;
    a5:=Ref(a4,-1)*O;
    {----------------------------------------}
    b1:=ValueWhen(1,(a5>0),O);
    b2:=If(Ref(C-b1,-1)>0,O-b1,0);
    b3:=If((L<Ref(L,-1))*(L<Ref(L,-2)),C-b1,0);
    {----------------------------------------}
    b4:=b2*(BarsSince(b3<>0)>BarsSince(b1>0));
    b5:=b3*(BarsSince(b2<>0)>BarsSince(b1>0));
    {----------------------------------------}
    If((a5>0),-(C/10),0);
    b2;
  •  06-09-2009, 11:30 29884 in reply to 29880

    Re: code for Pullback system

    Here's my first grab at the test code:

    Code:

          System Details
                ZigZag
                OptimizedNo
                Order BiasLong
                Portfolio BiasSingle
                Position Limit1

                Notes
                Equis Forum : http://forum.equis.com/forums/thread/29879.aspx

          
                Buy Order
                Order TypeMarket
                Order ExpirationGood Until Cancelled
                Entry Size Method# Of Units
                 
                Signal Formula
                ref(c,-2)<ref(c,-3) and ref(c,-1)<ref(c,-2) and h>ref(h,-1) and
                c>mov(c,50,e);
                
                Price Formula

                
                Entry Size Formula
                p1:=int(Simulation.AccountLongFundsAvailable * 0.04 * (Ref(OPEN,+1)
                - Ref(LLV(L,2),+1))); p2:=int(Simulation.AccountLongFundsAvailable /
                Ref(OPEN,+1)); min(p1,p2);
                 
                Strategic Delays
                # Bars on Tick Data0
                # Bars on Minute Data0
                # Bars on Daily Data0
                Sell Short Order
                Order TypeMarket
                Order ExpirationGood Until Cancelled
                Entry Size MethodUse Default Size
                 
                Signal Formula

                
                Price Formula

                
                Entry Size Formula
                100
                 
                Strategic Delays
                # Bars on Tick Data0
                # Bars on Minute Data0
                # Bars on Daily Data0

          
                Sell Order
                Order TypeMarket
                Order ExpirationGood Until Cancelled
                 
                Signal Formula
                CLOSE > extfml("forum.ref", OPEN,Simulation.CurrentPositionAge) OR L
                < Ref(LLV(L,2),-1)
                
                Price Formula

                
                Strategic Delays
                # Bars on Tick Data0
                # Bars on Minute Data0
                # Bars on Daily Data0
                Buy to Cover Order
                Order TypeMarket
                Order ExpirationGood Until Cancelled
                 
                Signal Formula

                
                Price Formula

                
                Strategic Delays
                # Bars on Tick Data0
                # Bars on Minute Data0
                # Bars on Daily Data0

           
                Stops
                      BreakEven Stop
                      PositionsNone
                      Floor Level0.00 %
                      Stop Loss
                      PositionsNone
                      Stop Value0.00 %

                      Trailing Stop
                      PositionsNone
                      Profit Risk Value0.00 %
                      Trailing Periods0.0
                      Inactivity Stop
                      PositionsNone
                      Minimum Value0.00 %
                      Periods0.0

                      Profit Target
                      PositionsNone
                      Target Value0.00 %


           
                Simulation Options

                General Options
                Points Only TestNo
                Initial Equity100000.
                Default Size10.00 % Of Available Equity
                Trade LongYes
                Trade ShortYes
                Optimization Results50

                Trade Execution Options
                Realistic Market PricesNo
                Buy PriceOpen
                Sell PriceOpen
                Sell Short PriceOpen
                Buy To Cover PriceOpen
                Delay To Open1
                 
                Slippage
                Buy0.00 %
                Sell0.00 %
                Sell Short0.00 %
                Buy to Cover0.00 %
                Broker Options
                Interest Rates
                Margin0.00 %
                Money Market0.00 %
                 
                Margin Requirement
                Long Initial100.00 %
                Long Maintenance0.00 %
                 
                Short Initial150.00 %
                Short Maintenance150.00 %
                 
                Commissions
                Entry$0.00 Per Transaction
                Exit$0.00 Per Transaction




    Hope this helps.

    wabbit Big Smile [:D]


    "The question of whether a computer can think is no more interesting than the question of whether a submarine can swim."
    Edsgar W. Dijkstra

     

    MS: 6.52 EOD, 7.x EOD, 8.0 PRO, 9.2 PRO w/QC, 10 PRO w/QC C, 11 PRO w/QC & MDK
    For custom MetaStock programming : http://www.wabbit.com.au
    My SkyPE status :
    My SkyPE account : wabbit.com.au

  •  06-11-2009, 14:33 29899 in reply to 29884

    Re: code for Pullback system

    johnl and Wabbit

    Thanks for you thoughts and codes.  Wabbit, I have optimized for the EMA period (prd=2) and backtested your code on daily SPY going back to 01/97, with the following changes:

    1. delay to open 0

    2. $10/trade

    3. 100% of available equity position size

    4. margin requirements 100%, 0%, 200% and 101%

    5. broker margin 3%, interest 0%

    Also, I think that

    p1:=int(Simulation.AccountLongFundsAvailable * 0.04 * (Ref(OPEN,+1)-Ref(LLV(L,2),+1)))

    should read

    p1:=int(Simulation.AccountLongFundsAvailable * 0.04 / (Ref(OPEN,+1)-Ref(LLV(L,2),+1)))

    no?

    Results show a system with a lot more winners than losers but average profit is just about 60% of average loss.  Despite upward sloping and extremely smooth equity curve and a lot of days out of the market, final equity is just a tad over 2x initial equity.  I wouldn't call it a winner but it might warrant some further research and tweaking.

    Many thanks for your help.

    ZigZag

View as RSS news feed in XML