t/p is not working properly - page 2

 
krishna_gopal_2:
Fine. Now what should I do to get more or less 100pips. Is there any formula to calculate Spread? 
Ask - Bid is the Spread.
 
krishna_gopal_2:
Fine. Now what should I do to get more or less 100pips. Is there any formula to calculate Spread? 
If you set your TP correctly, you will get 100 pips (more or less because ticks are emulated) for your winning trade in the Strategy Tester.
  • If you open a SELL at price X (bid) then set your TP at BID price - 100 pips.
  • If you open a BUY at price Y (ask) then set your TP at ASK + 100 pips.

About your initial post :

  • either you don't set a TP of 100 pips
  • or what you publish aren't winning trade
  • or you miscalculated your profit (pips)
  • or your trades aren't closed by TP.
 

  • If you open a SELL at price X (bid) then set your TP at BID price - 100 pips.
  • If you open a BUY at price Y (ask) then set your TP at ASK + 100 pips.


I think this has a small mistake, I'm not sure...

Like I said before, with an OP_SELL, you open at the bid price, then close at the ask price...so if the TP is bid - 100, your profit will be 100 pips minus the spread.

Also, any TP that is based on the Bid and Ask at time of opening assumes that the spread is constant. I've done a lot of research on it recently and the spread is never completely constant. This won't show up in backtesting because MT4 doesn't save the Ask price (I think?? Does it use close price + current spread???), but you need to consider the real world too.

 
alladir:


  • If you open a SELL at price X (bid) then set your TP at BID price - 100 pips.       use   OrderOpenPrice()
  • If you open a BUY at price Y (ask) then set your TP at ASK + 100 pips.

I think this has a small mistake, I'm not sure...

Like I said before, with an OP_SELL, you open at the bid price, then close at the ask price...so if the TP is bid - 100, your profit will be 100 pips minus the spread.

Also, any TP that is based on the Bid and Ask at time of opening assumes that the spread is constant. I've done a lot of research on it recently and the spread is never completely constant. This won't show up in backtesting because MT4 doesn't save the Ask price (I think?? Does it use close price + current spread???), but you need to consider the real world too.


make it open first the trade then modify it using its orderopenprice( ) will make it work on all accounts
 
deVries:

make it open first the trade then modify it using its orderopenprice( ) will make it work on all accounts


No, this is still not right.

for short orders, the spread is taken when the order is CLOSED, not before, so using OrderOpenPrice  still gives a profit of:   100 pips minus spread at time of closing.

 

Getting a TP of 100 pips for long orders is easy.

For short orders, you have to make the TP as OrderOpenPrice + 100 pips + spread

(and hope that the spread is near constant). 

 
alladir:


I think this has a small mistake, I'm not sure...

Like I said before, with an OP_SELL, you open at the bid price, then close at the ask price...so if the TP is bid - 100, your profit will be 100 pips minus the spread.


Also, any TP that is based on the Bid and Ask at time of opening assumes that the spread is constant. I've done a lot of research on it recently and the spread is never completely constant. This won't show up in backtesting because MT4 doesn't save the Ask price (I think?? Does it use close price + current spread???), but you need to consider the real world too.

  • No. For a SELL, trade open at bid (BID_OPEN), closed at tp, so when ask = BID_OPEN-100. Profit = Open price - Close price = BID_OPEN  - BID_OPEN + 100 = 100.
  • For a BUY, trade open at ask (ASK_OPEN), closed at tp, so when bid = ASK_OPEN+100. Profit = Close price - Open price = ASK_OPEN + 100 - ASK_OPEN = 100.

Floating spread or not, this remains true.

BUT

  • For a sell the price have to move from bid at open time to bid at close time, so from BID_OPEN to BID_OPEN - 100 - SPREAD_CLOSE. The move is 100 + spread at close time. If spread is widened near close time, the probability to close to trade is reduced.
  • For a buy the price have to move from ASK_OPEN - SPREAD_OPEN to ASK_OPEN + 100, so here you know from the start how much the price have to move (100 + spread at open time).

You are right about spread is never completely constant, you have to check it and choose a broker who provides what he promised (check it).

 
deVries:

make it open first the trade then modify it using its orderopenprice( ) will make it work on all accounts
You are right, this is to easiest way to program it. But I am not talking of any programming language, before programming, it's better to understand how it works.
 
angevoyageur:
  • No. For a SELL, trade open at bid (BID_OPEN), closed at tp, so when ask = BID_OPEN-100. Profit = Open price - Close price = BID_OPEN  - BID_OPEN + 100 = 100.


I'm still a noob so excuse me if I've been wrong all this time. But I was certain that for a short order, the TP was triggered when the BID price reaches the TP level, but the trade is closed using ASK price.... it's the weekend now so I can't test but really..... is this not the case? Do TP's get triggered by ASK price on short trades and BID price on long trades? And if so, what happens in backtesting when ASK prices aren't available?

 

As for spread, I wrote a tick collector which then plots various broker's spreads on one chart for comparison. I've found some of them are exactly constant except when news is released, but some of them have quite variable spreads... some of them even look like the Ask price is delayed by about 100ms (i.e. spread is too big when price suddenly falls, and too small when price suddenly rises).... 

 
angevoyageur:
  • No. For a SELL, trade open at bid (BID_OPEN), closed at tp, so when ask = BID_OPEN-100. Profit = Open price - Close price = BID_OPEN  - BID_OPEN + 100 = 100.
  • For a BUY, trade open at ask (ASK_OPEN), closed at tp, so when bid = ASK_OPEN+100. Profit = Close price - Open price = ASK_OPEN + 100 - ASK_OPEN = 100.

Floating spread or not, this remains true. 

Nope,  this isn't correct.  Take a hypothetical example where a trade is opened and then immediately closed,  the loss is due to the spread.  Using your calculation above for the SELL  Profit = Open price - Close price = BID_OPEN  - BID_OPEN + 0 = 0.  but this is not the correct answer because the Spread has to be paid. 

It should be this . . .  Profit = Open price - Close price = BID_OPEN  - ASK_OPEN + 0 = -Spread.  . . . .  but this assumes that the Spread is the same from the open time to the close time.

 
alladir:


I'm still a noob so excuse me if I've been wrong all this time. But I was certain that for a short order, the TP was triggered when the BID price reaches the TP level, but the trade is closed using ASK price.... it's the weekend now so I can't test but really..... is this not the case? Do TP's use ASK price on short trades and BID price on long trades? And if so, what happens in backtesting when ASK prices aren't available?

Don't worry, we have all to pass by this stage, test it again and again, it's the best way to learn. What is closing a SELL trade ? It's a BUY! So this BUY is taken at ask price, which ask price ? The TP of the sell.

Backtesting on week-end gives you the spread when the trading session is closed on friday evening. Ask is always simple Bid+Spread. That can give you big spread when baktesting on week-end as genrally the spread is widened at the end of the session.