EA Modification - Close At Profit

Hi Goldylox, sorry what i meant was when each trade reach the TP or SL say for example 0.1 pip then the EA will close only that trade when it has reached its TP or SL in pips.

All TP and SL should be in pips rather than dollars :slight_smile:

No basket is used.

Is that possible?

Thanks

it should now be in pips. I just made it alter the orders to set a tp and sl.

You want like a hidden tp and sl? so your broker cant see?

Thanks Goldylox for the pips change :slight_smile: Much appreciated.

My broker (hotforex) has a minimum TP of 3 pips.

The original EA works great that it does close trades when the TP hits 1 pip or even 0.1 pip, but it does not modify the TP or SL, sorry if i never mentioned that.

Is it possible to have the EA close trades when their TP or SL reaches a certain level for each individual trade rather than having the EA alter the TP and SL of the EA as if i scalp low like 1 pip those changes will most likely get rejected, if that makes sense for this EA ?

What is a hidden TP and SL, i thought we could not hide changes to orders from the broker ?

Thanks :slight_smile:

Hi Goldylox i think you got it right the first time :), if we removed the two variables in red above and let the EA close trades based on the current TP and SL in green, then this EA should work as i hope.

Your command in orange should be right as i want to close each trade individually, not do do a basket close of all trades when profit or SL reaches the set amount above.

Hope that makes sense thanks :slight_smile:

//+------------------------------------------------------------------+
//|                                                    Goldylox3.mq4 |
//|                                                         Goldylox |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Goldylox"
#property link      ""

extern double takeprofit=3;
extern double stoploss=10;
bool basketclose=false;
double tp,sl,dg,totalpips;


//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   dg=Digits;
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
   
   selectorder();
//----
   return(0);
  }
//+------------------------------------------------------------------+

void selectorder(){
int i;
double pt;
double buypips;
double sellpips;
   if(OrdersTotal()>0){
      for(i=OrdersTotal()-1;i>=0;i--){
         OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
            if(OrderType()==OP_BUY){
               if(dg==3 || dg==5)pt=Point*10;
                  else pt=Point;  
               if(StringFind(OrderSymbol(),"JPY",0) >= 0 && (dg==3 || dg==5)) pt=0.01;
              if (basketclose){
                  buypips = ((OrderClosePrice()-OrderOpenPrice())/pt)+buypips;
                  }
              else{ 
                  buypips = ((OrderClosePrice()-OrderOpenPrice())/pt);  
                  if(stoploss>0 && buypips<=stoploss*(-1))OrderClose(OrderTicket(),OrderLots(),0,0,Purple);  
                  if(takeprofit>0 && buypips>=takeprofit)OrderClose(OrderTicket(),OrderLots(),0,0,Purple); 
                  }
               }
               
            if( OrderType()==OP_SELL){
               if(dg==3 || dg==5)pt=Point*10;
                  else pt=Point;  
               if(StringFind(OrderSymbol(),"JPY",0) >= 0 && (dg==3 || dg==5)) pt=0.01;
              if(basketclose){
                  sellpips = ((OrderOpenPrice()-OrderClosePrice())/pt)+buypips;
                  }
              else{  
                  sellpips = ((OrderOpenPrice()-OrderClosePrice())/pt)+buypips; 
                  if(stoploss>0 && sellpips<=stoploss*(-1))OrderClose(OrderTicket(),OrderLots(),0,0,Orange);  
                  if(takeprofit>0 && sellpips>=takeprofit)OrderClose(OrderTicket(),OrderLots(),0,0,Orange); 

                }
              }
           }
           totalpips = buypips+sellpips;
           }
           Comment("BUY:",buypips,"  SELL:",sellpips,"  Total:",totalpips);
        }
     

Try this.

We call “Hidden StopLoss/TakeProfit”, when it is controlled by the code and not by setting a SL or TP.

Your broker probably would not let you set such a small TP or SL

The problem with hidden stoploss/takeprofit is it is always 1 step behind. ie it only closes when it gets the signal. If you set it in the order it will(should) close as soon as the brokers price hits it.
Also disconnects, etc can cause issues.

Thanks Goldylox, i think thats it :slight_smile: I’ll test it an let you know how it goes :slight_smile:

But yes i do understand it is slower to react to closing trades as opposed to having the price set in the trade itself, but i do want to be able to close trades automatically at 1 pip.

I have set takeprofit as “0.1” which i assume is 0.1 pips.

Will let you know how i get on :slight_smile:

Hi Goldylox, just had three trades close for the following pairs with your EA:

AUDUSD
AUDJPY
EURGBP

So looks like it works fine, i’ll let it run for the next few days just to be certain.

Thanks alot for editing this EA for me i really do appreciate your hard work and time on it

For those that want the MT4 file, here is the EA Goldylox has made for me:

-CloseAtProfit_-_v2.00.zip (874 Bytes)

EA definety works as planned thanks for the work Goldylox much appreciated!

its good when something actually works :slight_smile:

Hi Goldy and Sandy,

Just want to clarify two things. The new CloseAtProfit V2 ea only has 2 parameters, Stoploss and Take profit.

  1. Say im using a 5 digit brokers, should i set the take profit for 3 pips as 3 or 0.3?

  2. I have attached the ea on a GU chart, does the EA only closes the trades made on GU pairs or all trades regardless of currency pairs?

Please advice.

Thanks in advance!

If you set the profit at 3.0 this is 3 pips

Also if you put the EA on any chart it will close any open trades when the TP or SL is hit regardless of the currency pair. It will work on all pairs.

Hello Sandy and Goldy,

Sorry for my post. I find that ea that Sandy attached doesn’t work at all.

see attached.


I have set both TP and SL to be 1 pips each. The trades displayed each exceeded 1 pip value but the ea isn’t closing any trade.

Please help me out here.

Thank you.

You need to calculate according to your base curreny and exchange rate between the currency pair. example your base is USD and you are trading EURCHF, change the profit (dollars) by multiply 1/USDCHF rate to get USD dollar value. And this will be your pips also at profit take. If you using USD paired currency, then dont need conversion. This you will get same pips for all trades base on your acccount base currency.

You should contact with a professional programmer for this modification of your EA.
In Freelancer or Odesk you can find a lot of programmer waiting for this kind of project

Hi Goldylox, im using this ea (the original version without any modifications) but i would like to know if it can be modify so when a target profit (in money not pips) its reach it closes first open orders and then pending orders, because the way im using it is like this: using price action i determine if i enter a buy or a sell, then i enter one trade by market execution then i open 15 to 20 pending orders using martingale with 5 to 10 pips separation, i do this in 6 to 7 pairs, i set a 1-2% profit in the ea, but the problem is that when the profit its reach it closes the trades in the same order i enter them so when all the trades are close the profit is less than 1% or sometimes it ends in loss, i would like it to close first the open trades to secure the profit and then close the pending orders, thanks for your help