Announcement

Collapse
No announcement yet.

simple stop

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

  • simple stop

    1.
    How do I set simple stop based on % of my entry. Let's say 5% cut loss.
    2. Also how do I liquidate half position if gain is over 10%.
    Thanks

  • #2
    Hello osmar92,

    1. What I recommend is to create a global variable to store your stop price. In your formula, right after your entry calls such as Strategy.doLong(), set the value for the stop price. If for example you use the MARKET/NEXTBAR parameters for entry, the price will be the same as the open of the next bar. In back testing you can use open(1) to get this price. Then do the math accordingly.

    myStop = open(1) - (open(1) * 0.05)

    Add a section to your formula to test for the stops, which might look something like this.

    PHP Code:
    if (Strategy.isLong() && close(0) < myStop) {
        
    Strategy.doSell("sell"Strategy.CLOSEStrategy.THISBAR);

    Do the opposite using another global variable to track the profit target.

    2. You can check for the current holding using Strategy.getPositionSize() and then specify how many shares to sell using the lot size parameter in the .doSell() function.
    Jason K.
    Project Manager
    eSignal - an Interactive Data company

    EFS KnowledgeBase
    JavaScript for EFS Video Series
    EFS Beginner Tutorial Series
    EFS Glossary
    Custom EFS Development Policy

    New User Orientation

    Comment

    Working...
    X