Welcome Forex EA downloads & MT4/MT5 auto-trading resources — EAs, Gold EAs, quant tools and real-world automation.
Sign In Sign Up

Trade More After Breakeven - MetaTrader 4 Expert | MT4 EA Download - MetaTrader 4 Resources

author EAcpu | 5 reads | 0 comments |

The masterpiece of this little EA is the order counting function.

integer order counter()
  {
integer counter = 0 ; //--- order ( integer i = total number of orders ()- 1 ; i >= 0 ; i-)
if ( order select (i,SELECT_BY_POS))
if (OrderMagicNumber()==MagicNumber && OrderSymbol()== Symbol ()) // if this EA has an open order { //--- if breakeven occurs /* only used for buy if stop loss is equal to or higher than the open price Note: this is not an implementation If you plan to have pending orders, that's fine It's only suitable for buy and sell*/ double XBreakeven = OrderType()==OP_BUY? OrderStopLoss() >= OrderOpenPrice() : OrderStopLoss() <= OrderOpenPrice();
if (!X breakeven) //If breakeven and trailing stop do not occur' {
              Counter++; //calculate position }
          }
Return to counter;
  }

There is no stop loss when we only count the following orders above or equal to the opening price to buy and below the opening price to sell. I am short and we count all orders that did not reach breakeven or whose trailing stop did not protect their opening price.

 Double XBreakeven = OrderType()==OP_BUY? OrderStopLoss() >= OrderOpenPrice() : OrderStopLoss() <= OrderOpenPrice();
if (!X breakeven) //If breakeven and trailing stop do not occur'

With it we create a counter that returns the value that we will use to limit the maximum position, in our case we set it to 1 order at a time

 if (ordercounter()<maxordernumber)

So every time breakeven occurs, the function ignores counting it because by then we only have one position in this example.. it will return zero and then we make another sale and the process continues

This would also not be possible if I hadn't created the break-even function,

Blank breakeven function()
  { //--- order ( integer i = total number of orders ()- 1 ; i >= 0 ; i-)
if ( order select (i,SELECT_BY_POS))
if (OrderMagicNumber()==MagicNumber && OrderSymbol()== symbol ())
          { // If the bid is higher than the opening price + breakeven point, buy; vice versa, if sell double xHybrid = OrderType()==OP_BUY? (Bid>Opening Price()+Breakeven Points* _View && OrderStopLoss()  _View&& OrderStopLoss()>OrderOpenPrice());
/* Only used for buy if stop loss is equal to or higher than open price, vice versa for sell*/ if (x mixed)
              {
Boolean modfy = OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(), 0 , clone None );
              }
          }
  }

Try it? ?


Attachment download

📎 more_orders_after_breakeven.mq4 (5.14 KB)

Source: MQL5 #35609

Verification code Refresh