Need help me mql4 guru add take profit to this EA - page 2

 
John Davis:

This is the simplest way, but it leaves a lot to be desired, does not work with ECN brokers.



Dear John Davis

but I need over all take profit include buy & sell both take profit.

Thanks for your help.

Gayathri.

 
gayathri k:

Dear John Davis

but I need over all take profit include buy & sell both take profit.

Thanks for your help.

Gayathri.


Try...

extern double    Lots=0.1;
extern double ProfitGoal=10.00; // Profit goal in deposit currency
datetime NewTime=0;
int start()
  {
   if(NewTime!=Time[0])
     {
      NewTime=Time[0];
      if(Close[1]>=Open[1])
         OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,0,NULL,0,0,Blue);
      else
         OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,0,NULL,0,0,Red);
     }
   if(AccountProfit()>=ProfitGoal) // Checks if you reached your profit goal
     {
      // Closes all orders oldest first inline with FIFO
      for(int i=0; i<OrdersTotal(); i++)
        {
         if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
            if(OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),10,clrNONE))
               i--; // Decrement by one since closed orders are removed from que
        }
     }
   return(0);
  }
 

Dear John Davis 

 i am very happy 

you are amazing,thank you for your precious time.

Gayathri

 
John Davis:

Try...


Dear John Davis

in profit its not closing single pair 

its closing total profit.

Thanks 

Gayathri

 
gayathri k:

Dear John Davis

in profit its not closing single pair 

its closing total profit.

Thanks 

Gayathri


Ok, so this code has both types.

#property strict
extern double    Lots=0.1;
extern int TakeProfit=30; // Take profit value in points
extern double ProfitGoal=10.00; // Profit goal in deposit currency
datetime NewTime=0;
//+------------------------------------------------------------------+
//| Begin main function                                              |
//+------------------------------------------------------------------+
int start()
  {
   if(NewTime!=Time[0]) // Run only on new bars
     {
      NewTime=Time[0];
      bool orderOpended=false;
      if(Close[1]>=Open[1])
         orderOpended=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+(TakeProfit*_Point),NULL,0,0,Blue);
      else
         orderOpended=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,Bid-(TakeProfit*_Point),NULL,0,0,Red);
     }
   if(AccountProfit()>=ProfitGoal) // Checks if you reached your profit goal
     {
      // Closes all orders oldest first inline with FIFO
      for(int i=0; i<OrdersTotal(); i++)
        {
         if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
            if(OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),10,clrNONE))
               i--; // Decrement by one since closed orders are removed from que
        }
     }
   return(0);
  }
//+------------------------------------------------------------------+

You probably would want to add, stoploss and maxloss.

 

So, I released some code to the codebase, based on upon my interaction with you on this forum. Check it out.

https://www.mql5.com/en/code/19180

Not really profitable but the code fits on one page.

Engulfing with RSI
Engulfing with RSI
  • votes: 1
  • 2017.09.29
  • John Davis
  • www.mql5.com
Opens buys on Bullish Engulfing candles when RSI is above overbought and sells on Bearish Engulfing candles when RSI is below oversold. When the account's profit reaches the desired level it closes all the orders. Inputs Lot size - specify the trade...