Announcement

Collapse
No announcement yet.

Strategy function

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

  • Strategy function

    Strategy functions have two Fill Bar constants, Strategy.THISBAR and Strategy.NEXTBAR. How to I close a position after n bars after a position was opened?

  • #2
    dtrosty

    After you get filled, set a counter to 0.

    Then add one to the counter every time

    getBarState()==BARSTATE_NEWBAR

    Then when the counter is up to 'n bars', close the position.

    Comment


    • #3
      dloomos:

      Thank you for the suggestion. I tried it, and it does not work. I also tried getCurrentBarIndex(), and it does not work. What happens, if I want to close the position n=5 days after the position has been opened, the Analyzer counts n=5 buy signals after the original buy signal, and THEN closes the position. Which does not make sense.

      I would expect that this issue should have been resoved a long time ago, and it is a matter of finding somebody who has developed a working a strategy which holds a position for several days.

      dtrosty

      Comment


      • #4
        dtrosty
        Actually David's suggestion does work but you probably did not implement it correctly. Attached you can find an example showing what David suggested
        You may also want to go through the EFS KnowledgeBase where you will find various guides on EFS including one on developing strategies.
        Alex
        Attached Files

        Comment


        • #5
          Alex, David:

          You are right, this approach works. Something was wrong with my logic.

          Thanks

          David

          Comment

          Working...
          X