To use chat, please login.
Back to contacts
pc8multifx (pc8multifx)
Jul 28 2010 at 10:23
879 poster
salmas64 posted:
    Thanks for ideas. Hmm.... it seems to the world of MT4 is less ideal that I thought 😕

My EA works on idea of martingale system, but if case of larger movement of the market it opens hedges for some trades to protect equity. EA calculates combined profit for all opened BUY and SELL positions and if reaches 'Target combined $ profit' or 'Target Stop loss $ profit' closes all trades immediately with minimal slippage as possible.

EA calculates profit for each trade the way ( OrderProfit()+OrderSwap() ) so I believe this should be independent from broker's feeds. And big differences on balance I'm getting after closing those trades on some broker getting negative trend. 😞

Example: EA has open 30 trades (buys and sells) of size 0.01 lot and current combined profit is +$20.00.

After closing all 30 trades getting differences on closed trades:
Broker 1 = +$18.30
Broker 2 = +$17.80
Broker 3 = +$12.20
Broker 4 = -$2.20

I don't think that this is caused by slippage and different spread. That would be too high and I think EA calculates somehow differently on each broker the 'Combined profit' or is idea of combining trades bad way of trading? This is still on demo accounts, now I can imagine how it would be worse on real accounts.

Actually I'm not sure what is the real unit for OrderProfit() is it in traded currency, deposit currency or broker currency? See attached definition from MQL4 help, it's not quite clear to me.

Its order execution delay and slippage what causes the differences. Check it in the journal. One of the reasons can be the broker latency.

Slavo (salmas64)
Jul 28 2010 at 10:30
5 poster
Thanks Kenny.

Closing 30 trades takes about 1-5 seconds, it seems to me pretty fast. Maximum within 1-3 ticks, that's why I think can't be caused by spread 😞

Minimal slippage I managed to do via recursive loop with increasing slippage value.

In other words:
         EA tries to close trade with slippage 0. if fails
                          tries again with slippage 1. if fails
                          tries again with slippage 2. if fails
                          tries again with slippage 3. if fails
                          until trade is closed successfully.

Steve B (stevetrade)
Jul 28 2010 at 10:34
1408 poster
Not sure why you are doing it this way. Provided you have an honest broker submit it with a maximum slippage and if it can't close with no slippage then it will close with slippage.

In fact thinking about it further at the point you submit the request to close with zero slippage they might not be able to close at zero slippage.
When you then submit your request to close with 1 pip slippage they might actually be able to close with zero slippage etc.

Whenever I code EA's I always try and strip out any code that is not absolutely necessary. The more code you put in there the more there is to go wrong and to hold things up.

11:15, restate my assumptions: 1. Mathematics is the language of nature. 2. Everything around us can be represented and understood through numbers. 3. If you graph these numbers, patterns emerge. Therefore: There are patterns everywhere in nature.
kennyhubbard (compuforexpamm)
Jul 28 2010 at 10:47
265 poster

I'm inclined to agree with Steve. Slippage is a parameter that you can use to give yourself a choice of accepting a fill or not. Once you have decided to close a string of orders, you are actually committed to accepting whatever fill you get by your strategy...............changing the slippage does not improve the fill that you receive.

A normal broker will not look at your slippage before 'getting' you a price. They will find you a price and then they will look at the slippage parameter to determine whether to accept or to re-quote.

You should also tell me which broker you are with, as to be quite honest, 1 - 5 seconds to close 30 trades seems beyond belief. I would be interested to see that close routine. Do you use OrderCloseBy()?

Wealth Creation Through Technology
Elkart (Elkart)
Jul 28 2010 at 10:52
941 poster

I can't get over a transaction a second. Mostly because all the crap we had to write in to double check everything's happening as it should. Mt4 not the best piece of software around.

Have to write all the issues out and that takes time to check.

Elkart (Elkart)
Jul 28 2010 at 10:56
941 poster
Saying that, I did do 5000 trades yesterday in an hour. So I guess I shouldn't complain to much.

Elkart (Elkart)
Jul 28 2010 at 11:06
941 poster
Not that I wanted to mind you. Fat fingers, but old MT put it out there and Go markets took it without as much as a squeal...

kennyhubbard (compuforexpamm)
Jul 28 2010 at 11:59
265 poster
Actually just been running some tests. I have been eyeing out this OrderCloseBy() function for a while.

I don't do hedge Grid trading, but for those that are interested, here is some good ideas to pass on to your programmers....

There are 3 scripts attached to this post. Use the Open_Hedge_Trade script to open 30 trades on your demo account......make sure it is a big account cos it open 1 full lot per trade.

Run the Close_All script and note the time in the experts tab. Then Open the 30 trades again and run the Quick_Close script. Note the time in the experts tab. You will see the Quick_Close script closes all the trades about 50% - 100% quicker than the regular close script.

How does this work you ask? When a broker closes your trade he actually has to enter a trade for you in the opposite direction and this matching off take time. By using this OrderCLoseBy() function, you are telling the broker that there is a matching trade within your own account that you wish to close. This means that broker does not have to find a trading partner for you plus it kills 2 trades with 1 instruction.

Another benefit I can see here is that you would have no naked exposure in the market while you are closing one side of the hedge.

BTW, my times from my VPS were 6594 ms for the normal way and 4391 ms with the quick close. Also note the scripts are rough and dirty so there is no error handling and so on, they were just intended for demonstration purposes.

Bifogade filer:

Wealth Creation Through Technology
Steve B (stevetrade)
Jul 28 2010 at 12:08
1408 poster
Excellent work Kenny and well worth knowing

11:15, restate my assumptions: 1. Mathematics is the language of nature. 2. Everything around us can be represented and understood through numbers. 3. If you graph these numbers, patterns emerge. Therefore: There are patterns everywhere in nature.
Slavo (salmas64)
Jul 28 2010 at 15:34
5 poster
Thanks Kenny that's very useful information. Honestly I don't understand mechanics what's happening on broker's side. Why he has to enter opposite trade when I'm closing trade? I thought broker is passing and leveraging my trade somewhere 'farther away' 😄. Does it work other way as well? What broker does when I'm entering new trade? Has he closes his existing trade in opposite direction?

I really didn't notice OrderCloseBy() function. 😄 Thanks for the examples, so far I used in closing routine similar way like in your Close_All script.
In my case I have mixed bag of BUYs and SELLs, but not always equal ratio, but I can use OrderCloseBy() for pairs and OrderClose() for leftovers.

Vänligen logga in för att kommentera.