I've been working on more dynamic (or refined and redundant) exit algorithms for MT4 EAs.
For example, instead of getting out at predefined stop price levels and TP price levels, or entry signal reversals...instead using a percentage of price movement or combining it with an increase/decrease in AccountEquity() or an increase/decrease in AccountProfit() or other combinations that are not simply related static prices.
For example using percentage price movement:
Or using a move in AccountEquity():
My question is this... How would I or anyone go about making the second example above into a "trailing profit"? For example, lets say the variable EQS is preset to 4.0, in other words if/when AccountProfit (lets say $2025) exceeds AccountBalance (lets say $500), then close. But I'd like to trail this in case the trade goes sour. So lets say, if AccountProfit exceeds AccountBalance by 40%, exit if the profit drops to 20%.
The concept of coding a price trailing stop with OrderModify is something that will not work in this case, since I don't want this shown as a pending order, but a hidden signal.
Has anyone have any experience implementing a similar concept? Any ideas and code examples would help tremendously.
For example, instead of getting out at predefined stop price levels and TP price levels, or entry signal reversals...instead using a percentage of price movement or combining it with an increase/decrease in AccountEquity() or an increase/decrease in AccountProfit() or other combinations that are not simply related static prices.
For example using percentage price movement:
Inserted Code
if ((OrderMagicNumber() == Magic1) && (SafetyStop == true)) { if (OrderType() == OP_BUY && (iHigh(NULL,1,1) < NormalizeDouble(OrderOpenPrice()-(OrderOpenPrice()*SLX),5) && iHigh(NULL,1,1) < NormalizeDouble(OrderOpenPrice()-(OrderOpenPrice()*SLX),5)) ) result = OrderClose( OrderTicket(), OrderLots(), Bid, 50, Red ); if (OrderType() == OP_SELL && (iLow(NULL,1,1) > NormalizeDouble(OrderOpenPrice()+(OrderOpenPrice()*SLX),5) && iHigh(NULL,1,1) > NormalizeDouble(OrderOpenPrice()+(OrderOpenPrice()*SLX),5)) ) result = OrderClose( OrderTicket(), OrderLots(), Ask, 50, Red ); }
Or using a move in AccountEquity():
Inserted Code
if ((OrderMagicNumber() == Magic1) && (UseAccountProfit == true)) { if (OrderType() == OP_BUY && (AccountProfit() > AccountBalance()*EQS) ) result = OrderClose( OrderTicket(), OrderLots(), Bid, 50, Red ); if (OrderType() == OP_SELL && (AccountProfit() > AccountBalance()*EQS) ) result = OrderClose( OrderTicket(), OrderLots(), Ask, 50, Red ); }
My question is this... How would I or anyone go about making the second example above into a "trailing profit"? For example, lets say the variable EQS is preset to 4.0, in other words if/when AccountProfit (lets say $2025) exceeds AccountBalance (lets say $500), then close. But I'd like to trail this in case the trade goes sour. So lets say, if AccountProfit exceeds AccountBalance by 40%, exit if the profit drops to 20%.
The concept of coding a price trailing stop with OrderModify is something that will not work in this case, since I don't want this shown as a pending order, but a hidden signal.
Has anyone have any experience implementing a similar concept? Any ideas and code examples would help tremendously.