fxDreema

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

    Filter trades by age. Number of bars elapsed rather than minutes.

    Questions & Answers
    2
    4
    1810
    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.
    • M
      Mantadiver last edited by

      I am trying to close trades after x bars and the only option I can find in the close block is to "Filter trades by age" in minutes, not bars.

      When using bars that have no fixed time I have to count the bars.

      Is there a way to filter by age in terms of the number of bars that have passed since open ?

      If not I will try to build a separate running bar counter for each trade unless you feel it worthy of being added to the wish list.

      Thank you.

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

        I think once in the past someone asked the same question, I don't remember what solution I gave him. But I think that with some calculations you can get the number of minutes from the bars. I don't know what calculation and I am actually very very bad in mathematics, but here is some example that shows that you can do such things.

        MathFloor((TimeCurrent() + 86400) / 86400) * 86400
        

        Here TimeCurrent() gives you the current time, the value that this function gives is going up with 1 each second, so the value is the number of seconds since 1 Jan 1970. More here: https://www.epochconverter.com/

        And MathFloor() is a MQL function that is described like this "The function returns integer numeric value closest from below."

        So, the whole calculation is giving you the time at 00:00 of the current day, no matter if TimeCurrent() is giving you the time at 02:10 or 18:45 of the day.

        So there should be similar formula that turns the age of the trade into number of candles.

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

          Let's say the age is 55 minutes. The age written in MQL4 is like this:

          OrderCloseTime() - OrderOpenTime()
          

          If the period is 15 minutes, then you can just divide: 55 / 15. The result is 3.666. Now, you can use either MathFloor() or MathCeil(), the first function will give you 3 from 3.666 and the second will give you 4 from 3.666. Try this: http://prntscr.com/ikmrdw

          1 Reply Last reply Reply Quote 0
          • M
            Mantadiver last edited by

            The candles I am using are achievement based and therefore each one has a different amount of time.

            I have resorted to:-

            a) Running a continuous bar count on each bar open = (Current Bar Number)
            b) Recording the current bar number when a new trade is placed = (Trade Start Bar Number)
            c) Calculating the number of bars between now & when the trade started = (Current Bar Number) - (Trade Start Bar Number)

            A little crude and simple but appears to be working.

            Many thanks for the input.

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

            Online Users

            A
            E
            R
            S
            B
            N
            M
            A

            15
            Online

            146.7k
            Users

            22.4k
            Topics

            122.6k
            Posts

            Powered by NodeBB Forums | Contributors