Failed Modify #id [Position doesn't exist]

 

Hello,

I am new in MQL5 programming language and creating a simple expert advisor.

The problem is I've placed an order and then modified using Stop-Loss and Take-Profit. But I want to remodify my Stop-Loss and Take-Profit for the same order on specific market condition. But I can't do that. It's throwing an error :

2022.06.26 20:30:11.561 2022.06.01 03:06:41   failed modify #2 buy 59.99 USDJPY sl: 128.517, tp: 128.917 -> sl: 128.517, tp: 129.271 [Position doesn't exist].

Code used to execute when remodifying:

request.action = TRADE_ACTION_SLTP;
request.position = result.order;

I'm wondering if I can change the Stop-Loss and Take-Profit limit multiple time for the same order. Is this doable?

Note: My demo account is a Hedging Account. I tried to change the sltp limit when I was atleast .05 points away from Take-Profit and the market execution was perfect and also Stop-Loss and Take-Profit were accurate the first time. But when I tried to modify them again, it showed that message. Hope that would be enough.

 
Quamruzzaman: I am new in MQL5 programming language and creating a simple expert advisor. The problem is I've placed an order and then modified using Stop-Loss and Take-Profit. But I want to remodify my Stop-Loss and Take-Profit for the same order on specific market condition. But I can't do that. It's throwing an error :

2022.06.26 20:30:11.561 2022.06.01 03:06:41   failed modify #2 buy 59.99 USDJPY sl: 128.517, tp: 128.917 -> sl: 128.517, tp: 129.271 [Position doesn't exist].

Code used to execute when remodifying: I'm wondering if I can change the Stop-Loss and Take-Profit limit multiple time for the same order. Is this doable?

Note: My demo account is a Hedging Account. I tried to change the sltp limit when I was atleast .05 points away from Take-Profit and the market execution was perfect and also Stop-Loss and Take-Profit were accurate the first time. But when I tried to modify them again, it showed that message. Hope that would be enough.

Yes, you can modify the stops multiple times as long as it is within the limitations defined by your broker's contract specifications.

However, you will have to provide a larger section of your code if you want help. The information and code you provided is not sufficient to identify the problem.

 

Mistake number 1: You create an indicator handle on each tick - a gross mistake!!! According to the MQL5 style, the indicator handle should be created ONCE and should be done in OnInit.

Please correct this mistake!

 
Vladimir Karputov #:

Mistake number 1: You create an indicator handle on each tick - a gross mistake!!! According to the MQL5 style, the indicator handle should be created ONCE and should be done in OnInit.

Please correct this mistake!

Actually I'm learning from Andrew Young's book. That's why I still need to learn many things. In his book he initially showed us this approach. I'll definitely change my style. Thanks for your reply. Is this the one that is creating the error?
 
Quamruzzaman # :
Actually I'm learning from Andrew Young's book. That's why I still need to learn many things. In his book he initially showed us this approach. I'll definitely change my style. Thanks for your reply. Is this the one that is creating the error?

After that you should show your code. And only then it will be possible to look for the following errors.