Help! - How to make trailing stop not take losses when negative profit?
Results 1 to 6 of 6

Thread: Help! - How to make trailing stop not take losses when negative profit?

  1. #1
    I am back testing utilizing MB trading demo. Th standard will not take into account of the commission and order swap.
    Anyone had tried successful to have the trailing cease not take reductions with adverse profit?

    Typical trailing stop code:

    void ShortTrailingStop()

    int scnt;
    int stotal = OrdersTotal();

    for(scnt=stotal-1; scnt gt;= 0; scnt--)

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

    if(OrderType()==OP_SELL) // short position is started

    if(TrailingStopgt;0)

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

    if((OrderStopLoss()gt;(Ask (Point*TrailingStop)))

  2. #2
    Easy. Only have the trailing code add up the profit=profit OrderProfit() and refuse to cashout unless the profitgt;0. - You'll have to shut the orders by program code rather than using a in-order stoploss.

  3. #3
    Thanks for your answer,

    Then it doesn't track, it will just take profit if there's profit
    demand OrderModify() work for trailing,
    but the double stoploss Parameter is the cause of the problem. It won't work with commissioned broker.

    Is there a way to work with this?

  4. #4
    Quote Originally Posted by ;
    I'm back analyzing ...

    if(OrderType()lt;=OP_SELL OrderSymbol()==Symbol())
    {
    if(OrderType()==OP_SELL) // short position is opened
    {
    Well Im not too sure if it would alter the final result of the code right now, but I believe I've seen this little bit mentioned in some other thread recently.

    If(OrderType()lt;=OP_SELL
    will probably always be accurate, something to do with OrderType() is not a number.
    I believe you get away with it cause your next when() ie
    if(OrderType()==OP_SELL)
    Watch in this 1 you are assessing if it is equal to OP_SELL, that's the appropriate usage. Checking if less than OP_SELL isnt the right usage (gramar?))

    I believe there is a swap value saved for the order, but not sure about commission.

    cheers

  5. #5
    Thanks for you answer.

    That is not the problem, I've just change it to ==

    FYI
    that was to check if it's OP_SELL or OP_BUY which will return 1 and 0.
    Lt;= 0 or 1.

    Perhaps not the reason for the Tailing Stop Loss to sell in loss.

  6. #6
    The routine gets somewhat involved. You need to calculate the pip profit attained since the order was started. Subtract your trail factor. If trail would be activated check if order is actually profit. If that's the case let order to be closed. You are going to need to use iBarShift or even iLowest to calculate the highest or lowest price attained since order production. Start with the OrderOpenTime() and proceed forward to current time and loe the Highest/Lowest price (based on if its a BUY or SELL). Also keep tally of OrderProfit() - If its in the profit near the order with OrderClose().

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
This website uses cookies
We use cookies to store session information to facilitate remembering your login information, to allow you to save website preferences, to personalise content and ads, to provide social media features and to analyse our traffic. We also share information about your use of our site with our social media, advertising and analytics partners.