fxDreema

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

    Works in tester, but "Alert: Modify error" on live feed

    Questions & Answers
    2
    23
    5725
    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.
    • J
      james last edited by

      Sorry. Me again! 🙂

      This time I'm experiencing a problem with placing and modifying a stop loss on a live feed. I've tried several methods, but keep getting an error. The most recent error is:
      __Alert: Modify error: Array index is out of range (4002)[/quote:dg7otuwc]
      I'm trying to place a stop loss below a buy at the 55 day EMA, and then run it as a trailing stop. This all seems to work fine in the tester, but not on the live feed.

      See here: http://fxdreema.com/shared/0uYNJ9m3c

      Should this work? Or is it me doing something wrong?

      1 Reply Last reply Reply Quote 0
      • J
        james last edited by

        Oops! Forgot to say (again!) I'm on local build v053.

        1 Reply Last reply Reply Quote 0
        • J
          james last edited by

          Heck! More of my mistakes! 🙂

          Error in my "Buy now" block. Here's the link with a refreshed setup:

          http://fxdreema.com/shared/6yxLH5G9c

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

            I rewrote the trading functions, so now 053 is old... but I got another type ot strange errors that seems to come from the server 😕
            Do you have errors when using that EA from the web version?

            1 Reply Last reply Reply Quote 0
            • J
              james last edited by

              I have re-created the EA from the web version, and am now running it live. Will let you know as soon as it does anything.

              1 Reply Last reply Reply Quote 0
              • J
                james last edited by

                Yes, I think the web version produces something similar. Journal log says:
                __15:00:32 '58032744': instant order buy 10.37 US500.U at 1687.25 sl: 1668.44 tp: 0.00
                15:00:33 '58032744': order buy 10.37 US500.U opening at 1687.25 sl: 1668.44 tp: 0.00 failed [Invalid S/L or T/P]
                15:00:33 '58032744': instant order buy 10.37 US500.U at 1687.25 sl: 1668.44 tp: 0.00
                15:00:33 '58032744': order buy 10.37 US500.U opening at 1687.25 sl: 1668.44 tp: 0.00 failed [Invalid S/L or T/P]
                15:00:33 '58032744': instant order buy 10.37 US500.U at 1687.25 sl: 1668.44 tp: 0.00
                15:00:33 '58032744': order buy 10.37 US500.U opening at 1687.25 sl: 1668.44 tp: 0.00 failed [Invalid S/L or T/P]
                etc.[/quote:31u5kg1w]
                Experts log says:
                __15:00:33 US500 TrendFollow 2PointFormat type 2 v2 web US500.U,H4: New trade error: Invalid Sl or TP (130). Retrying..
                15:00:33 US500 TrendFollow 2PointFormat type 2 v2 web US500.U,H4: New trade error: Invalid Sl or TP (130). Retrying..
                15:00:33 US500 TrendFollow 2PointFormat type 2 v2 web US500.U,H4: New trade error: Invalid Sl or TP (130). Retrying..
                etc.[/quote:31u5kg1w]
                The problem seems to be that the EA's instruction to place the stop at a given price (in this case the 55 day EMA level) is misunderstood by the broker's server. Even using the method I adopted of saving the SL price into the variable BuySL does not seem to get around the issue.

                Incidentally, I've also tried using a formula block, (candle low(1) - EMA 55 candle close(1)) store in variable BuySLPips, and using BuySLPips in fixed pips mode for the stop loss in the "Buy now" block.

                As I say, this doesn't seem to be a problem in the tester.

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

                  The first project you posted is wrong, because BuySL holds price value and you are using this value as a pips size, so at the end Buy now thinks you want to place SL at 1.314... pips, or whatever the MA value is.

                  Build 054 is uploaded. Now I'm changing things a bit. Before, if SL/TP are too close or on the opposite side it will give you error 13 and it will stop there.

                  Now before opening a new trade it checks if SL/TP are too close, and it places them on the minimum available level. For Buy the minimum SL level is Ask-StopsLevel, where StopsLevel depends on the broker and in my broker it is 0, it is measured in points).
                  If we have SL (or TP) at this minimum price it will go to buy/sell... but I found that sometimes it gives error 130 again. This is probably because of the time delay between SL/TP calculation and the moment when the order is received in the server.

                  Unfortunately SL/TP levels are send as levels, not as points relative to the open price, so I can't help much about that. We calculate the minimum levels at time X, we send them to the server with delay, and it receives them at time Y, but in this time price can be changed. So what we can do - try again.

                  I even tested things in Market Execution manner (ECN broker). This is when you send the trade without stops and then you send another command to modify them. Why this is correct in theory? Because when you have Market Execution the trade is opened on the nearest available price, not on Ask/Bid, so at the end the open price can be different than Ask/Bid - and knowing that price you can calculate SL/TP in relation to it. But I tested that and things are the same - there are errors again because of the time delay.

                  In theory Market Execution is different than Instant Execution (where you must send Ask/Bid price and max Slippage, and it will decide if it's possible to create the trade), but it looks that there is no difference. At least it's good that OrderSend() can now work with stops bigger than 0 🙂

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

                    There is even more - something called "Freeze level", where you can't modify. Here is more about these limits: http://book.mql4.com/appendix/limits . Scalping is not easy 🙂

                    1 Reply Last reply Reply Quote 0
                    • J
                      james last edited by

                      Thank you so much for your full reply. If I was more conversant with what goes on behind MT4 and the brokers I'm sure I'd have understood it in detail. As it is, I think - hope 🙂 - I get the idea.

                      I was aware I'd made a mistake in http://fxdreema.com/shared/0uYNJ9m3c, so amended it in http://fxdreema.com/shared/6yxLH5G9c, which I hope is correct. But I'm sure you'll keep me right if not!

                      Also I'm not trying to scalp, unless my interpretation of scalping is wrong! I'm trying to place a stop at the 55 day EMA level, which, on average on the S&P500 is always something like 30 pips away from the current price at the points when I place a trade.

                      Therefore I do understand that fxDreema will now check the stop is acceptable, and if not change it to the minimum allowed by the broker - which is great! 🙂 - thank you. But I'm not sure if local build 054 answers my original query. Maybe it does.

                      As far as I can see, and looking at http://fxdreema.com/shared/6yxLH5G9c, block 5 "Set BuySL" places the price level of the 55 day EMA in the variable "BuySL"; then block 3 "Buy now" uses that value to place a "Dynamic level (price input)" stop loss at the price currently held in variable "BuySL".

                      In the MetaTrader Tester this all works fine, and places my stops at the 55 day EMA, which is, as I say, always around 30 pips away on trading.

                      This placing of the stop at the 30 pip, 55 day EMA price level was the bit which seemed not to be working in the live environment. Have I got this wrong? Does local build 054 fix this?

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

                        This works for me on live.

                        So you still receive error 4002? To be honest, I don't know where it comes, there are no arrays used in trading functions that I wrote, so I think it can be some MT4 fault. What if you restart it?

                        1 Reply Last reply Reply Quote 0
                        • J
                          james last edited by

                          OK. I'll re-edit the EA with local build 054 and then run it on a live feed again to test. I'll get back to you if I encounter the issue again.

                          1 Reply Last reply Reply Quote 0
                          • J
                            james last edited by

                            I'm afraid it still isn't working for me, and I am using local build 054.

                            Take a look at http://fxdreema.com/shared/M7Rosd5rb. Its the same EA as before, edited.

                            Block 8 updates the variable BuySL with the price of the 55 day EMA, and block 7 is the trailing stop block which uses a "Dynamic level" to set a stop loss at the price held in BuySL.

                            Now take a look at the picture of MT4 on a live feed:
                            Clipboard02.jpg
                            The solid red line at the bottom is the 55 day EMA, well below the current price. The dotted red line is one of only two successful attempts over many attempted placings of the SL, and is as close to the price as possible, but not where I want it!

                            Experts tab says:
                            __2013.09.13 21:59:15 US500 TrendFollow 2PointFormat type 2 v1 US500.U,H4: Modify error: Invalid Sl or TP (130). Waiting for a new tick to retry..
                            [/quote:3n862o2e]
                            Journal tab says:
                            __2013.09.13 21:59:15 '58032744': modification of order #33169429 buy 10.37 US500.U at 1688.50 sl: 1688.75 tp: 0.00 -> sl: 1669.11 tp: 0.00 failed [Invalid S/L or T/P]
                            [/quote:3n862o2e]
                            It seems to me that even if the "Dynamic level" in the trailing stop block was setting a pips stop loss and not a price stop loss, the figure in this case would be a 1669.83 pips stop loss. So where its getting its stop loss from I just don't know.

                            You'll notice that the "Buy now" on the EA uses a fixed pip SL of 55. Therefore the errors are related to what's happening in the trade loop. It seems to me that the "Dynamic level" bit isn't working correctly. Somehow the broker's server doesn't get the correct instruction.

                            Have I done something wrong? This should work, shouldn't it? 🙂

                            If I do have it wrong, how do I place a stop and then run a trailing stop, both at the 55 day EMA price?

                            ......
                            Clipboard02.jpg

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

                              Just wondering why do you use such a strange, even wrong project to show something simple. If "Buy now" does not work, it's absolutely enough to have "Buy now" block, and "Just pass" only because it needs to be executed.

                              "Trailing stop" is not to be placed below "Start trades loop". If you have 20 trades and this makes "Start trades loop" to be executed 20 times in a tick, why do you need to execute "Trailing stop" 20 times in a tick? This blocks construction is not correct.

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

                                Unfortunately markets are closed on my MT4, and I even don't have this instrument, but I backtested on SP500 and it seems to work.

                                If I don't have initial SL it works like this:
                                2013.09.14 01:27:45 2013.09.09 00:00 stoploss #SP500U3,H4: modify #1 buy 0.10 #SP500U3 at 1652.30 sl: 1647.79 tp: 0.00 ok
                                2013.09.14 01:27:45 2013.09.09 00:00 stoploss #SP500U3,H4: open #1 buy 0.10 #SP500U3 at 1652.30 ok

                                Otherwise, because 55 pips are something very small for this instrument (point format), it works like this:
                                2013.09.14 01:28:55 2013.09.09 00:00 stoploss #SP500U3,H4: open #1 buy 0.10 #SP500U3 at 1652.30 sl: 1651.75 ok

                                and there is no trailing stop, because the initial stop is above MA.

                                I don't understand why you have invalid SL/TP error, I think you have to receive something like "Order is too close to market". And this value 1669.11 is lower than 1688.50... very strange. Is the open price of this trade 1688.50 really? And why it looks that SL of this Buy is above it's open price 😮

                                1 Reply Last reply Reply Quote 0
                                • J
                                  james last edited by

                                  Hi again, and thanks for the reply.

                                  I agree that back testing on SP500 (S&P500, US500 are all the same index) works fine. Its running on the live feed that is the issue. From what I can work out, the broker, Alpari, allows anything down to a 2 pip stop loss on this.

                                  Actually, if you look carefully at the picture of my chart, the price is just above the SL on it. As I said, the EA managed to move the SL twice during many attempts, and the SL got very close to the current price. The SL isn't above the current price. This is what it managed just before I stopped the EA:
                                  __2013.09.13 21:35:38 US500 TrendFollow 2PointFormat type 1 v2 US500.U,M1: modify #33169429 buy 10.37 US500.U at 1688.50 sl: 1688.75 tp: 0.00 ok
                                  [/quote:kazcf2bp]
                                  As you see, a very close stop, way above the 55 day EMA, and just below the current price of 1689.25.

                                  So, just to re-cap, on the live feed...
                                  *the "Buy now" block with a 55 pip SL seems OK, but not if a dynamic price is used;
                                  the "Trailing stop" set to "Dynamic value" with a price loaded into variable BuySL seems not to work;
                                  but "Dynamic value" for both blocks work fine on the back tester.[/list:u:kazcf2bp]

                                  Do you think these two blocks set to "Dynamic value" should work in this way, or not? If not, how to I set a stop loss and trailing SL at the 55 day EMA?

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

                                    http://fxdreema.com/shared/qt1SxbDEd

                                    On backtest this makes SL to move upwards only when MA goes up, otherwise SL stays untouched.

                                    I don't understand something. This is Buy trade, SL should be below the open price, but it is above. It's true that sometimes I am dumb, but I think normal Buy trade should looks like this:

                                    https://sphotos-b-ord.xx.fbcdn.net/hphotos-prn1/p480x480/12063_558492000849145_1588723552_n.jpg

                                    And you want your SL to be on MA line, which is below that dotted green line, but now it is on the opposite side - above the green line. How is that possible?

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

                                      http://charts.mql5.com/2/516/sp500u3-h4-mig-bank.png

                                      Huh, when I do "Save As Picture" it uploads it on a link like this http://www.mql5.com/en/charts/763385/sp ... mig-bankSo

                                      So, this is how it should be.

                                      2013.09.14 13:31:17 2013.09.09 00:02 stoploss #SP500U3,H4: modify #1 buy 0.10 #SP500U3 at 1652.30 sl: 1648.06 tp: 0.00 ok
                                      2013.09.14 13:31:16 2013.09.09 00:01 stoploss #SP500U3,H4: modify #1 buy 0.10 #SP500U3 at 1652.30 sl: 1648.04 tp: 0.00 ok
                                      2013.09.14 13:31:16 2013.09.09 00:01 stoploss #SP500U3,H4: modify #1 buy 0.10 #SP500U3 at 1652.30 sl: 1648.02 tp: 0.00 ok
                                      2013.09.14 13:31:16 2013.09.09 00:00 stoploss #SP500U3,H4: modify #1 buy 0.10 #SP500U3 at 1652.30 sl: 1647.99 tp: 0.00 ok
                                      2013.09.14 13:31:15 2013.09.09 00:00 stoploss #SP500U3,H4: modify #1 buy 0.10 #SP500U3 at 1652.30 sl: 1647.97 tp: 0.00 ok
                                      2013.09.14 13:31:15 2013.09.09 00:00 stoploss #SP500U3,H4: modify #1 buy 0.10 #SP500U3 at 1652.30 sl: 1647.95 tp: 0.00 ok
                                      2013.09.14 13:31:15 2013.09.09 00:00 stoploss #SP500U3,H4: open #1 buy 0.10 #SP500U3 at 1652.30 ok

                                      1 Reply Last reply Reply Quote 0
                                      • J
                                        james last edited by

                                        Thanks again for the quick reply.

                                        I'm not using the File/Save As option in MT4 to get a picture. I'm screen copying into IrfanView, and saving this file onto this forum. And no, you are not dumb! I promise! If either of us is, its me! 😳 My picture in my post Sat Sep 14, 2013 12:02 am is misleading. Sorry.

                                        Anyway, it doesn't matter as I think there may be some progress.

                                        I've back tested your EA from http://fxdreema.com/shared/qt1SxbDEd (date range 2013.05.06 to 2013.05.08 on the SP500) and it runs fine, just the way I expected. I then checked mine again, made a couple of edits and made a new link: http://fxdreema.com/shared/0G2DBNfbd. It also back tests perfectly over this time.

                                        So now I think we are both on the same track! 🙂

                                        Therefore, when the markets open, I'd be very grateful if you would put both yours and mine onto a live feed to see if the stop losses get set correctly at the 55 day EMA. I'll do the same here.

                                        Many thanks, again.

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

                                          Aha, your SL is placed there not from the start, but later, when the price is somewhere above the open price. This is the dumb thing - when I can't see something in front of my eyes 🙂

                                          So obviously instead of putting SL to a certain price, it thinks that this value is in pips, and because this number is small - it puts SL to the nearest possible value. But I checked if there is something wrong in the code that can cause this, and all looks correct. We will see on monday.

                                          Again, Trailing Stop is not to be used like this. In this particular EA there is no difference, because it has 1 trade at a time, but it's not correct. Just remove this pink block from there.

                                          Also note that block 10 will be executed after 1 and 6, but if 1 is 11 and 6 is 16, then block 10 will be executed first. Block numbers matters when they are in parallel.

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

                                          Online Users

                                          H
                                          H
                                          O
                                          R
                                          S
                                          Z
                                          M
                                          J
                                          M
                                          H
                                          S
                                          C
                                          T

                                          23
                                          Online

                                          146.7k
                                          Users

                                          22.4k
                                          Topics

                                          122.6k
                                          Posts

                                          Powered by NodeBB Forums | Contributors