Results 1 to 3 of 3
 0 Attachment(s)    

Thread: MT4's Basic MA ea

  1. #1

    Default MT4's Basic MA ea

    Can someone code in a basic trailing stoploss function......without changing any of its present functions

    regards fxloot
    Last edited by fxloot; 09-02-2010 at 02:57.

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

    Default

    Hi fxloot,

    My trailing stop function :

    Extern :

    Code:
    int trailingstopmode=0;                  // 0 new sl=ask+/-trailingstart, 1 new sl=sl+/-trailingstop or order open price/-trailingstop if sl=0
    extern double trailingstart=0;           // profit in pips required to enable the trailing stop
    extern double trailingstop=0;            // trailing stop
    After extern :
    Code:
    double pt,mt;
    Init :
    Code:
       if(Digits==3 || Digits==5){
          pt=Point*10;
          mt=10;
       }else{
          pt=Point;
          mt=1;
       }
    At the end of the code :
    Code:
    void movetrailingstop(int mode,double trailingstart,double trailingstop){
       RefreshRates();
       if(OrdersTotal()>0){
          for(int 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-(trailingstop+trailingstep)*pt,Digits)){
                         OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Bid-trailingstop*pt,Digits),OrderTakeProfit(),0,Blue);
                         return(0);
                      }
                   }
                   else{
                      if(NormalizeDouble(Bid,Digits)<NormalizeDouble(OrderOpenPrice()-trailingstart*pt,Digits)
                      && (NormalizeDouble(OrderStopLoss(),Digits)>(NormalizeDouble(Ask+(trailingstop+trailingstep)*pt,Digits))) || (OrderStopLoss()==0)){                 
                         OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Ask+trailingstop*pt,Digits),OrderTakeProfit(),0,Red);
                         return(0);
                      }
                   }
                }
             }
             if(mode==1){
                if(OrderType()<=OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber()==magic){
                   if(OrderType()==OP_BUY && OrderStopLoss()==0){
                      if(NormalizeDouble(Ask,Digits)>=NormalizeDouble(OrderOpenPrice()+trailingstart*pt,Digits)){
                         OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Ask-trailingstop*pt,Digits),OrderTakeProfit(),0,Blue);
                         return(0);
                      }
                   }
                   if(OrderType()==OP_BUY && OrderStopLoss()!=0){
                      if(NormalizeDouble(Ask,Digits)>=NormalizeDouble(OrderOpenPrice()+trailingstart*pt,Digits)
                      && NormalizeDouble(Ask,Digits)>=NormalizeDouble(OrderStopLoss()+trailingstart*pt,Digits)){
                         OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderStopLoss()+trailingstop*pt,Digits),OrderTakeProfit(),0,Blue);
                         return(0);
                      }
                   }
                   if(OrderType()==OP_SELL && OrderStopLoss()==0){
                      if(NormalizeDouble(Bid,Digits)<=NormalizeDouble(OrderOpenPrice()-trailingstart*pt,Digits)){
                         OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Bid+trailingstop*pt,Digits),OrderTakeProfit(),0,Red);
                         return(0);
                      }
                   }
                   if(OrderType()==OP_SELL && OrderStopLoss()!=0){
                      if(NormalizeDouble(Bid,Digits)<=NormalizeDouble(OrderOpenPrice()-trailingstart*pt,Digits)
                      && NormalizeDouble(Bid,Digits)<=NormalizeDouble(OrderStopLoss()-trailingstart*pt,Digits)){
                         OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderStopLoss()-trailingstop*pt,Digits),OrderTakeProfit(),0,Red);
                         return(0);
                      }
                   }
                }
             }
          }
       }
    }
    Mode : 0 new sl=ask+/-trailingstart (as long as), 1 new sl=sl+/-trailingstop or order open price/-trailingstop if sl=0 (step by step).

  3. #3

    Default

    Thankyou...........i think.......lol

    regards fxloot

Similar Threads

  1. The Basic Candlestick Patterns
    By painofhell in forum Trading discussion
    Replies: 0
    Last Post: 12-05-2014, 15:34
  2. Six basic tenets of Dow theory
    By painofhell in forum Trading discussion
    Replies: 0
    Last Post: 10-14-2014, 00:28
  3. Need basic money management information
    By rafiq in forum Trading discussion
    Replies: 6
    Last Post: 09-15-2014, 15:45
  4. Basic EMA Crossover Expert Advisor
    By MesquiteLizard in forum Ideas for expert advisors
    Replies: 0
    Last Post: 09-22-2013, 04:03

Tags for this Thread

mt4, profit, step by step, stop, stoploss, trailing, trailingstart, trailingstep

Posting Permissions

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