fxDreema

    • Register
    • Login
    • Search
    • Back to the main page
    • Categories
    • Recent
    • Tags
    • Popular
    • Search

    How many bars since the last trade was opened

    Questions & Answers
    2
    4
    1269
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • O
      oyan7348 last edited by

      I have created an working ea and a part of it is that it counts how many bars have passed since a trade has entered, but when I turn it off and turn it back on it looses the stored value and starts at 1 again. How can I write something in the "on Init" so it checks upon starting the ea. Basically if there are any open trades it counts how many bars it has been since it was opened

      1 Reply Last reply Reply Quote 0
      • fxDreema
        fxDreema last edited by

        Can you work with the age of the trade, which is time between now and the time it was created? In this case you are using values that stay in MetaTrader even if the whole PC restarts.

        There can be other tricks, like using Terminal Variables (they are stored in some file) or even objects on the chart. But if you can just work with the age, that will be best.

        O 1 Reply Last reply Reply Quote 0
        • O
          oyan7348 @fxDreema last edited by

          @fxDreema Thank you for your quick reply. I actually tried to use the check age and it does work to a degree, but once it comes across a weekend where we skip two days, it miscalculates. I know how to create an object once a trade has been entered, but can you please show me how I would reference to it? I basically need it to check "if it has been over 10 bars since the latest trade has been entered"

          1 Reply Last reply Reply Quote 0
          • fxDreema
            fxDreema last edited by

            Here is about the objects, I tried to explain them via those 2 examples https://fxdreema.com/examples#Chart-Objects

            1 Reply Last reply Reply Quote 0
            • 1 / 1
            • First post
              Last post

            Online Users

            T
            B
            K
            T

            10
            Online

            146.9k
            Users

            22.4k
            Topics

            122.6k
            Posts

            Powered by NodeBB Forums | Contributors