You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Ok so this is my code part that involves stop loss and take profit...I've tried to modify it with ticks but it gives me the same error in the tester....now I'm going to paste that
And this is the tester
This is the log....the retcode gives me 10013 which is also invalid request.
During the test, even when the price rises significantly on the chart, the log doesn't show any attempt to apply the trailing stop. The log only sporadically shows the trailing stop being attempted, and even then, it happens only immediately after opening an order.
Do you need me to share the part of the code where the trailing stop is implemented in the OnTick function?
Pietroalutto1 #:
You are mixing up the concepts of Positions and Orders. Don't think in the MT4 way. An open position is NEVER a "pending order". It is just an open position currently in the market, irrespective of what order created it.
The part I marked in red is useless. Take it out.
Please read the following article ...
The "PositionModify" method call you are using is for "netting" accounts, not "hedging" accounts. Which account type are you using?
For "hedging" accounts you should be using the method with a position ticket ...
The "PositionModify" method call you are using is for "netting" accounts, not "hedging" accounts. Which account type are you using?
For "hedging" accounts you should be using the method with a position ticket ...
thank you for the answer. I use hedging account
I paste the modified code so you can tell me if there are errors:
Then your entire "ApplyTrailingStop()" logic should be redesigned. It is assuming "netting" or single position, which on a "hedging" account is not the case.
You need to go through all the currently open positions, filtering by Symbol and Magic Number and then applying the trailing stop to each that fits your conditions.
Your EA's logic needs to be redesigned.
Then your entire "ApplyTrailingStop()" logic should be redesigned. It is assuming "netting" or single position, which on a "hedging" account is not the case.
You need to go through all the currently open positions, filtering by Symbol and Magic Number and then applying the trailing stop to each that fits your conditions.
Your EA's logic needs to be redesign
or maybe I can change to a netting account
No, don't be lazy! Make your code work properly for both types of accounts.
Study how to properly handle the trade functionality on MT5 ...