Looking for a trailing stop function of sorts-when price hits a certain value above or below order open price, i want to move stoploss to even or better. Any help would be greatly appreciated!!! Thank you Dan
extern int Trailing_Stop=3;
extern int TP=5;
int start()
{int totalO = OrdersTotal();
int i, ticket;
if (totalO > 0){
for(i=OrdersTotal()-1;i>=0;i--)
{
if(OrderType()==OP_BUY && OrderOpenPrice()==Bid-Point*TP)
{
ticket=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+Point*Trailing_Stop,OrderTakeProfit(),0,Blue);
if(ticket<0) Print("OrderModify=",_OrderTicket[i]," StopLoss failed with error #",GetLastError());
}
if(OrderType()==OP_SELL && OrderOpenPrice()==Ask+Point*TP)
{
ticket=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-Point*Trailing_Stop,OrderTakeProfit(),0,Green);
if(ticket<0) Print("OrderModify=",_OrderTicket[i]," StopLoss failed with error #",GetLastError());
}
}
return(0);
}
couple of things I can see...
1: I dont think it can be == because it might gap above or below that criteria and so prevent the order mod.
rather make it something like >=
2: try this rather :
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderType()<=OP_SELL && OrderSymbol()==Symbol())
{
if(OrderType()==OP_BUY)
{
if(TrailingStop>0)
{
if(Bid-OrderOpenPrice()>=Point*TP)
{
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green);
return(0);
}
}
}
Replace
if(OrderType()==OP_BUY && OrderOpenPrice()==Bid-Point*TP)
to
if(OrderType()==OP_BUY && OrderOpenPrice()>Bid-Point*Trailing_Stop&& OrderStopLoss()>Bid-Point*Trailing_Stop)
and
if(OrderType()==OP_SELL && OrderOpenPrice()==Ask+Point*TP)
to
if(OrderType()==OP_SELL && OrderOpenPrice()<Ask+Point*Trailing_Stop&&(OrderStopLoss<Ask+Point*Trailing_Stop||OrderStopLoss()==0))
IMHO Trailing_Stop=3 it's too less.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Looking for a trailing stop function of sorts-when price hits a certain value above or below order open price, i want to move stoploss to even or better. Any help would be greatly appreciated!!! Thank you Dan
extern int Trailing_Stop=3;
extern int TP=5;
int start()
{int totalO = OrdersTotal();
int i, ticket;
if (totalO > 0){
for(i=OrdersTotal()-1;i>=0;i--)
{
if(OrderType()==OP_BUY && OrderOpenPrice()==Bid-Point*TP)
{
ticket=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+Point*Trailing_Stop,OrderTakeProfit(),0,Blue);
if(ticket<0) Print("OrderModify=",_OrderTicket[i]," StopLoss failed with error #",GetLastError());
}
if(OrderType()==OP_SELL && OrderOpenPrice()==Ask+Point*TP)
{
ticket=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-Point*Trailing_Stop,OrderTakeProfit(),0,Green);
if(ticket<0) Print("OrderModify=",_OrderTicket[i]," StopLoss failed with error #",GetLastError());
}
}
return(0);
}