fxDreema

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

    Positioning and referencing trade events

    Questions & Answers
    2
    9
    1474
    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
      oseiwe last edited by

      Hi All,

      I am trying to program my ea to do the following:

      • After the previous sell trade, to NOT enter another sell trade (whether or not the previous trade has closed) until price has reverted back to the 20SMA

      Because price could revert back to the 20SMA at any time (provided it does so after the previous sell trade has been placed), I am finding it difficult to set up. For example I could use the "No Trade" block plus an indicator condition, but would then have to specify within what period price should touch the SMA (which defeats the purpose as I want trades to re-enabled ANYTIME price reverts back to the SMA - no fixed period).

      Hopefully I am just being silly and there is an easy way to do this.

      Any ideas?

      Regards
      Ose

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

        I don't fully understand the question, by I have this feeling that you may want to try something like this

        Project example: https://fxdreema.com/demo/mt4-buy-sell- ... conditions
        Image:
        https://fxdreema.com/examples/screenshots/mt4-buy-sell-buy-sell-opposite-conditions.png

        1 Reply Last reply Reply Quote 0
        • O
          oseiwe last edited by

          Thanks fxdreema,

          Your illustration is pretty close, but I think there is an aspect I need clarification on:

          So taking your illustration further, suppose after the MA cross and after closing any open trades, there is a further requirement for there to be another cross (say 50MA x> 100MA), but this cross does not happen until long after the initial cross, will there ever be a buy trade?

          I know the above sounds confusing. Let me try to explain further:

          Let's say we have the below requirement (similar to yours):

          1. Check that there are no trades
          2. Wait for 1MA to cross 5MA
          3. Close all open trades
          4. Wait for 10MA to cross 20MA
          5. Open BUY trade

          Now suppose 1, 2, and 3 occur at 10am, but 4 does not occur until 5pm that same day, will the BUY trade still be opened? In other words, after condition 2 has been met and step 3 has taken place, will the EA store the result/outcome of step 2 and 3 until the condition in step 4 is met? or will it keep looping through the steps until step 4 is met (in which case, step 2 would no longer be valid because the cross would have happened a long time ago)?

          I hope this makes sense.

          Regards
          Ose

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

            If you have one block for each step and all blocks are connected one after another, then the answer is no. In "on Tick" blocks run on every tick and there is no situation when you reach one block that currently can't pass and wait for it to pass. If a block does not pass, nothing happens, for that tick everything is over and the block will probably be "asked" again on the next tick.

            You may want something like this here: viewtopic.php?f=5&t=3274 But as you can see, I decided that this model was slow and I stopped working on it.

            So when you work under "on Tick" you must think from that perspective. Here is another example where people are thinking that the EA will stay on some block waiting for it to pass, but it doesn't work that way: https://fxdreema.com/demo/mt4-wrong-closing-rule (this is the example called "Wrong: Closing rule" from the examples here https://fxdreema.com/examples/)

            1 Reply Last reply Reply Quote 0
            • O
              oseiwe last edited by

              OK thanks. I can see that on the surface, this is not possible.

              However as a workaround, is it possible to assign the date and time of the last trade/alert to a variable and also assign the date and time of the next MA cross to a variable, and then issue a condition that says:

              If Time of Last Sell Trade (ie VarSell) < TIme of MA cross (ie VarCross), then open a sell trade. If not, do nothing?

              This way, the EA will keep checking every tick for the next MA cross. Once this is found, it will compare the time of cross with the time of the last trade and then place a trade. However if it does not find an MA cross, no trade will be opened.

              If the above is not possible, then I guess I would have to give up 😞

              Regards

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

                By the way I decided to find a way to do this thing, to add new event called "on Hold" where if any block fails to pass, to retry it on the next tick. Many people are asking for this and many people are thinking that things work that way. I'm tired to explain those things again and again, so I think it's better to just do it, even if the result is slow.

                Otherwise yes, it's possible to set any Variables. The Time as a data type is "datetime", which is similar to integer (whole number) and two Time variables can be compared.

                1 Reply Last reply Reply Quote 0
                • O
                  oseiwe last edited by

                  Hi,

                  Thanks for your response. Thanks for the HOLD option. However since you say it is slow, I guess it would not be a preferred method. Also thanks for making mention of the Datetime data type.

                  I however (after hours of trying different options) found another solution that seems to work fine:

                  Block 1

                  • Create a condition that checks for the first MA cross on every tick
                  • Create a flag that gets set to 1 (or any other number or string) when the MA cross occurs

                  Block 2

                  • Create a separate condition that checks for the second MA cross
                  • Create a "Check flag" that checks if the flag in block 1 is set to 1
                  • If the flag is set to one (because the flag does not get overwritten by each tick), initiate a trade.
                  • Create a flag that sets the flag back to 0 when the trade is initiated

                  So people stop bothering you about stuff like this, I guess you could add it to the "Examples" area, as I think it would help those that have been requesting it. In short, they need to use "Flags".

                  Regards
                  Ose

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

                    Yes, you described what can be done in this situation. It would be the same if you use Variables instead of flag-blocks, because in fact those flag blocks use variables to keep their memory.

                    The example I posted above is similar, but the difference is that the memory that is used is external, it's in the trades that are created. So, instead of storing and checking temporary information (variables in the EA are in RAM), I use the type of the trade as such information. But this is very particular example where this can be used. Anyway, what I want to recommend is to first try to find a way to use information from the trades/orders/candles, and if this is not possible Variables/Flags can be used as well (and sometimes this will result in faster EAs for testing).

                    1 Reply Last reply Reply Quote 0
                    • O
                      oseiwe last edited by

                      Thanks!

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

                      Online Users

                      D
                      L
                      H
                      S

                      8
                      Online

                      146.7k
                      Users

                      22.4k
                      Topics

                      122.6k
                      Posts

                      Powered by NodeBB Forums | Contributors