Download MetaTrader 5
To add comments, please log in or register
Traders have already contributed more than 300 articles. Write your own one!
gszabo
108
gszabo 2012.08.24 11:05 

I tried to use this fields but the Back Tester ignored them. When and how to use this fields? And there is a StopLimit fiels as well. What to know about it?.

Thanks

Gabor

Pawel Wojnarowski
685
Pawel Wojnarowski 2012.08.24 11:15  
gszabo:

I tried to use this fields but the Back Tester ignored them. When and how to use this fields? And there is a StopLimit fiels as well. What to know about it?.

Thanks

Gabor

https://www.mql5.com/en/docs/constants/structures/mqltraderequest

By the way, why do you think that the Strategy Tester ignored them? 

Documentation on MQL5: Standard Constants, Enumerations and Structures / Data Structures / Trade Request Structure
Documentation on MQL5: Standard Constants, Enumerations and Structures / Data Structures / Trade Request Structure
  • www.mql5.com
Standard Constants, Enumerations and Structures / Data Structures / Trade Request Structure - Documentation on MQL5
shemz
3
shemz 2013.01.31 15:47  

Its an old thread, but can someone please explain about this?

I used the step by step manual (https://www.mql5.com/en/articles/100) to prototype a simple time and price limited scalping strategy. But the stop loss and take profit are not executed in the back tester. It waits until an opposite order is placed.

Step-By-Step Guide to writing an Expert Advisor in MQL5 for Beginners
Step-By-Step Guide to writing an Expert Advisor in MQL5 for Beginners
  • 2010.06.09
  • Samuel
  • www.mql5.com
The Expert Advisors programming in MQL5 is simple, and you can learn it easy. In this step by step guide, you will see the basic steps required in writing a simple Expert Advisor based on a developed trading strategy. The structure of an Expert Advisor, the use of built-in technical indicators and trading functions, the details of the Debug mode and use of the Strategy Tester are presented.
Miguelito Yap
640
Miguelito Yap 2013.02.01 18:21  

The answer is in the link already posted.  Defined fields may or may not be used depending on the type of execution.

phi nuts
2184
phi nuts 2013.02.02 10:22  
shemz:

Its an old thread, but can someone please explain about this?

I used the step by step manual (https://www.mql5.com/en/articles/100) to prototype a simple time and price limited scalping strategy. But the stop loss and take profit are not executed in the back tester. It waits until an opposite order is placed.

I'm not so sure if my answer here is 100% correct. This question does have relation with how brokers and banks process our trades -  and Strategy Tester does reflects what brokers does to our trades .

MT5 is position based trading trade platform (MT4 is ticket (or order) based trading), which mean in position based trading, to close a position we must open opposite position with the same lot, while in ticket based trading, to close a position, we use SL, TP or just simply close it.

Here's an example, in position based trading, when you trade to open position to sell (or buy) - say GBPJPY, to close that position, you must trade back by buy back (or sell back) that GBPJPY with the same volume. For this reason, we don't recommend using SL and TP when open a position with MT5, instead you should use stop-pending orders as TP and limit-pending orders as SL. So right after successful opening a position, immediately open pending orders for TP and SL. As you can see, you actually open three positions instead of one position with TP and SL.

Remember broker trades (read : buy and sell) with banks. What happen here, when we open one position and two pendings, broker send all those three orders to bank and at the set price, bank will execute two of them immediately - one for opening a position and the other one is either the pending for the SL or TP (you have to delete the other pending).

In ticket based trading, broker will only send one order to bank to open a position, the SL and the TP will stay with broker and will never be sent to banks. When price for TP (or SL) is reached, broker will try to close your position by trade back your position which is by send an opposite position to a bank with the same volume. This will lead that your position may not be closed at the right price. 

If your broker use ticket based trading system, ask this question : do your broker have a guaranteed stop ? Pretty much, the answer is no, which mean that there's no guarantee that your SL and TP will be executed at the price you set. For example, if you set SL at 30 pips, your position may get closed at 32, or 35 or what ever pips (if you're lucky you get closed at less than 30:) ). 

Not in position based trading, since all three orders were sent to bank, bank will executed two of them without waiting for broker or your request.

So why, there's still a SL and TP in MT5 ?, that's because there are some broker that still offer to use SL and TP to close a position - and so they are also don't offer guaranteed stop. 

Hope that's help :) 

Alain Verleyen
Moderator
30206
Alain Verleyen 2013.03.08 18:51  
phi.nuts:

I'm not so sure if my answer here is 100% correct. This question does have relation with how brokers and banks process our trades -  and Strategy Tester does reflects what brokers does to our trades .

MT5 is position based trading trade platform (MT4 is ticket (or order) based trading), which mean in position based trading, to close a position we must open opposite position with the same lot, while in ticket based trading, to close a position, we use SL, TP or just simply close it.

Here's an example, in position based trading, when you trade to open position to sell (or buy) - say GBPJPY, to close that position, you must trade back by buy back (or sell back) that GBPJPY with the same volume. For this reason, we don't recommend using SL and TP when open a position with MT5, instead you should use stop-pending orders as TP and limit-pending orders as SL. So right after successful opening a position, immediately open pending orders for TP and SL. As you can see, you actually open three positions instead of one position with TP and SL.

Remember broker trades (read : buy and sell) with banks. What happen here, when we open one position and two pendings, broker send all those three orders to bank and at the set price, bank will execute two of them immediately - one for opening a position and the other one is either the pending for the SL or TP (you have to delete the other pending).

In ticket based trading, broker will only send one order to bank to open a position, the SL and the TP will stay with broker and will never be sent to banks. When price for TP (or SL) is reached, broker will try to close your position by trade back your position which is by send an opposite position to a bank with the same volume. This will lead that your position may not be closed at the right price. 

If your broker use ticket based trading system, ask this question : do your broker have a guaranteed stop ? Pretty much, the answer is no, which mean that there's no guarantee that your SL and TP will be executed at the price you set. For example, if you set SL at 30 pips, your position may get closed at 32, or 35 or what ever pips (if you're lucky you get closed at less than 30:) ). 

Not in position based trading, since all three orders were sent to bank, bank will executed two of them without waiting for broker or your request.

So why, there's still a SL and TP in MT5 ?, that's because there are some broker that still offer to use SL and TP to close a position - and so they are also don't offer guaranteed stop. 

Hope that's help :) 

Your response, while interesting in either,  is not related to the asked problem. For it, the question is to know if you have a Instant Execution or a Market Execution. This is related to broker.

In your case, it seems to be a lot of speculation about the flow of orders. Do you have any references to support your statements?

Pasi Hakamaki
4369
Pasi Hakamaki 2013.03.09 10:08  
Me too am interested in knowing where you got this interesting info :)
phi nuts
2184
phi nuts 2013.03.09 11:03  
angevoyageur:

Your response, while interesting in either,  is not related to the asked problem. For it, the question is to know if you have a Instant Execution or a Market Execution. This is related to broker.

In your case, it seems to be a lot of speculation about the flow of orders. Do you have any references to support your statements? 

Me too am interested in knowing where you got this interesting info :)

Some from my experience and some from my conversation in the past with a friend of mine who run a broker (but does not own it).

Here's a simple example, say that US Dollar will go up and you buy US Dollar directly from your local bank or money changer, or say that gold price will go up, and you buy some gold from some jewellery store.

Question is, how do you sell your 'position' in that US Dollar and Gold ? Well, sell it back ! to bank, money changer and jewellery store.

Same thing goes with broker, since we don't trade directly with banks, it's our broker job to trade (buy and sell) with the banks. And that's how trading is, there's always sell for every buy and there's always buy for every sell - (do I really have to explain that in writing ?).

Anyway,  Since built 773, SL and TP are executed properly.

Alain Verleyen
Moderator
30206
Alain Verleyen 2013.03.09 12:10  
phi.nuts:

I'm not so sure if my answer here is 100% correct. This question does have relation with how brokers and banks process our trades -  and Strategy Tester does reflects what brokers does to our trades . Ok, but I suppose not every broker process those the same way.

MT5 is position based trading trade platform (MT4 is ticket (or order) based trading), which mean in position based trading, to close a position we must open opposite position with the same lot, while in ticket based trading, to close a position, we use SL, TP or just simply close it.

Here's an example, in position based trading, when you trade to open position to sell (or buy) - say GBPJPY, to close that position, you must trade back by buy back (or sell back) that GBPJPY with the same volume. For this reason, we don't recommend (who are "we" ?) using SL and TP when open a position with MT5, instead you should use stop-pending orders as TP and limit-pending orders as SL. So right after successful opening a position, immediately open pending orders for TP and SL. As you can see, you actually open three positions instead of one position with TP and SL. Technically speaking, this is not true, you have only 1 position, pending orders are not position. Anyway your recommendation is a good method to manage multiples trades on one symbol with mt5. But if you have only one trade at a time by symbol, you can safelly use SL and TP. 

Remember broker trades (read : buy and sell) with banks. What happen here, when we open one position and two pendings, broker send all those three orders to bank and at the set price, bank will execute two of them immediately - one for opening a position and the other one is either the pending for the SL or TP (you have to delete the other pending). I don't think that it's true for all broker. Process you describe is for an ECN broker no ?

In ticket based trading, broker will only send one order to bank to open a position, the SL and the TP will stay with broker and will never be sent to banks. When price for TP (or SL) is reached, broker will try to close your position by trade back your position which is by send an opposite position to a bank with the same volume. This will lead that your position may not be closed at the right price. I don't see the relation between position (MT5) or ticket (MT4) and the way broker process ours orders. In all cases brokers execute ours orders in one way or another and the RESULT is either a unique position (=MT5) or multiples positions (=MT4 where position is named order).

If your broker use ticket based trading system, ask this question : do your broker have a guaranteed stop ? Pretty much, the answer is no, which mean that there's no guarantee that your SL and TP will be executed at the price you set. For example, if you set SL at 30 pips, your position may get closed at 32, or 35 or what ever pips (if you're lucky you get closed at less than 30:) ). Here also I dont'see relation between ticket/position model and guarenteed stop. It seem to me that a stop is never guaranteed, it depend on liquidity, am I wrong ?

Not in position based trading, since all three orders were sent to bank, bank will executed two of them without waiting for broker or your request. And what if the bank can't provide you the price of your pending order ?

So why, there's still a SL and TP in MT5 ?, that's because there are some broker that still offer to use SL and TP to close a position - and so they are also don't offer guaranteed stop. Pure speculation I think. Broker must always offer sl and tp, otherwise find another broker (MT5 or not).

Hope that's help :) 

My are highlighted in vert. My comments are in blue. Friendly, do not see anything personal.
phi nuts
2184
phi nuts 2013.03.10 12:27  
angevoyageur:
My are highlighted in vert. My comments are in blue. Friendly, do not see anything personal.

No, I don't mind and no problem at all.

Just one thing to remember, my answer there were based on problem that SL and TP were not executed, and so we had to use opposite pending orders instead of SL and TP.

It seem like I have to explain how brokers works to understand why some broker does not accept SL and TP - which I think it's gonna be long explanation for this, so I hope you don't mind waiting and being patient a little.

I'm guessing that you also never try other trade platform like currenex or cqg, where Order Cancel the Other (OCO) is available, am I correct ? 

Currenex
  • www.currenex.com
Offering Executable Streaming Prices (ESP™), Request For Streams (RFS), Benchmark Trading, Algorithmic Trading, and complete Prime Brokerage functionality with fully integrated...
Alain Verleyen
Moderator
30206
Alain Verleyen 2013.03.10 12:40  
phi.nuts:

No, I don't mind and no problem at all.

Just one thing to remember, my answer there were based on problem that SL and TP were not executed, and so we had to use opposite pending orders instead of SL and TP.

It seem like I have to explain how brokers works to understand why some broker does not accept SL and TP - which I think it's gonna be long explanation for this, so I hope you don't mind waiting and being patient a little.

I'm guessing that you also never try other trade platform like currenex or cqg, where Order Cancel the Other (OCO) is available, am I correct ? 

Do not feel obliged to develop long explanations.

You are correct, I only have experienced with MT4 and MT5.

/ /12
To add comments, please log in or register