Announcement

Collapse
No announcement yet.

EfS computeonclose/barstate

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

  • EfS computeonclose/barstate

    can you use compute on close and barstate currentbar at the same time
    sam

  • #2
    sam
    It is possible to check for BARSTATE_CURRENTBAR in the same script in which you are using setComputeOnClose() however because setComputeOnClose() forces a formula to execute only once per bar [when a bar is completed and a new bar is being formed] getBarState() will never return a bar state of CURRENTBAR
    Alex

    Comment


    • #3
      Thanks Alex
      Do you have any ideas for doing 5min bar on close for entry and exit at a stop / target price when hit.
      sam

      Comment


      • #4
        sam
        To do that you need to enclose the entry conditions in a conditional statement that checks for BARSTATE_NEWBAR while your exit conditions will be evaluated on every tick.
        Alex

        Comment


        • #5
          Thanks Alex
          Tried that and had problems.
          it caused multiple trades when loading and was not stable.
          I'll give it another go. Nice to know I'm on the right track

          Sam
          sam

          Comment


          • #6
            sam
            To prevent the script from generating trades while it is loading enclose the trade commands inside a conditional statement that checks that getCurrentBarIndex() is equal to 0 [or -1 if using setComputeOnClose()]
            Alex

            Comment

            Working...
            X