Announcement

Collapse
No announcement yet.

Strategy.setStop

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

  • Strategy.setStop

    I see in Chris' help file:

    Strategy.setStop(30);
    Set a stop order to sell all shares if high of any bar at or after the current bar >= 30.

    I was wondering if anyone knows of a comparable command if attempting to exit from a short position?

    TIA,
    Greg

  • #2
    Greg
    Unless I am misunderstanding your question Strategy.setStop() can close out any active position.
    Alex

    Comment


    • #3
      Alex,

      Implicitly per the wording in the help file, as I read it, once the price reaches 30 or above in the example, any LONG position will be closed (~Strategy.doSell). What I am inquiring about is there an analogous command if am in a SHORT position, essentially doing a Strategy.doCover.

      Thanks,
      Greg

      Comment


      • #4
        Greg
        If you look above that example where the various strategy functions are explained you should find
        Strategy.setStop(dStop) -- sets a stop order; this will close out the active position if the stop order price is reached or exceeded
        Run the enclosed efs on a 5 minute chart for $INDU and you should see that on 8/27 at 11:50 EST it will go short at the close of that bar as per the condition. It will then close out the trade at 13:15 when the price reaches the defined stop price ie entry price+5. While short the background will be colored in yellow (see image)
        Alex

        PHP Code:
        function preMain() {
            
        setPriceStudy(true);
            
        setStudyTitle("setStop");
        }

        var 
        vStopPrice;

        function 
        main() {
           
            if(!
        Strategy.isShort()&&(getHour()*100)+getMinute()>1130&&getDay()==27&&close()<10189){
                
        Strategy.doShort("Short",Strategy.CLOSE,Strategy.THISBAR);
                
        vStopPrice close()+5;
            }

            if(
        Strategy.isShort()) 
                
        Strategy.setStop(vStopPrice);

            if(
        Strategy.isShort())
                
        setBarBgColor(Color.yellow);

            return ;

        Comment


        • #5
          Alex,

          You've even gone to the trouble of adding an illustration this time. Thanks, as always,

          Greg

          Comment

          Working...
          X