A solution for a long position could be as follows:
double max_quote = (max_quote < current_quote) ? current_quote : max_quote; double percentage = ((position_TP - max_quote) / (position_TP - open_price)); double stop_out = max_quote - (max_profit * perccentage); if(stop_out > current_quote) { ClosePosition(); }
untested pseudocode but it should give an idea on how it could be approached.
EDIT:
you will need to take measures to track each single positions values according to their parameters. Especially you need to store the value max_quote for each position, or recalculate it every time based on opening time and quote.
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
Hi, I am trying to complete the code for a tight trailing stop for my EA. The Trailing Stop I currently have is such as that only when the trade is much closer to the TP, is when the actual SL is moved up, but I want to make a trailing stop that stays exactly the same distance from the current price, as the price level moves closer to the TP, any advice would be helpful.
Here is the code: