Forget trailing stop :) If it makes sense to simply use a take profit of the previous orders loss (example: last order's loss = -$10.00... So the current take profit is +$10.00) then maybe this makes things a bit easier to understand.
I suppose using a take profit would be easier to code than a break even (though i believe that it can be done). For now, we could simply use a take profit instead of break even to keep it simple.
BOTTOM LINE: The current "take profit" needs to be modified to a positive value of the last order's loss (if the last order loses). The "take profit" will change to a positive value of the last order's loss whenever the last order loses.
I hope this helps u ubzen & thank you much for your post!
I usually use something like this on a System-Level. Example:
if(AccountEquity()>=Equity_High){Close_All_Orders();} //Where Equity_High=Highest Equity Ever Reached.
Something Similar could be done via Order-Level. Example:
Return Last_Historical_Order_Profit(), If that value is <Than 0. Return Active_Market_Order_Profit(). If that value is >Than the Math_Absolute(Last_Profit) then Close Active_Order.
Biggest difference between the two examples is that the Top is always looking for break-even where as the bottom is only looking to recover the last order losses.
I'll give it a shot. I have to stare at the code to fully grasp its purpose and usefulness when used by my strategy.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Ok, here is my game plan amigos. Lets say I just placed a (short) sell order and it loses. Next, the strategy wants to place a new order (or sell order) with a "break even" that recovers the last (short) sell order's loss.
Example: (short) sell order closes with -$10.00 loss. Next, the strategy opens a buy OR sell order with a break even at +$10.00 when price reaches a certain "goal" which could be idk... +$12.00. (we'll just say that we are trading with 0.01 lots to make this example simple and easy to understand. Ok, the reason I want a "break even" and NOT a "Take Profit" is because there could be a possibility for the market to keep moving in a "positive" direction". (If the market continues to move in a positive direction, Obviously I would rather let the "profits run" with a break even and not "quit" with a take profit when the "target" has been reached. I am aware of market retracements or reversals which will trigger closing of the order when break even is hit, but I will solve this problem once I have solved this issue first.
I was thinking along the lines of something like this...
OrderSelect(ticket, SELECT_BY_TICKET,MODE_TRADES); // (sell order "ticket")
if (OrderProfit < 0) {
{
bool sell order loss = true;
}}
if (sell order loss == true) {
{
int buy order break even = "a positive value of the last sell order's loss";
}}
/*
I know, I gotta burn a few candles and be up all night for a week to iron this whole thing out, but I -
was hoping that a member of mql4 has already "crossed this bridge" and could post a suggestion -
before I begin the "nighttime grind". haha. - joke is on me ;) + thanks much.
*/