Good Evening,
I have been trying to develop a trail stop using percentage but not having much luck. This trail stop seems to stop out at the initial trailing stop pips and I can't figure out why. This EA is a modified version of the one on the forex blog with help from admin. However it seems to stop out after 7 pips. My goal is to get this EA working and then modify it again for different trail stop levels such as
10 pips - 20%
20 pips - 40 % etc up to 60 pips at 70%.
Help appreciated.
I have been trying to develop a trail stop using percentage but not having much luck. This trail stop seems to stop out at the initial trailing stop pips and I can't figure out why. This EA is a modified version of the one on the forex blog with help from admin. However it seems to stop out after 7 pips. My goal is to get this EA working and then modify it again for different trail stop levels such as
10 pips - 20%
20 pips - 40 % etc up to 60 pips at 70%.
Help appreciated.
MQL4:
#property copyright "Campbell Congdon" #property link "campbell_congdon@hotmail.com" extern double InitialTrailingStop = 8; extern double trailing_stop_percentage = 20; // Set it to some value above 0 to activate stop-loss extern double StopLoss = 0; //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() {double PointValue; for (int i = 0; i < OrdersTotal(); i++) { OrderSelect(i, SELECT_BY_POS, MODE_TRADES); //Calculate the point value in case there are extra digits in the quotes if (MarketInfo(OrderSymbol(), MODE_POINT) == 0.00001) PointValue = 0.0001; else if (MarketInfo(OrderSymbol(), MODE_POINT) == 0.001) PointValue = 0.01; else PointValue = MarketInfo(OrderSymbol(), MODE_POINT); //Normalize trailing stop value to the point value double TSTP = InitialTrailingStop * PointValue; if (OrderType() == OP_BUY) { if ((trailing_stop_percentage > 0) && (Bid - OrderOpenPrice() >= TSTP)) { TSTP = NormalizeDouble((Bid - OrderOpenPrice()) * trailing_stop_percentage / 100, Digits); { if (OrderStopLoss() < (Bid - TSTP)) { OrderModify(OrderTicket(), OrderOpenPrice(), Bid - TSTP, OrderTakeProfit(), Red); } } } else if ((OrderStopLoss() != Bid - StopLoss * PointValue) && (StopLoss != 0)) OrderModify(OrderTicket(), OrderOpenPrice(), Bid - StopLoss * PointValue, OrderTakeProfit(), Red); } else if (OrderType() == OP_SELL) { if ((trailing_stop_percentage > 0) && (OrderOpenPrice() - Ask >= TSTP)) { TSTP = NormalizeDouble((OrderOpenPrice() - Ask) * trailing_stop_percentage / 100, Digits); { if ((OrderStopLoss() > (Ask + InitialTrailingStop * PointValue)) || (OrderStopLoss() == 0)) { OrderModify(OrderTicket(), OrderOpenPrice(), Ask + TSTP, OrderTakeProfit(), Red); } } } else if ((OrderStopLoss() != Ask + StopLoss * PointValue) && (StopLoss != 0)) OrderModify(OrderTicket(), OrderOpenPrice(), Ask + StopLoss * PointValue, OrderTakeProfit(), Red); } } //---- //---- return(0); } //+------------------------------------------------------------------
Last edited by a moderator: