Download MetaTrader 5

Cannot get EA to place ( take profit ) from the opened trade price...

To add comments, please log in or register
Ramy Ram
99
Ramy Ram  

Hi,

This is what i have tried so far, but they all don't work except for the NormalizeDouble. But, it wont let me place the (take profit) at anything lower than 1.5 lots. I would like to be able to place it at 0.15 lots.

How do you get it to place the ( take profit ) from the trade  price when you add trades?  The price moves but the EA places the (take profit) at the ask or bid of the market price not the opened trade price.

 

       ObjectSetInteger(0,"BUY",OBJPROP_STATE,0);
      request.volume=Lot;
      request.price=last_tick.ask;
      request.type=ORDER_TYPE_BUY;
      if(SL!=0) request.sl=last_tick.bid-SL*Point();
      else request.sl=0;
     
    //request.tp=SymbolInfoDouble(Symbol(),SYMBOL_ASK) +TP*Point();
    
     request.tp=NormalizeDouble (TP, _Digits)-1650000*Point();
    
     //request.tp=price;
     
      //request.tp = (SymbolInfoDouble(Symbol(), SYMBOL_ASK) - PositionGetDouble(POSITION_PRICE_OPEN)+ TP * Point());
     
     // request.tp = PositionGetDouble(POSITION_PRICE_CURRENT)+TP*Point();
     
      //request.tp=HistoryDealGetInteger ( DEAL_ENTRY )
     
      //request.tp=NormalizeDouble(SymbolInfoDouble(Symbol(), SYMBOL_ASK), _Digits)+TP*Point();
     
      //request.tp=TP*Point();
     
      //request.tp=NormalizeDouble(TP,Point())/2;
     
     
      OrderSend(request,result);
      return;

Any help would be greatly appriciated. I have been trying to figure this out for 3 days...

 

Thks,

 

Ramy 

Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Position Properties
  • www.mql5.com
Standard Constants, Enumerations and Structures / Trade Constants / Position Properties - Documentation on MQL5
Andriy Moraru
1259
Andriy Moraru  

Don't forget to use Code tags.

request.tp=NormalizeDouble (TP, _Digits)-1650000*Point();

What is "TP"? Why do you subtract 1650000 pips from it? What error do you get in your logs when it's executed?

Ramy Ram
99
Ramy Ram  

Hi,

TP is my setting in the  input parameters.

I dont get any errors. the ( // ) lines are just some of the things i tried to get the EA to place  the take profit at the trade open price and not at the market price.

I attached the EA so you can better understand. the lines with //, are things i have tried but i still cannot get it to place the take profit at the open trade price.

I know its some simple code that i cannot find anywhere... I looked threw a lot of indicators and EAs that do it, but i cannot figure out how whith this one.

And i just noticed that  (_digits) places the take profit as digits. if i put (_Point) it still places the take profit as digits... I would like it to be placed as points.

 

P.S. I tried to re-edit my first post with code tags but i cannot. So i will code tag my next comments. Sorry about that.  

Regards,

 

Ramy 

 

Files:
pipser2.mq5 6 kb
Andriy Moraru
1259
Andriy Moraru  

OK. So, according to your .mq5 file you are using TP=25. For example, EUR/USD pair with fractional pips - what we get:

NormalizeDouble(TP, _Digits) = NormalizeDouble(25, 5) = 25.0000

1650000 * Point() = 1650000 * 0.00001 = 16.5

25.0000 - 16.5 = 8.5

So, basically, you are trying to set your stop-loss to 8.5, which is probably rejected by your broker.

Ramy Ram
99
Ramy Ram  

Hi,

Forget the math. I just want it to place the (take profit limit order) at the trade price when i add orders and not at the market price. 

thks for trying to help its appreciated

 

cheers,

 

Ramy 

Andriy Moraru
1259
Andriy Moraru  

Did you try to print OrderSend return code after its execution? What code does it return?

Place this link after your OrderSend if haven't tried doing so yet:

Print(result.retcode);
To add comments, please log in or register