Results 1 to 3 of 3
 0 Attachment(s)    

Thread: Modifying TP Code

  1. #1

    Default Modifying TP Code

    Hi Funyoo,

    Could you help me out with this problem. I'm trying to modify the TP code in some of your ea's. I want the TP to take into consideration the spread when it is sending an order, so TP -spread.

    Example, with your EA's using automanagement setting produces a TP of 6 pip. The spread is 2 pip, so modified TP should be 4 pip, or if too close to the price then it should be the next minimum TP level allowed.

    When working with other EA's code I can usually add something like this;

    take -= MarketInfo(symbol,MODE_SPREAD);

    if(dir == OP_BUY && MarketInfo(symbol,MODE_SPREAD) <= spread)
    while(ticket < 0)
    price = MarketInfo(symbol,MODE_ASK);
    point = MarketInfo(symbol,MODE_POINT);
    digit = MarketInfo(symbol,MODE_DIGITS);
    sl = NormalizeDouble(price-stop*point,digit);
    tp = NormalizeDouble(price+take*point,digit);
    ticket = OrderSend(symbol,dir,lots,price,3,sl,tp,Key,Magic, 0,CLR_NONE);

    The important bits are in bold type.

    The problem is that I can't seem to be able to do this type of function with your code layout as the order functions are much more complex.

    Is there some simple code that I can use in your EA's that will do this?
    Last edited by matrix; 09-02-2010 at 11:32.

  2. #2
    Administrator funyoo's Avatar
    Join Date
    Sep 2008


    Hi matrix,

    You can replace this :

       if(type==OP_BUY || type==OP_BUYSTOP || type==OP_BUYLIMIT){
          if(hidesl==false && stoploss>0){sl=price-stoploss*pt;}else{sl=0;}
          if(hidetp==false && takeprofit>0){tp=price+takeprofit*pt;}else{tp=0;}
       if(type==OP_SELL || type==OP_SELLSTOP || type==OP_SELLLIMIT){
          if(hidesl==false && stoploss>0){sl=price+stoploss*pt;}else{sl=0;}
          if(hidetp==false && takeprofit>0){tp=price-takeprofit*pt;}else{tp=0;}
    With :

       if(type==OP_BUY || type==OP_BUYSTOP || type==OP_BUYLIMIT){
          if(hidesl==false && stoploss>0){sl=price-(stoploss+MarketInfo(symbol,MODE_SPREAD))*pt;}else{sl=0;}
          if(hidetp==false && takeprofit>0){tp=price+(takeprofit+MarketInfo(symbol,MODE_SPREAD))*pt;}else{tp=0;}
       if(type==OP_SELL || type==OP_SELLSTOP || type==OP_SELLLIMIT){
          if(hidesl==false && stoploss>0){sl=price+(stoploss+MarketInfo(symbol,MODE_SPREAD))*pt;}else{sl=0;}
          if(hidetp==false && takeprofit>0){tp=price-(takeprofit+MarketInfo(symbol,MODE_SPREAD))*pt;}else{tp=0;}

  3. #3


    Thanks Funyoo, I'll see if this works

Similar Threads

  1. Modifying an existing Harmonic Pattern indicator
    By TradeWynds in forum MQL programming
    Replies: 0
    Last Post: 12-21-2014, 14:44
  2. Can anyone Code this EA?
    By pret1102 in forum Softwares
    Replies: 1
    Last Post: 03-21-2012, 04:26
  3. Need Code for S/L and some more
    By Monkesy in forum Ideas for expert advisors
    Replies: 0
    Last Post: 04-05-2011, 10:30
  4. Please help me to code this EA
    By sshirbhate in forum MQL programming
    Replies: 2
    Last Post: 03-21-2011, 13:03
  5. Help with code
    By fxwealth in forum MQL programming
    Replies: 1
    Last Post: 03-25-2010, 18:10

Tags for this Thread

add, funyoo, level, magic, sells, simple, spread, stop, stoploss

Posting Permissions

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