Hello,
I am not sure if this could be integrated into your EA, but I put a separate fonction that you can put at the end of the code and call during the main loop.
Make sure you have a global variable "Magic" that you are using when placing order:
----
int Magic;
-----
Also you need to set the number of pips in profit "ProfitModifySL" before you would like to set your stopLoss to the actual opening price:
----
extern double ProfitModifySL=15; // After being in 15 pips Profit Stoploss is adjusted to the opening price of the order
-----
//+------------------------------------------------------------------+
//| Scan through Order and if in profit by PrmSL Modify SL |
//+------------------------------------------------------------------+
void fModifySLWhenInProfit()
{
for (int i=0; i<OrdersTotal(); i++)
{
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if (OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if (OrderType()==OP_BUY && Bid-OrderOpenPrice()>=ProfitModifySL*Point)
fModifyStopLoss(OrderOpenPrice());
if (OrderType()==OP_SELL && OrderOpenPrice()-Ask>=ProfitModifySL*Point)
fModifyStopLoss(OrderOpenPrice());
}
}
}
}
//+------------------------------------------------------------------+
//| Modify Stop Loss |
//+------------------------------------------------------------------+
void fModifyStopLoss(double tStopLoss)
{
bool result = OrderModify(OrderTicket(),OrderOpenPrice(),tStopLo ss,OrderTakeProfit(),0,NULL);
}
Otherwise I attached to the post a simple EA that does it.
Hope this help
Cheers