fxDreema

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

    Check Trades Position Block?

    Questions & Answers
    2
    12
    2652
    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.
    • T
      Trader3487 last edited by

      I am looking for a block/way to do the following: if less than 3 trades exist between high point and low point of previous 12 hours, then open trade. If condition is false, do not open trade.
      In other words, is there a way to check if trade/how many trades are running within specific market range?

      1 Reply Last reply Reply Quote 0
      • T
        Trader3487 last edited by

        also, is there a way to check whether another trade is open close to the current market value? For example, if trade exists within 10 pips of candle close[0], then don't open new trade

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

          You can always check if OP is above or below some value, but in this scenario is a little bit more complex. And no, there is no block for this and it can be made with loop, but this will be rude. The code for such a thing takes less space (literally) compared to what will be if you use blocks and variables for them, and in this case it's better to use it as a code. So I wrote this code that can be used in a custom block:

             // input parameters for the block
             int Hours=12;
             int MaxTrades=3;
             double HighLevel=1.9999;
             double LowLevel=0.9999;
             
             int trades_found=0;
             int total=OrdersTotal();
             for (int pos=total-1; pos>=0; pos--) {
                if (OrderSelect(pos, SELECT_BY_POS, MODE_TRADES)==false) {
                   continue; // can't load this trade - continue with the next one
                }
                if (TimeCurrent()-OrderOpenTime()>Hours*60*60) { // the difference in time is in seconds
                   break; // too old trade, exit the loop
                }
                if ( (HighLevel==0 || OrderOpenPrice()<HighLevel) && (LowLevel==0 || OrderOpenPrice()>LowLevel) )
                {
                   trades_found++; // trade's OP is within the limits, increment trades_found variable
                }
                if (trades_found>=MaxTrades) {
                   break; // max trades found, no need to continue searching, exit the loop
                }
             }
             if (trades_found>=MaxTrades) {~next~} else {~inext~}
          

          I have to say that I didn't tested that! I just wrote it like this and it can be wrong somewhere, but you can try it at least.
          You can leave input variables like this, or remove them from the code and define it with the program (http://fxdreema.com/studio/MQL4), but for now maybe it's better to edit them inside the code.
          I wrote values like 1.9999 and 0.9999 for levels, but you can replace those with some Variable name.

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

            __also, is there a way to check whether another trade is open close to the current market value? For example, if trade exists within 10 pips of candle close[0], then don't open new trade[/quote:1a9ogw44]
            I might be wrong here as well (again not tested), but something like this could work: http://fxdreema.com/shared/am8G3OUpb

            1 Reply Last reply Reply Quote 0
            • T
              Trader3487 last edited by

              brilliant! thank you. When I added a levels tester to print "open price" on screen it prints only the open price of first order in loop so it seems that the "in loop/trade order in loop" in condition blocks only checks the first trade. But we want if candle close[0] < open price level for any open trade not just the first trade. Or maybe it is working correctly but levels tester can print only one value?

              1 Reply Last reply Reply Quote 0
              • T
                Trader3487 last edited by

                ... how can I check if the block is actually looping through all of the orders and not just checking the first (newest) order?

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

                  Well, Levels tester draws single value per candle and if new information comes within that candle, it just overwrites the last value.

                  By the way, for your last project, go to Options -> Project Blocks: Normalize IDs. I still don't know how block IDs starts to become so big, at least this did not happened to me, but this option turns them back to normal 🙂

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

                    __... how can I check if the block is actually looping through all of the orders and not just checking the first (newest) order?[/quote:7rex6bgg]
                    If I have to do it, I will connect "Draw arrow" and "Terminate EA" after that block and I will count arrows. Also "Alert message" is good for showing information. But your "Start trades loop" should loop all trades as it's not configured to work with only one of them.

                    1 Reply Last reply Reply Quote 0
                    • T
                      Trader3487 last edited by

                      having trouble getting this to draw arrow: http://fxdreema.com/shared/am8G3OUpb
                      I created this one to test but it's opening orders very close to each other. Even though the buy now comes after "every tick" block, it should only open an order if there are no other orders within 0.001 above or below. Am I missing something? http://fxdreema.com/shared/EejFU65ae

                      Thank you! 🙂

                      1 Reply Last reply Reply Quote 0
                      • T
                        Trader3487 last edited by

                        this one works now: http://fxdreema.com/shared/RA2XPxFUd

                        1 Reply Last reply Reply Quote 0
                        • T
                          Trader3487 last edited by

                          well, turns out that last example works if there is a single order but doesn't work for multiple orders... I've tried every possibility over the last 4 hours and still can't figure it out 😞
                          http://fxdreema.com/shared/HlLY20Kpb

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

                            You are counting how many arrows there are? Then answer the question - what does "Once per bar" do? 🙂

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

                            Online Users

                            B
                            A
                            P
                            A
                            A
                            X
                            K
                            F

                            16
                            Online

                            146.7k
                            Users

                            22.4k
                            Topics

                            122.6k
                            Posts

                            Powered by NodeBB Forums | Contributors