fxDreema

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

    EA for SMA crossing

    Questions & Answers
    4
    8
    3154
    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
      teobusetti last edited by

      Hi all,
      I am trying to build an EA that enters a trade when the 100 SMA > 200 SMA and when the Stochastic crosses the 25 level from below. Let's suppose I set a fixed TP and SL, each of 100 pips. How can you stop the EA from entering a new trade when the SL or TP are reached and the SMAs still have not crossed over?
      I.e. I would like the EA to enter just one trade per SMA crossovers...
      Many thanks!!!

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

        try "once per bar" block

        Between trading and gambling is a very small gap, be careful.

        T 1 Reply Last reply Reply Quote 0
        • T
          teobusetti @miro1360 last edited by

          @miro1360 once per bar does not work. the following example could clarify a bit:

          • SMA cross on bar 0
          • stochastic gives signal on bar 2 and trade is entered
          • trade exit at bat 10
          • at bar 12 the stochastic gives another entry signal and the trade is entered
          • trade exit at bar 20
          • SMA cross again at bat 22

          I am trying to find a way to block the EA from entering the trade at bar 12 - i.e. any trade triggered after the first trade and before the SMA cross in the opposite direction of the first trade... hope it makes sense...

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

            Normally you check bunch of conditions at the current moment and decide what to do. It's good that you have information from the past - MetaTrader knows OHLC levels of many candles in the past => indicator values can be calculated => many values from the past can be used from the past. And this is how things work most of the time - you check something NOW using current or past data and you do something (buy, sell, close) now.

            The reverse way is not very easy. You want to remember that something happened, so you probably need to use Variables to save the current state of the strategy in them. To deal with that I made this functionality: https://fxdreema.com/demo/mt4-wait-crossovers But to be honest, after I made this, I realized that it's not that easy to use it as I was initially expecting.

            T 2 Replies Last reply Reply Quote 0
            • T
              teobusetti @fxDreema last edited by

              @fxDreema Thanks! I will try to make it work with the example you provided 🙂

              1 Reply Last reply Reply Quote 0
              • T
                teobusetti @fxDreema last edited by

                @fxDreema Hey! I've tried to apply what you suggested but I cannot seem to figure out how to configure it properly.
                Isn't there another way of telling the indicator to "stop entering trades until X condition is met"? the X condition being that the SMA must crossover in the opposite direction.

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

                  I have best experience with variables (Flag) ... but sometimes it is hard to do and need a lot of testing ...

                  Between trading and gambling is a very small gap, be careful.

                  1 Reply Last reply Reply Quote 0
                  • S
                    SShui last edited by

                    try this:

                    Set a new Variable (as 0) - for this example I will use 'RunOnce'
                    Add a condition to run your EA only if RunOnce == 0
                    After your BUY or SELL - set RunOnce to 1
                    Add an extra condition to set RunOnce to 0 once the Opposite Cross Over happens again

                    See screenshot

                    http://imgur.com/a/yn6Rt

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

                    Online Users

                    M
                    M
                    E
                    M
                    A
                    H
                    E
                    E
                    M
                    S

                    18
                    Online

                    146.7k
                    Users

                    22.4k
                    Topics

                    122.6k
                    Posts

                    Powered by NodeBB Forums | Contributors