Announcement

Collapse
No announcement yet.

Current Position Help

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

  • Current Position Help

    I have a question about doing a trailing stop based on my position.

    I am attempting the following code, but EFS keeps calculating the variable perc as 0. Also, is there anyway to "debug" the formula step by step to check the values of each variable?

    //assuming price is populated from a previous run
    var price;
    var perc = null;
    perc = close() - price;
    perc = Math.abs(perc);
    var percentage = null;
    var percentage = (perc/price);
    ....
    if(close() >= v && !Strategy.isLong())
    {
    Strategy.doLong("Crossing Up",Strategy.MARKET, Strategy.THISBAR);
    price = close();
    }
    if(perc>0.02 && Strategy.isLong() == true)
    Strategy.doSell("2% Target",Strategy.MARKET, Strategy.THISBAR);

    EFS closes out every trade at the same price. Any help would be greatly appreciated,
    Anthony
    --------------------
    http://groupshares.com

  • #2
    possible solution...

    your code is doing this....

    entering the LONG trade at MARKET/THISBAR - that means you are entering on THISBAR at the OPEN...

    Then you are recording PRICE at the CLOSE of the entry bar.

    Perc = Math.abs(close() - price);

    Thus, Perc is always equal to the difference between the entry bar's close and the current close...

    Now, your exit strategy is...

    if(perc>0.02 && Strategy.isLong() == true)
    Strategy.doSell("2% Target",Strategy.MARKET, Strategy.THISBAR);

    because you are using Math.abs... any move 0.02 away from the entry bar close will generate this EXIT...

    From looking at your code, you want a 2% exit...

    I think you want this....

    PHP Code:
    //assuming price is populated from a previous run
    var price;
    var 
    perc null;
    perc close() - price;
    var 
    percentage null;
    var 
    percentage = (perc/price);
    ....
    if((
    close() >= v) && (!Strategy.isLong()))
    {
    Strategy.doLong("Crossing Up",Strategy.MARKETStrategy.THISBAR);
    price close();
    }
    if((
    percentage 0.02) && (Strategy.isLong()))
    Strategy.doSell("2% Target",Strategy.MARKETStrategy.THISBAR);

    // this is an example of a short signal..
    if((close() <= v) && (!Strategy.isShort()))
    {
    Strategy.doShort("Crossing Down",Strategy.MARKETStrategy.THISBAR);
    price close();
    }
    if((
    percentage < -0.02) && (Strategy.isShort()))
    Strategy.doCover("2% Target",Strategy.MARKETStrategy.THISBAR); 
    Brad Matheny
    eSignal Solution Provider since 2000

    Comment


    • #3
      Working a bit better, but.

      Thank you for the quick reply, but my question boils down to is there a function to get the purchase price of the security in the formula?

      i.e.: Strategy.getPurchaseValue("STOCK SYMBOL");
      --------------------
      http://groupshares.com

      Comment


      • #4
        well...

        no, not really... BUT....

        when you are using Strategy.MARKET, the entry price is the OPENing price of THISBAR or NEXTBAR....

        when you are using Strategy.LIMIT or Strategy.STOP, the entry price is the price you specify in your "Strategy" function on THISBAR or NEXTBAR...

        So, knowing this, you can easily identify the ENTRY PRICE for any "Strategy" trade you make...

        B
        Brad Matheny
        eSignal Solution Provider since 2000

        Comment

        Working...
        X