Help! - How to make trailing stop loss take losses?

thread: Help! - How to make trailing stop loss take losses?

  1. #1

    Help! - How to make trailing stop loss take losses?

    I get unwanted profit when running trailing stop loss because the code does not account for the commission and swap,
    I tried the followings which don't work
    require help, thanks!



    Void LongTrailingStop()

    int lcnt;
    int ltotal = OrdersTotal();
    dual BuyProfit;

    for(lcnt=ltotal-1; lcnt gt;= 0; lcnt--)

    OrderSelect(lcnt, SELECT_BY_POS, MODE_TRADES);
    if(OrderType()lt;=OP_SELL OrderSymbol()==Symbol())

    if(OrderType()==OP_BUY) // long position is started

    if(TrailingStopgt;0)

    if(Bid-OrderOpenPrice()gt;(Point*TrailingStop))

    if(OrderStopLoss()lt;Bid-(Point*TrailingStop))

    BuyProfit = (OrderProfit() OrderCommission() OrderSwap());
    OrderModify(OrderTicket(),OrderOpenPrice(),Bid-(Point*TrailingStop BuyProfit),OrderTakeProfit(),0,Green);
    return(0);

  2. #2
    Thanks for your reply,

    OrderModify(OrderTicket(),OrderOpen Price(),Bid-(Point*TrailingStop BuyProfit),Orde rTakeProfit(),0,Green);
    return(0);

    does Not work, error 130

    for trailing stop, I use OrderModify, along with
    bool OrderModify( int ticket, double price, double stoploss, double takeprofit, datetime Expiry, Colour arrow_color=CLR_NONE)

    and by default the double stoploss does not take into account the Price of trading.

    Stop loss which I coded Bid-(Point*TrailingStop BuyProfit) doesn't have more work.

    Maybe I should ask, how do I code a trailing stop maybe not that will take into account the cost of trading when quitting losses?

  3. #3
    Member
    71
    Hi johnny,

    From your code, it would appear that you presume OrderProfit() has just one point unit price.
    OrderProfit() does not equal to Bid-OrderOpenPrice(). If OrderProfit() return a value of 1, then it does not mean your profit is 1 point.
    OrderProfit() depends on your lot size, calculated as follows:
    1 pips = 10 point = $10
    for buy order, OrderProfit() = lotsize*(Bid-OrderOpenPrice)/(10*point)*$10

    expect this support

  •