Announcement

Collapse
No announcement yet.

Setting dynamic stops for backtesting

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Setting dynamic stops for backtesting

    In trying to test a trend system, I would like to set a dynamic stop loss level. In the case of going long, setting the stop at the low of the entry bar and then have the stop rise to the next bar low, if it is greater that current low and so on (and vice versa for a short position).

    I am not a EFS coder and the only option in the Wizard is to set a hard stop (actual price value) - which garauntees a loss on a trend following system as it never adjusts up/down if the trend is favourable to the position taken.

    Is there a way to achieve this in the wizard? Or if there is existing code that achieves this, would appreciate a link to that thread.

    Thanks in advance.

    Alex.

  • #2
    here are the basic rules...

    the basis of your system is simple.. Here is what I would do..

    You need to structure your code so that your stops are tested at the beginning of y our code. Like this...

    function main() {

    .. test current stops
    .. Adjust new stops

    ..test for entries

    }


    here is a better example..

    PHP Code:
    var nStopPrice null;


    function 
    main() {


      
    // test stops
      
    if ((Strategy.isLong()) && (low() <= nStopPrice)) {
        if (
    high() < nStopPrice) {
          
    Strategy.doSell("Lx Stop"Strategy.LIMITStrategy.THISBARStrategy.ALLopen());
        } else {
          
    Strategy.doSell("Lx Stop"Strategy.LIMITStrategy.THISBARStrategy.ALLnStopPrice);
        }
      }
      if ((
    Strategy.isShort()) && (high() >= nStopPrice)) {
        if (
    low() > nStopPrice) {
          
    Strategy.doCover("Sx Stop"Strategy.LIMITStrategy.THISBARStrategy.ALLopen());
        } else {
          
    Strategy.doCover("Sx Stop"Strategy.LIMITStrategy.THISBARStrategy.ALLnStopPrice);
        }
      }

    //  Adjust stop levels
      
    if ((Strategy.isLong()) && (low() > nStopPrice)) {
       
    nStopPrice low();
      }
      if ((
    Strategy.isShort()) && (high() < nStopPrice)) {
       
    nStopPrice high();
      }

    if (
    time to go long) {
      
    Strategy.doLong(...);
      
    nStopPrice low();
    }
    if (
    time to go short) {
      
    Strategy.doShort(...);
      
    nStopPrice high();
    }

     return;

    Brad Matheny
    eSignal Solution Provider since 2000

    Comment


    • #3
      Thanks very much Brad.

      Comment

      Working...
      X