SP trend following System

Discussion in 'Strategy Building' started by acrary, Oct 14, 2002.

  1. Here is my correction:
    The only difference is that I made you .....BuyAtStop ( Bar + 1, .....). I think you need to know first if the ADX is below a certain level. Then on the next bar you can take the action. Else I think the code looks ok. If you have any further questions please let me know (I emailed you too). Oh, and I added the indicator.



    {Use 30 minute bars}

    var Bar: integer;

    for Bar := 20 to BarCount - 1 do

    if LastPositionActive then begin
    if (PositionLong( LastPosition )) and (ADX( Bar, 14 ) < 25) then
    SellAtStop(Bar + 1, Lowest( Bar, #Low, 5), LastPosition,'Sell');

    if LastPositionActive then begin
    if (PositionShort( LastPosition )) and (ADX( Bar, 14 ) < 25) then
    CoverAtStop(Bar + 1, Highest( Bar, #High, 5), LastPosition,'Cover');

    if not LastPositionActive then begin
    if ADX( Bar, 14 ) < 25 then begin
    BuyAtStop( Bar + 1, Highest( Bar, #High, 15),'Buy');
    ShortAtStop( Bar + 1, Lowest( Bar, #Low, 15),'Short');


    var ADXPane: integer;
    ADXPane := CreatePane( 100, true, true );
    PlotSeries( ADXSeries( 14 ), ADXPane, 009, #Thin );
    DrawLabel( 'ADX(14)', ADXPane );
    #51     Nov 29, 2002
  2. Since you guys are in sharing system code, here is one that I have published on the US page. Unfortunatly you can not test it there (yet), because you need intra day data, but for those who have WLD2. The system waits until the close of an intra day bar is above/below the first 30 minute range and buys on the next open. You can play arround with the time. I had great success trading this system with a few more filters on the german DAX.

    Have fun.


    var OD, HIGH30, LOW30: float;
    var N, NUM, BAR, COUNTER: integer;

    {this is a function that is available on the desktop}

    n := BarInterval;

    if n = 0 then
    ShowMessage( 'Works on intraday data only!' );

    function MarketPosition: integer;
    if not LastPositionActive then
    Result := 0
    else if PositionLong( LastPosition ) then
    Result := 1
    Result := -1;

    {setting the time interval (here 30 minutes) that i want to use}

    num := ( 30 / n ) - 1;

    for Bar := 20 to BarCount - 1 do

    {color the first 30 minutes in green}

    if BarNum( Bar ) <= num then
    SetBarColor( Bar, #Green );

    {the breginning of the day}

    if BarNum( Bar ) = 0 then

    {get the open of the day}

    OD := PriceOpen ( Bar );

    {set a variable called "counter" to zero on every beginning of the day}

    Counter := 0;

    if BarNum( Bar ) = num then

    {get the highest high and the lowest low after 30 minutes}

    High30 := Highest( Bar, #High, num + 1 );
    Low30 := Lowest( Bar, #Low, num + 1 );
    if LastBar( Bar ) then

    {exit on the last bar of the day}

    SellAtClose( Bar, LastPosition, 'Last Bar' )
    else if BarNum( Bar ) > num then

    {check wether the closing price of the previous day was greater then 5
    ( we dont want to trade penny stocks ). If it is smaller then five the
    script will coninue the upper loop until the closing price is above 5.}

    if PriceClose( Bar ) < 5 then

    {only if the Close is above five the next line will be executed}

    if PriceClose( Bar ) > High30 then
    {if the closing price is greater then the first 30 minute high the bars will
    be colored blue}

    SetBarColor( Bar, #Blue );

    {checking that we are not long already}

    if MarketPosition <> 1 then

    {if we are short then we want to cover}

    CoverAtMarket( Bar + 1, LastPosition, '' );

    {checking that we had no position on that day already, because we only want
    to take one position per day}

    if Counter = 0 then
    BuyAtMarket( Bar + 1, '' );

    {since we are getting into a position for the first time we put the counter
    to one}

    Counter := 1;

    {see wether the close is below the first 30 minute low}

    else if PriceClose( Bar ) < Low30 then

    {if it is the bars are now cloured red}

    SetBarColor( Bar, #Red );

    {make sure we arent already short}

    if MarketPosition <> -1 then

    {if we are long we exit the position}

    SellAtMarket( Bar + 1, LastPosition, '' );

    {make also sure we did not have any position during the day, because we only
    want to take one position per day}

    if Counter = 0 then

    {now we can go short}

    ShortAtMarket( Bar + 1, '' );

    {and set the counter to one}

    Counter := 1;

    PS: I dont know whether this has been discussed here already.
    #52     Nov 29, 2002
  3. Wow great stuff Volker. Thanks.

    Wealth-Lab sure seems like a great way to go. I like the intuitive language code. Here's what I want, so here's what I type.

    Now if I were only smart enough to figure out what I want..... :D

    Thanks again Volker.

    #53     Nov 29, 2002
  4. Yes, this has been discussed here at some length in the thread called 'The importance of simplicity'. So what's up with the intraday data for WL users? Can we get it any time soon?

    #54     Nov 29, 2002
  5. Entry Rules:

    1). Buy at the highest high for the past 15 bars.
    2). Sell at the lowest low for the past 15 bars.

    Exit Rules:

    1). Exit long trades at the lowest low for the past 5 bars.
    2). Exit short trades at the highest high for the past 5 bars.


    This strikes me as being a viable system only in trending markets. During choppy conditions, I think a trader would be chopped to pieces.

    I just plotted this strategy on the Q's for the past several months and it looks like a real dud.

    It does seem like it would work in clearly trending markets though. Agree??

    #55     Feb 5, 2003
  6. dbphoenix


    You may want to think about defining the relationship of the bars to each other. For example, should the 5 bars used for exiting longs be making lower lows? Does an inside bar count? Etc.

    #56     Feb 5, 2003
  7. acrary


    Yes, it's been a dud lately and it is totally dependent on the character of the market having a tendency to trend (as I warned in the second paragraph of the first post). It can go for months (or longer) while waiting for the market to establish a strong trend.

    I had originally intended to morph the system into a edge-based system to show how edge trading is done. I realized after a few posts that this is not the correct medium for doing how-to's lasting over a period of a couple of weeks.
    #57     Feb 11, 2003
  8. acrary,

    how come you don't think this is the correct medium? i wouldn't ask you to do something you don't want to do, but if you're willing, i'm sure there would be some of us with an interest; including myself.
    #58     Feb 11, 2003
    #59     Feb 11, 2003
  10. onelot


    I second that acrary. You're one of the few people on this board I have a lot of respect for and have learned a lot from. Anything you contribute would be hugely appreciated. :)

    #60     Feb 12, 2003