fxDreema

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

    help :: make EA open&close deals by open&close candle

    Questions & Answers
    2
    2
    411
    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
      medhat2014 last edited by

      i need make EA buy on each new candle and close it when close candle

      i can open buy on each new candle

      but i cant close it with close candle

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

        Practically this is the same thing, the same event.

        Many people ask for candle close, and let's say that this is something that happens on the last second of our timeframe. But there is a problem with it. MetaTrader has this "On Tick" event and the EA reacts on it, but it does not have "On Candle Close" event. Well, we can make it by creating endless loop and waiting for the second to become 59 and fire that even (call some function), but this is possible in live only. When backtesting, the EA is controlled by this "On Tick" event and it only does something when a new tick is "received". But ticks are irregular, some can come in :58, the next can come in :59, so how can we know from inside the EA which tick will be the last tick of the current candle? I don't know how. And if we create some endless loop and backtest it, the EA actually stops on it, it stays forever in the same tick.

        So... "Once per bar" when placed under "on Tick" does the job to detect the moment when a new candle is created. Yes, it can be few seconds in the new minute, but it's pretty accurate and works well 🙂 So my suggestion is to place the "Close" block before "Buy" or "Sell" one.

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

        Online Users

        M
        M
        G
        M
        B
        T
        F

        23
        Online

        146.8k
        Users

        22.4k
        Topics

        122.6k
        Posts

        Powered by NodeBB Forums | Contributors