fxDreema

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

    How to Select "Least profitable trade"?

    Questions & Answers
    2
    5
    2170
    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.
    • R
      rafaelgrecco last edited by

      Hi,

      There is a blue block on "Trading Actions" that closes the least profitable trade.

      But what I want is to select this trade (the least profitable trade) to compare with another value.

      How can I do it? A pink block "select least profitable trade" would be perfect.

      Thanks

      1 Reply Last reply Reply Quote 0
      • R
        rafaelgrecco last edited by

        Any idea?

        I have tried using a combination of check loss, check profit, variables, conditions, etc. But it's not very simple... If I have several open trades, I have to compare all of them to select which one has the biggest loss...

        But I still haven't found a reliable way to do that.

        Any help or idea is much appreciated.
        Thanks

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

          https://fxdreema.com/shared/2TwfqkIod
          Well, I have an idea but its not the simplest one 😄
          We could use a position loop that goes through all your open trades, it finds the lowest profit and the trade number (loop id) - after that loop we have the amount and trade number identified and so we can select that individual trade, and also use the basic condition block.

          If you copypaste the blocks, you will need to create these variables to your project:
          0_1530636572822_bb986a9a-41a8-446a-bf09-6781aeabe4f1-image.png

          Hope you get the idea 😄

          Need small help? Tag me in your post
          Need big help? https://www.fiverr.com/big_algo/automate-your-winning-strategy-in-mql4-or-mql5

          1 Reply Last reply Reply Quote 0
          • R
            rafaelgrecco last edited by

            Hi @roar

            Thank you very much for your help! Using your example I was able to make something that works on my strategy!

            What I was missing was:

            • Reseting the variable "smallestprofit" on every new loop
            • Using the second output of "Each Trade" to wait for all trades to be checked

            Best regards!

            roar 1 Reply Last reply Reply Quote 1
            • roar
              roar @rafaelgrecco last edited by roar

              @rafaelgrecco said in How to Select "Least profitable trade"?:

              What I was missing was:

              • Reseting the variable "smallestprofit" on every new loop

              We must reset the variables at some point, so the ea don't get "stuck" to some big loss that is already closed. Now it resets the variable on every tick, and also calculates it again so we always have the correct value. It is not the most cpu-optimal way but should work fine.

              • Using the second output of "Each Trade" to wait for all trades to be checked

              I think this is the correct way, we must first check all trades in order to find the lowest profit.

              The looping blocks work a bit different than other blocks, go ahead and test different logic builds 🙂

              Need small help? Tag me in your post
              Need big help? https://www.fiverr.com/big_algo/automate-your-winning-strategy-in-mql4-or-mql5

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

              Online Users

              J
              D
              E

              20
              Online

              146.7k
              Users

              22.4k
              Topics

              122.6k
              Posts

              Powered by NodeBB Forums | Contributors