Results 1 to 3 of 3
 0 Attachment(s)    

Thread: Trailing stop code request

  1. #1

    Default Trailing stop code request

    Hi Funyoo,

    I require alittle code help.

    I'd like to modify your trailing stop function in one of your EA's. I 'd like the trailing stop to start from the price that the current bar has opened at and not the price that I placed my trade at.

    With slippage and variable spread, backtesting with the trailing stop based on entries is hit and miss.

    Hope you can help,

    Thanks

  2. #2
    Administrator funyoo's Avatar
    Join Date
    Sep 2008
    Posts
    7,003

    Default

    Hi Matrix,

    You can replace the trailingstop function with :

    Code:
    void movetrailingstop(int mode,double trailingstart,double trailingstop){
       RefreshRates();
       if(OrdersTotal()>0){
          for(i=OrdersTotal();i>=0;i--){
             OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
             if(mode==0){
                if(OrderType()<=OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber()==magic){
                   if(OrderType()==OP_BUY){
                      if(NormalizeDouble(Ask,Digits)>NormalizeDouble(OrderOpenPrice()+trailingstart*pt,Digits)
                      && NormalizeDouble(OrderStopLoss(),Digits)<NormalizeDouble(Bid-((Ask-Open[0])/pt+trailingstep)*pt,Digits)){
                         OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Bid-(Ask-Open[0]),Digits),OrderTakeProfit(),0,Blue);
                         return(0);
                      }
                   }
                   else{
                      if(NormalizeDouble(Bid,Digits)<NormalizeDouble(OrderOpenPrice()-trailingstart*pt,Digits)
                      && (NormalizeDouble(OrderStopLoss(),Digits)>(NormalizeDouble(Ask+((Open[0]-Bid)/pt+trailingstep)*pt,Digits))) || (OrderStopLoss()==0)){                 
                         OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Ask+(Open[0]-Bid),Digits),OrderTakeProfit(),0,Red);
                         return(0);
                      }
                   }
                }
             }
          }
       }
    }

  3. #3

    Default

    Thanks Funyoo! I'll give this a try

Similar Threads

  1. EA Request Trailing Buy Stop/Sell Stop or Buy Limit/Sell Limit
    By bseth in forum Ideas for expert advisors
    Replies: 3
    Last Post: 02-25-2016, 04:04
  2. Trailing stop and Trailing profit
    By Luudt in forum MQL programming
    Replies: 0
    Last Post: 02-15-2016, 21:00
  3. SL/TP/Trailing stop code
    By crescendo in forum Scripts and other tools
    Replies: 1
    Last Post: 09-14-2011, 15:25
  4. Trailing stop code
    By daxc in forum Ideas for expert advisors
    Replies: 0
    Last Post: 07-22-2010, 13:32
  5. Waddah Attar Win EA - with Trailing Stop & Stop Loss
    By dlhc in forum Scripts and other tools
    Replies: 0
    Last Post: 03-09-2010, 12:33

Tags for this Thread

backtesting, funyoo, request, slippage, spread, stop, trailing, trailingstart, trailingstep, trailingstop

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •