in Search

Trailing stop help

Last post 04-02-2009, 19:58 by manatrader. 6 replies.
Sort Posts: Previous Next
  •  03-08-2009, 1:30 29130

    Trailing stop help

    In indicator builder, how would I program a basic trailing stop. In pseudo type language
    ( after buy signal put a stop 20 ticks below low of last 3 bars, then after 1 period put stop 20 ticks below the low)

    so in a uptrend, the stop would be 20 ticks below the low of the previous bar. hope this makes sense, any help would be appreciated



  •  03-08-2009, 3:13 29131 in reply to 29130

    Re: Trailing stop help

    Kraniv:
    In indicator builder, how would I program a basic trailing stop. In pseudo type language
    ( after buy signal put a stop 20 ticks below low of last 3 bars, then after 1 period put stop 20 ticks below the low)

    so in a uptrend, the stop would be 20 ticks below the low of the previous bar. hope this makes sense, any help would be appreciated


    First you need some code to identify when the buy signal occurred.  Later you might think you need some latching, but now let us just assume you don't.

    buy:={some logic goes here};

    Next, you need to find the lowest low on the bar when the entry was true, and then subtract 20 points:

    initialStop:=ValueWhen(1,buy,L)-20;

    You have defined the trailing component as the previous bar low minus 20:

    trailingStop:=Ref(L,-1)-20;

    This is where things start to get interesting because you haven't mentioned that the stop loss can only move in the favour of the trade, so you might consider something like this:

    stop:=if(barssince(buy)<=1,initialStop,highestsince(1,buy,trailingStop));


    Anyway, I hope you have enough ideas to formulate your own codes?

    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

  •  03-08-2009, 8:33 29132 in reply to 29131

    Re: Trailing stop help

    Thats great thanks, but I meant in Enhanced System Tester in MS. Can I use this code in there are it seperately defines, BUY,  SELL , SELL SHORT, BUY TO COVER etc..
  •  03-08-2009, 20:33 29133 in reply to 29132

    Re: Trailing stop help

    You can set fixed-point stop values (and other stop methods) in the EST Stops tab, otherwise you have to code the scenarios.

    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

  •  03-30-2009, 16:12 29313 in reply to 29133

    Re: Trailing stop help

    What are some good stop trail codes wabbit? I can't figure out how to make reference to the entry price. I want to try to place the stop info in the buy sell rules section of the strategy tester, instead of using the stops tab. Thanks
  •  03-31-2009, 20:55 29320 in reply to 29313

    Re: Trailing stop help

    manatrader:
    I can't figure out how to make reference to the entry price.


    entryPrice:=ValueWhen(1,Simulation.CurrentPositionAge=0,OPEN);



    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

  •  04-02-2009, 19:58 29328 in reply to 29320

    Re: Trailing stop help

    That is great thanks much!
View as RSS news feed in XML