Hi
The test code below opens a buy trade at market price with a stop loss and take profit price 10 points from the market rate. If the market rate returned from the broker differs from the original market rate requested (ie. slips) the test code below uses PositionModify() method to modify the stop loss and take profit prices of the open position to be the same 10 points against the new market rate.
The code has been run in the strategy tester, on a hedging account, with delay set to 1000ms and modelling on real ticks to increase the possibility of generating a slippage.
What I have found is that the stop loss and take profit gets correctly adjusted by PositionModify() but it seems to also change the position's open price.
My understanding was PositionModify does not adjust the position's open price.
Is my understanding incorrect, what am I missing?
Below is the test code used.
In the attached Strategy Tester Journal output related to Ticket 36:
The price changed from the request price of 83.667 to the result price of 83.668 an increase of 1 point.
The stop loss and take profit prices have both been moved up by 1 point, as expected.
The modified price of 83.668 (which is derived from PositionSelectByTicket and POSITION_PRICE_OPEN property in code) is as I would expect it unchanged from the result price.
In the attached Strategy Tester Operations output for the same Ticket 36:
The position price looks like it has now been modified to 83.665. This is not what I would have expected. I would have expected to also see 83.668 here.
Am I misunderstanding PositionModify here or mis-interpreting the strategy tester operations output?
Thanks in advance for any clarification.
The open price was not modified, it can't be modified. The Strategy Tester just show what was the current price when you SL/TP were modified, that is 83.665
So I was interpreting the Strategy Tester output incorrectly.
Pity the price field works that way as it makes sense for opening positions, but I think it is misleading when modifying positions.
No matter. As a workaround I'll create an export file, with the values I would prefer to see in the price field.
Thanks Alain for your help with this.
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi
The test code below opens a buy trade at market price with a stop loss and take profit price 10 points from the market rate. If the market rate returned from the broker differs from the original market rate requested (ie. slips) the test code below uses PositionModify() method to modify the stop loss and take profit prices of the open position to be the same 10 points against the new market rate.
The code has been run in the strategy tester, on a hedging account, with delay set to 1000ms and modelling on real ticks to increase the possibility of generating a slippage.
What I have found is that the stop loss and take profit gets correctly adjusted by PositionModify() but it seems to also change the position's open price.
My understanding was PositionModify does not adjust the position's open price.
Is my understanding incorrect, what am I missing?
Below is the test code used.
In the attached Strategy Tester Journal output related to Ticket 36:
The price changed from the request price of 83.667 to the result price of 83.668 an increase of 1 point.
The stop loss and take profit prices have both been moved up by 1 point, as expected.
The modified price of 83.668 (which is derived from PositionSelectByTicket and POSITION_PRICE_OPEN property in code) is as I would expect it unchanged from the result price.
In the attached Strategy Tester Operations output for the same Ticket 36:
Am I misunderstanding PositionModify here or mis-interpreting the strategy tester operations output?
Thanks in advance for any clarification.