+ Reply to Thread
Results 1 to 7 of 7
 0 Attachment(s)    

Thread: Add a breakeven

  1. #1
    Administrator funyoo's Avatar
    Join Date
    Sep 2008
    Posts
    7,455

    Default Add a breakeven

    After extern parameters, add :

    Code:
    extern int BreakEven=0;//|-----------------------break even
    After start(){, add :

    Code:
       if(BreakEven>0)MoveBreakEven();
    At the end of the code, add :

    Code:
    void MoveBreakEven()
    {
       int cnt,total=OrdersTotal();
       for(cnt=0;cnt<total;cnt++)
       {
          OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
          if(OrderType()<=OP_SELL&&OrderSymbol()==Symbol()&&OrderMagicNumber()==Magic)
          {
             if(OrderType()==OP_BUY)
             {
                if(BreakEven>0)
                {
                   if(NormalizeDouble((Bid-OrderOpenPrice()),Digits)>BreakEven*Point)
                   {
                      if(NormalizeDouble((OrderStopLoss()-OrderOpenPrice()),Digits)<0)
                      {
                         OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()+0*Point,Digits),OrderTakeProfit(),0,Blue);
                         return(0);
                      }
                   }
                }
             }
             else
             {
                if(BreakEven>0)
                {
                   if(NormalizeDouble((OrderOpenPrice()-Ask),Digits)>BreakEven*Point)
                   {
                      if(NormalizeDouble((OrderOpenPrice()-OrderStopLoss()),Digits)<0)
                      {
                         OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()-0*Point,Digits),OrderTakeProfit(),0,Red);
                         return(0);
                      }
                   }
                }
             }
          }
       }
    }

  2. #2
    Member
    Join Date
    Jan 2009
    Posts
    37

    Default

    how to edit if I want my stoploss move to breakeven +2pip after my open position in +17pip condition?

  3. #3
    Member
    Join Date
    Jan 2009
    Posts
    151

    Default

    Quote Originally Posted by darkkiller View Post
    how to edit if I want my stoploss move to breakeven +2pip after my open position in +17pip condition?
    Just set BreakEven=2;

    Btw, you don't need to use the NormalizeDouble() function until you're ready to modify the order and, if you're not adding or subtracting anything to or from the entry price, you won't even need to normalize it then.

    The order modify line can just read:

    Code:
    OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0,Blue)//for longs
    What you will need to do is compensate the BreakEven value for 3/5-digit brokers.
    PipRider.com - The home of the PipRider EA. From $100 to over $1m in 10 year backtest, and it works LIVE too!!

  4. #4
    Member
    Join Date
    Jan 2009
    Posts
    37

    Default

    thanks jezzer,but my problem solve when i change this
    Code:
                         OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()-0*Point,Digits),OrderTakeProfit(),0,Red);
    to this code
    Code:
                         OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()-2*Point,Digits),OrderTakeProfit(),0,Red);

  5. #5
    Member
    Join Date
    Jan 2009
    Posts
    151

    Default

    Quote Originally Posted by darkkiller View Post
    thanks jezzer,but my problem solve when i change this
    Code:
                         OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()-0*Point,Digits),OrderTakeProfit(),0,Red);
    to this code
    Code:
                         OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()-2*Point,Digits),OrderTakeProfit(),0,Red);
    I see. Sorry, I had misunderstood what you were trying to achieve.
    PipRider.com - The home of the PipRider EA. From $100 to over $1m in 10 year backtest, and it works LIVE too!!

  6. #6
    Member
    Join Date
    Jan 2009
    Posts
    37

    Default

    Quote Originally Posted by jezzer1961 View Post
    I see. Sorry, I had misunderstood what you were trying to achieve.
    Its okay,something new i learn from you today

  7. #7
    Junior Member
    Join Date
    May 2009
    Posts
    4

    Default

    How would you add code to this if you wanted Breakeven2 and a Breakeven3?? Marty

+ Reply to Thread

Posting Permissions

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