trailing stops...

 
Greetings once again,

I was writing my own trailing stop routine from some of those examples that are often given. I noticed that my stop lines were eratic and decided to implement the following statement. I hope this helps anyone that has the same idea.

void TrailOrder(int type)
{
if(TrailingStop>0)
{
if(OrderMagicNumber() == MagicNumber)
{
if(type==OP_BUY)
{
if(Bid-OrderOpenPrice()>Point*TrailingStop)
{
if(OrderStopLoss()<Bid-Point*TrailingStop)
{
StopPriceL = MathMax(StopPriceL,Bid-Point*TrailingStop);
string ArrowCloseLongOrder=NewArrow(Time[0], StopPriceL, MediumSpringGreen);
Print("Ticket: ",OrderTicket()," LongTrailTime: ",mytime," Close: ",Close[0]," StopPrice: ",StopPriceL);
OrderModify(OrderTicket(),OrderOpenPrice(),StopPriceL,OrderTakeProfit(),0,Green);
}
}
}
if(type==OP_SELL)
{
if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
{
if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))
{
StopPriceS = MathMin(StopPriceS,Ask+Point*TrailingStop);
string ArrowCloseShortOrder=NewArrow(Time[0], StopPriceS, Yellow);
Print("Ticket: ",OrderTicket()," ShortTrailTime: ",mytime," Close: ",Close[0]," StopPrice: ",StopPriceS);
OrderModify(OrderTicket(),OrderOpenPrice(),StopPriceS,OrderTakeProfit(),0,Red);
}
}
}
}
}
}
Reason: