Static Trailing stop or Dynamic

 
Static Trailing stop or Dynamic for scalping?
 

Pending Trailing - expert for MetaTrader 5

The EA belongs to the utility class. It works with all pending orders installed in the terminal. Pulls a pending order after the price.

The figure below shows HOW PENDING ORDERS WORK -



 
gouki1001:
Static Trailing stop or Dynamic for scalping?

Any EA you write should have—at a minimum—trailing stop methods based upon fixed, percent, and ATR.

Then you can back test and find which works best for your specific instrument, time frame, volatility, etc.

 

I doubt the usefulness of a trailing stop, because the trade closes on the stop in the worst position. You need to manage both opening and closing trades yourself. Here is the best trailing stop, but better without it. Code MT4:

//the StopLoss is kept at a Distance from the most extreme shadow of the last Number hours
int DoTrailOrders(double eDistance, double eHoursNumber, int eMagicNumber, string eSymbol, int eTimeFrame)
   {
   int eDigits=(int)MarketInfo(eSymbol,MODE_DIGITS);
   eDistance*=MarketInfo(eSymbol,MODE_POINT);
   double eSpread=MarketInfo(eSymbol,MODE_SPREAD)*MarketInfo(eSymbol,MODE_POINT);
   int eBarsNumber=(int)MathMax(MathCeil(3600.0/PeriodSeconds(eTimeFrame)*eHoursNumber),1);
   double eExtremum;
   int ePosition, eTotal=OrdersTotal(), eType;
   for(ePosition=0; ePosition<eTotal; ePosition++)
      {
      if(!OrderSelect(ePosition,SELECT_BY_POS,MODE_TRADES))
         {
         //error handling
         continue;
         }
      eType=OrderType();
      if(eType!=OP_BUY && eType!=OP_SELL) continue;
      if(OrderMagicNumber()!=eMagicNumber) continue;
      if(OrderSymbol()!=eSymbol) continue;
      //we observe starting from the bar following the opening bar
      if(iBarShift(eSymbol,eTimeFrame,OrderOpenTime())==0) continue;
      if(eType==OP_BUY)
         {
         //the stop is set at the eDistance from the lowest shadow of the bar in the history of eBarsNumber
         eExtremum=iLow(eSymbol,eTimeFrame,iLowest(eSymbol,eTimeFrame,MODE_LOW,eBarsNumber,1));
         //the distance from the minimum to StopLoss must exceed the TrailingLevel
         if(NormalizeDouble(eExtremum-OrderStopLoss(),eDigits)<=eDistance && OrderStopLoss()>0) continue;
         //the distance from the minimum to the opening price must exceed the TrailingLevel
         if(NormalizeDouble(eExtremum-OrderOpenPrice(),eDigits)<=eDistance) continue;
         //the new stop must be no closer to the current price than two spreads
         if(NormalizeDouble(MarketInfo(eSymbol,MODE_BID)-eExtremum+eDistance,eDigits)<=eSpread) continue;
         
         if(!OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(eExtremum-eDistance,eDigits),OrderTakeProfit(),OrderExpiration(),clOpenBuy))
            {
            //error handling
            }
         }
      if(eType==OP_SELL)
         {
         eExtremum=iHigh(eSymbol,eTimeFrame,iHighest(eSymbol,eTimeFrame,MODE_HIGH,eBarsNumber,1));
         if(NormalizeDouble(OrderStopLoss()-eExtremum,eDigits)<=eDistance && OrderStopLoss()>0) continue;
         if(NormalizeDouble(OrderOpenPrice()-eExtremum,eDigits)<=eDistance) continue;
         if(NormalizeDouble(eExtremum+eDistance-MarketInfo(eSymbol,MODE_ASK),eDigits)<=eSpread) continue;
         if(!OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(eExtremum+eDistance,eDigits),OrderTakeProfit(),OrderExpiration(),clOpenSell))
            {
            //error handling
            }
         }
      }
   return(0);
   }
Reason: